buuren / pysphere

Automatically exported from code.google.com/p/pysphere
0 stars 0 forks source link

No datastoreFolder and networkFolder in _retrieve_properties_traversal method #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
s = VIServer()
s.connect('vc', 'user', 'pass')
results = s._retrieve_properties_traversal(property_names=["name"])

What is the expected output? What do you see instead?
I get:
>>> [r.Obj for r in results if "group-s" in r.Obj ]
>>> []

Fix:

#Traversal through vmFolder branch
f2ns = VI.ns0.TraversalSpec_Def('datacenterDataStoreTraversalSpec').pyclass()
f2ns.set_element_name('datacenterDataStoreTraversalSpec')
f2ns.set_element_type(MORTypes.Datacenter)
f2ns.set_element_path('networkFolder')
f2ns.set_element_skip(False)
spec_array_f2ns = [do_ObjectSpec_objSet.new_selectSet()]
spec_array_f2ns[0].set_element_name('visitFolders')
f2ds.set_element_selectSet(spec_array_f2ns)

f2ds = VI.ns0.TraversalSpec_Def('datacenterNetTraversalSpec').pyclass()
f2ds.set_element_name('datacenterNetTraversalSpec')
f2ds.set_element_type(MORTypes.Datacenter)
f2ds.set_element_path('datastoreFolder')
f2ds.set_element_skip(False)
spec_array_f2ds = [do_ObjectSpec_objSet.new_selectSet()]
spec_array_f2ds[0].set_element_name('visitFolders')
f2ds.set_element_selectSet(spec_array_f2ds)

spec_array_visit_folders = [(...)
do_ObjectSpec_objSet.new_selectSet(),
do_ObjectSpec_objSet.new_selectSet()]
(...)
spec_array_visit_folders[8].set_element_name('rpToVm')
spec_array_visit_folders[9].set_element_name('datacenterNetTraversalSpec')
spec_array_visit_folders[10].set_element_name('datacenterDataStoreTraversalSpec'
)
visit_folders.set_element_selectSet(spec_array_visit_folders)

#Add all of them here
spec_array = [visit_folders, dc_to_vmf, dc_to_ds, dc_to_hf, cr_to_h,
cr_to_rp, rp_to_rp, h_to_vm, ds_to_vm, rp_to_vm, f2ds, f2ns]

Result:
>>> [r.Obj for r in results if "group-s" in r.Obj ]
['group-s9450', 'group-s1260', 'group-s220', 'group-s215', 'group-s725', 
'group-s242', 'group-s29', 'group-s24', 'group-s607', 'group-s791', 
'group-s323', 'group-s781', 'group-s625', 'group-s225', 'group-s126', 
'group-s34', 'group-s813', 'group-s808', 'group-s803', 'group-s9440']
>>> [r.Obj for r in results if "group-n" in r.Obj ]
['group-n9451', 'group-n1261', 'group-n221', 'group-n216', 'group-n726', 
'group-n243', 'group-n30', 'group-n25', 'group-n608', 'group-n792', 
'group-n324', 'group-n782', 'group-n626', 'group-n226', 'group-n127', 
'group-n35', 'group-n814', 'group-n809', 'group-n804']

test:
allMors = {}

for row in results:
    for prop in row.PropSet:
        if allMors.has_key(row.Obj) == False:
            allMors[row.Obj] = {}
        allMors[row.Obj][prop.Name] = prop.Val

for (key, val) in allMors.items():
    tmp = val
    print key,
    while tmp.has_key("parent"):
        print tmp["parent"],
        try:
            tmp = allMors[tmp["parent"]]
        except:
            print "No such object :/"
    print 

What version of the product are you using? On what operating system?
1.8

Please provide any additional information below.

Original issue reported on code.google.com by jdkar...@gmail.com on 22 Jul 2014 at 3:09