def create(client, context, vappInfo): logging.debug('__INIT__vapp_create [ {0} ]'.format(vappInfo)) cresult = vapp_pb2.CreateVAppResult() cresult.created = False #cresult.in_vapp_info=vapp_pb2.CreateVAppInfo() cresult.in_vapp_info.CopyFrom(vappInfo) try: logged_in_org = client.get_org() org = Org(client, resource=logged_in_org) v = org.get_vdc(vappInfo.vdc) if v is None: raise errors.VDCNotFoundError(vappInfo.vdc) vdc = VDC(client, href=v.get('href')) logging.info("__LOG__vapp_create_calling instantiate_vapp............") network = None memory = None storage_profile = None accept_all_eulas = False power_on = False if vappInfo.network: network = vappInfo.network if vappInfo.memory: memory = vappInfo.memory if vappInfo.storage_profile: storage_profile = vappInfo.storage_profile if vappInfo.accept_all_eulas: accept_all_eulas = vappInfo.accept_all_eulas if vappInfo.power_on: power_on = vappInfo.power_on logging.info( "__LOG__ CREATE VAPP Params - MEMORY = [%s] NETWORK = [%s] storage_profile =[%s] ", memory, network, storage_profile) result = vdc.instantiate_vapp(name=vappInfo.name, catalog=vappInfo.catalog_name, template=vappInfo.template_name, network=network, memory=memory, cpu=vappInfo.cpu, power_on=power_on, storage_profile=storage_profile, accept_all_eulas=accept_all_eulas) task = client.get_task_monitor().wait_for_status( task=result.Tasks.Task[0], timeout=60, poll_frequency=2, fail_on_statuses=None, expected_target_statuses=[ TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR, TaskStatus.CANCELED ], callback=task_callback) st = task.get('status') if st == TaskStatus.SUCCESS.value: cresult.created = True else: raise errors.VCDVappCreationError( etree.tostring(task, pretty_print=True)) vapp = vdc.get_vapp(vappInfo.name) if vappInfo.power_on is True: logging.info("Powering on [Vapp %v]".format(vappInfo.name)) vapp.power_on() else: logging.info("Powering off [Vapp %v]".format(vappInfo.name)) vapp.undeploy() except Exception as e: error_message = 'ERROR.. Not Created VApp {0} {1}'.format( vappInfo.name, str(e)) logging.warn(error_message, e) context.set_code(grpc.StatusCode.INVALID_ARGUMENT) context.set_details(error_message) return cresult
print("\n") for j in range(0, i): print("\t", end='') for e in root.getchildren(): print(e.tag, end='') #print (e.tag,end='') #print (type(e),end='') print_element(e, i + 1) if __name__ == '__main__': # We need to build a health service to work with go-plugin logging.basicConfig(level=logging.DEBUG) file = open('task.xml') xslt_content = file.read() file.close() logging.info("parsing %s ", xslt_content) #tree = etree.XML(xslt_content) tree = etree.XML(xslt_content) error_node = tree.findall("{http://www.vmware.com/vcloud/v1.5}Error") msg = error_node[0].get('message') logging.info(msg) logging.info(etree.tostring(tree, pretty_print=True)) e = errors.VCDVappCreationError("l") raise e