1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-22 09:39:58 -05:00

Added List_SDDC Function & Added Standard Output Function

Adding a standalone list_sddc function, parameters to handle the
calling of whether or not the intended action be a list, create, and/or
delete method, added a standard output function to match what’s
available as part of the logical network example.
This commit is contained in:
Kyle Ruddy 2018-03-21 17:41:40 -04:00
parent b8554584c2
commit 0a62db4e0f

View File

@ -42,6 +42,9 @@ class CreateDeleteSDDC(object):
self.vmc_client = None self.vmc_client = None
self.sddc_id = None self.sddc_id = None
self.sddc_name = None self.sddc_name = None
self.listsddc = None
self.createsddc = None
self.deletesddc = None
self.cleanup = None self.cleanup = None
self.refresh_token = None self.refresh_token = None
self.interval_sec = None self.interval_sec = None
@ -65,6 +68,18 @@ class CreateDeleteSDDC(object):
default=60, default=60,
help='Task pulling interval in sec') help='Task pulling interval in sec')
parser.add_argument('-ls', '--listsddc',
action='store_true',
help='List SDDCs in the specified Org')
parser.add_argument('-cs', '--createsddc',
action='store_true',
help='Create an SDDC in the specified Org')
parser.add_argument('-ds', '--deletesddc',
action='store_true',
help='Deletes the SDDC in the specified Org ')
parser.add_argument('-c', '--cleardata', parser.add_argument('-c', '--cleardata',
action='store_true', action='store_true',
help='Clean up after sample run') help='Clean up after sample run')
@ -73,6 +88,9 @@ class CreateDeleteSDDC(object):
self.refresh_token = args.refresh_token self.refresh_token = args.refresh_token
self.org_id = args.org_id self.org_id = args.org_id
self.listsddc = args.listsddc
self.createsddc = args.createsddc
self.deletesddc = args.deletesddc
self.cleanup = args.cleardata self.cleanup = args.cleardata
self.sddc_name = args.sddc_name or \ self.sddc_name = args.sddc_name or \
@ -116,7 +134,7 @@ class CreateDeleteSDDC(object):
print('\n# Example: SDDC created:') print('\n# Example: SDDC created:')
self.sddc_id = task.resource_id self.sddc_id = task.resource_id
sddc = self.vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id) sddc = self.vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id)
print(tabulate([[sddc.id, sddc.name]], ["ID", "Name"])) self.print_output([sddc])
def delete_sddc(self): def delete_sddc(self):
print('\n# Example: Delete SDDC {} from org {}'.format(self.sddc_id, print('\n# Example: Delete SDDC {} from org {}'.format(self.sddc_id,
@ -137,22 +155,35 @@ class CreateDeleteSDDC(object):
print('\n# Example: Remaining SDDCs:'. print('\n# Example: Remaining SDDCs:'.
format(self.org_id)) format(self.org_id))
sddcs_list = self.vmc_client.orgs.Sddcs.list(self.org_id) sddcs = self.vmc_client.orgs.Sddcs.list(self.org_id)
self.print_output(sddcs)
headers = ["ID", "Name"] def list_sddc(self):
sddcs = self.vmc_client.orgs.Sddcs.list(self.org_id)
if not sddcs:
raise ValueError('The sample requires at least one SDDC associated'
'with the calling user')
print("\n# Example: List SDDCs")
self.print_output(sddcs)
def print_output(self, sddcs):
table = [] table = []
for sddc in sddcs_list: for sddc in sddcs:
table.append([sddc.id, sddc.name]) table.append([sddc.id, sddc.name, sddc.resource_config.region])
print(tabulate(table, headers)) print(tabulate(table, ['ID', 'Name', 'AWS Region']))
def main(): def main():
esx_operations = CreateDeleteSDDC() sddc_operations = CreateDeleteSDDC()
esx_operations.option() sddc_operations.option()
esx_operations.setup() sddc_operations.setup()
esx_operations.create_sddc() if sddc_operations.listsddc:
if esx_operations.cleanup: sddc_operations.list_sddc()
esx_operations.delete_sddc() if sddc_operations.createsddc:
sddc_operations.create_sddc()
if sddc_operations.deletesddc:
sddc_operations.delete_sddc()
if sddc_operations.cleanup:
sddc_operations.delete_sddc()
if __name__ == '__main__': if __name__ == '__main__':