mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-22 09:39:58 -05:00
Merge pull request #49 from tianhao64/master
Add exception handling for sddc samples to get detailed error message
This commit is contained in:
commit
2ab8622b32
@ -19,7 +19,8 @@ import argparse
|
|||||||
import atexit
|
import atexit
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from com.vmware.vmc.model_client import EsxConfig
|
from com.vmware.vmc.model_client import EsxConfig, ErrorResponse
|
||||||
|
from com.vmware.vapi.std.errors_client import InvalidRequest
|
||||||
from vmware.vapi.vmc.client import create_vmc_client
|
from vmware.vapi.vmc.client import create_vmc_client
|
||||||
|
|
||||||
from samples.vmc.helpers.vmc_task_helper import wait_for_task
|
from samples.vmc.helpers.vmc_task_helper import wait_for_task
|
||||||
@ -89,9 +90,16 @@ class AddRemoveHosts(object):
|
|||||||
def add_host(self):
|
def add_host(self):
|
||||||
print('\n# Example: Add 1 ESX hosts to SDDC {}:'.format(self.sddc_id))
|
print('\n# Example: Add 1 ESX hosts to SDDC {}:'.format(self.sddc_id))
|
||||||
esx_config = EsxConfig(1)
|
esx_config = EsxConfig(1)
|
||||||
|
|
||||||
|
try:
|
||||||
task = self.vmc_client.orgs.sddcs.Esxs.create(org=self.org_id,
|
task = self.vmc_client.orgs.sddcs.Esxs.create(org=self.org_id,
|
||||||
sddc=self.sddc_id,
|
sddc=self.sddc_id,
|
||||||
esx_config=esx_config)
|
esx_config=esx_config)
|
||||||
|
except InvalidRequest as e:
|
||||||
|
# Convert InvalidRequest to ErrorResponse to get error message
|
||||||
|
error_response = e.data.convert_to(ErrorResponse)
|
||||||
|
raise Exception(error_response.error_messages)
|
||||||
|
|
||||||
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
||||||
org_id=self.org_id,
|
org_id=self.org_id,
|
||||||
task_id=task.id,
|
task_id=task.id,
|
||||||
@ -101,10 +109,17 @@ class AddRemoveHosts(object):
|
|||||||
print('\n# Example: Remove 1 ESX host from SDDC {}:'.
|
print('\n# Example: Remove 1 ESX host from SDDC {}:'.
|
||||||
format(self.sddc_id))
|
format(self.sddc_id))
|
||||||
esx_config = EsxConfig(1)
|
esx_config = EsxConfig(1)
|
||||||
|
|
||||||
|
try:
|
||||||
task = self.vmc_client.orgs.sddcs.Esxs.create(org=self.org_id,
|
task = self.vmc_client.orgs.sddcs.Esxs.create(org=self.org_id,
|
||||||
sddc=self.sddc_id,
|
sddc=self.sddc_id,
|
||||||
esx_config=esx_config,
|
esx_config=esx_config,
|
||||||
action='remove')
|
action='remove')
|
||||||
|
except InvalidRequest as e:
|
||||||
|
# Convert InvalidRequest to ErrorResponse to get error message
|
||||||
|
error_response = e.data.convert_to(ErrorResponse)
|
||||||
|
raise Exception(error_response.error_messages)
|
||||||
|
|
||||||
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
||||||
org_id=self.org_id,
|
org_id=self.org_id,
|
||||||
task_id=task.id,
|
task_id=task.id,
|
||||||
|
@ -22,7 +22,8 @@ import requests
|
|||||||
from random import randrange
|
from random import randrange
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
from com.vmware.vmc.model_client import AwsSddcConfig
|
from com.vmware.vmc.model_client import AwsSddcConfig, ErrorResponse
|
||||||
|
from com.vmware.vapi.std.errors_client import InvalidRequest
|
||||||
from vmware.vapi.vmc.client import create_vmc_client
|
from vmware.vapi.vmc.client import create_vmc_client
|
||||||
|
|
||||||
from samples.vmc.helpers.vmc_task_helper import wait_for_task
|
from samples.vmc.helpers.vmc_task_helper import wait_for_task
|
||||||
@ -98,8 +99,15 @@ class CreateDeleteSDDC(object):
|
|||||||
sddc_config = AwsSddcConfig(
|
sddc_config = AwsSddcConfig(
|
||||||
region='US_WEST_2', num_hosts=1, name=self.sddc_name,
|
region='US_WEST_2', num_hosts=1, name=self.sddc_name,
|
||||||
provider=provider)
|
provider=provider)
|
||||||
|
|
||||||
|
try:
|
||||||
task = self.vmc_client.orgs.Sddcs.create(org=self.org_id,
|
task = self.vmc_client.orgs.Sddcs.create(org=self.org_id,
|
||||||
sddc_config=sddc_config)
|
sddc_config=sddc_config)
|
||||||
|
except InvalidRequest as e:
|
||||||
|
# Convert InvalidRequest to ErrorResponse to get error message
|
||||||
|
error_response = e.data.convert_to(ErrorResponse)
|
||||||
|
raise Exception(error_response.error_messages)
|
||||||
|
|
||||||
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
||||||
org_id=self.org_id,
|
org_id=self.org_id,
|
||||||
task_id=task.id,
|
task_id=task.id,
|
||||||
@ -113,8 +121,15 @@ class CreateDeleteSDDC(object):
|
|||||||
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,
|
||||||
self.org_id))
|
self.org_id))
|
||||||
|
|
||||||
|
try:
|
||||||
task = self.vmc_client.orgs.Sddcs.delete(org=self.org_id,
|
task = self.vmc_client.orgs.Sddcs.delete(org=self.org_id,
|
||||||
sddc=self.sddc_id)
|
sddc=self.sddc_id)
|
||||||
|
except InvalidRequest as e:
|
||||||
|
# Convert InvalidRequest to ErrorResponse to get error message
|
||||||
|
error_response = e.data.convert_to(ErrorResponse)
|
||||||
|
raise Exception(error_response.error_messages)
|
||||||
|
|
||||||
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
wait_for_task(task_client=self.vmc_client.orgs.Tasks,
|
||||||
org_id=self.org_id,
|
org_id=self.org_id,
|
||||||
task_id=task.id,
|
task_id=task.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user