Skip to content

Commit adc4180

Browse files
nksprzakanguenot
authored andcommitted
Update examples to reflect Wiki (#23)
1 parent 1d9253d commit adc4180

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

examples/create-scratch-vapp/create_scratch_vapp.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
api = iland.Api(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=USERNAME, password=PASSWORD)
1010

1111
def main():
12-
vdc_uuid = print_entity_inventory('IAAS_VDC')
12+
vdc_uuid = print_entity_inventory()
1313
vapp_uuid = create_scratch_vapp(vdc_uuid)
1414
delete_vapp(vapp_uuid)
1515

1616
'''
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.
2020
'''
21-
def print_entity_inventory(entity_type):
21+
def print_entity_inventory():
2222
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'])
3030
return vdc_uuid
3131

3232
'''
@@ -41,7 +41,6 @@ def create_scratch_vapp(vdc_uuid):
4141
build_vapp_task = api.post('/vdcs/%s/actions/build-vapp' % vdc_uuid, scratch_vapp)
4242
wait_for_synced_task(build_vapp_task['uuid'])
4343
vapps = api.get('/vdcs/%s/vapps' % vdc_uuid)
44-
vapp_uuid = ''
4544
for vapp in vapps['data']:
4645
if vapp['name'] == 'Example vApp Name':
4746
vapp_uuid = vapp['uuid']

examples/power-off-vm/power_off_vm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def main():
2020
'''
2121
def print_and_get_vapp():
2222
vapp_name = 'Example vApp Name'
23-
vapp_uuid = ''
2423
inventory = api.get('/users/%s/inventory' % USERNAME)['inventory']
25-
for i in inventory:
26-
vapps = i['entities']['IAAS_VAPP']
24+
for item in inventory:
25+
vapps = item['entities']['IAAS_VAPP']
26+
vms = item['entities']['IAAS_VM']
2727
for vapp in vapps:
2828
if vapp['name'] == vapp_name:
2929
vapp_uuid = vapp['uuid']

0 commit comments

Comments
 (0)