99api  =  iland .Api (client_id = CLIENT_ID , client_secret = CLIENT_SECRET , username = USERNAME , password = PASSWORD )
1010
1111def  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' ]
0 commit comments