9
9
api = iland .Api (client_id = CLIENT_ID , client_secret = CLIENT_SECRET , username = USERNAME , password = PASSWORD )
10
10
11
11
def main ():
12
- vdc_uuid = print_entity_inventory ('IAAS_VDC' )
12
+ vdc_uuid = print_entity_inventory ()
13
13
vapp_uuid = create_scratch_vapp (vdc_uuid )
14
14
delete_vapp (vapp_uuid )
15
15
16
16
'''
17
- This function gets a user's inventory with the GET endpoint /users/{username}/inventory and filters to get the specified
18
- entity type. In this case I am getting all the vDCs the user has access to so I pass IAAS_VDC .
19
- Besides printing all the vDCS, this function lazily grabs the first vDC uuid for the scratch vApp that we create below.
17
+ This function gets a user's inventory with the GET endpoint /users/{username}/inventory and filters to get vDCS, vApps and VMs.
18
+ In this case I am printing all the vDCs the user has access. I also show how to get vApps and VMs but don't print them .
19
+ Besides printing all the vDCS, this function lazily grabs the a vDC uuid for the scratch vApp that we create below.
20
20
'''
21
- def print_entity_inventory (entity_type ):
21
+ def print_entity_inventory ():
22
22
inventory = api .get ('/users/%s/inventory' % USERNAME )['inventory' ]
23
- vdc_uuid = ''
24
- for i in inventory :
25
- vdcs = i ['entities' ][entity_type ]
26
- for vdc in vdcs :
27
- if vdc_uuid == '' :
28
- vdc_uuid = vdc ['uuid' ]
29
- print (vdc ['name' ] + ' ' + vdc ['uuid' ])
23
+ for item in inventory :
24
+ vdcs = item [ 'entities' ][ 'IAAS_VDC' ]
25
+ vapps = item ['entities' ]['IAAS_VAPP' ]
26
+ vms = item [ 'entities' ][ 'IAAS_VM' ]
27
+ for vdc in vdcs :
28
+ vdc_uuid = vdc ['uuid' ]
29
+ print (vdc ['name' ] + ' ' + vdc ['uuid' ])
30
30
return vdc_uuid
31
31
32
32
'''
@@ -41,7 +41,6 @@ def create_scratch_vapp(vdc_uuid):
41
41
build_vapp_task = api .post ('/vdcs/%s/actions/build-vapp' % vdc_uuid , scratch_vapp )
42
42
wait_for_synced_task (build_vapp_task ['uuid' ])
43
43
vapps = api .get ('/vdcs/%s/vapps' % vdc_uuid )
44
- vapp_uuid = ''
45
44
for vapp in vapps ['data' ]:
46
45
if vapp ['name' ] == 'Example vApp Name' :
47
46
vapp_uuid = vapp ['uuid' ]
0 commit comments