本文整理汇总了Python中pyvcloud.vcd.vapp.VApp.power_on方法的典型用法代码示例。如果您正苦于以下问题:Python VApp.power_on方法的具体用法?Python VApp.power_on怎么用?Python VApp.power_on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcd.vapp.VApp
的用法示例。
在下文中一共展示了VApp.power_on方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import power_on [as 别名]
def update(client, context, vappInfo):
logging.info("__INIT__update[Vapp]")
cresult = vapp_pb2.UpdateVAppResult()
cresult.updated = False
print("Vapp[ {0} ], Vdc[ {1} ]".format(vappInfo.name, vappInfo.vdc))
org_resource = client.get_org()
org = Org(client, resource=org_resource)
try:
vdc_resource = org.get_vdc(vappInfo.vdc)
vdc = VDC(client, name=vappInfo.vdc, resource=vdc_resource)
vapp_resource = vdc.get_vapp(vappInfo.name)
vapp = VApp(client, name=vappInfo.name, resource=vapp_resource)
resp = None
if (vappInfo.power_on == True):
logging.info("Powering on [Vapp %v]".format(vappInfo.name))
resp = vapp.power_on()
else:
logging.info("Powering off [Vapp %v]".format(vappInfo.name))
resp = vapp.undeploy()
task = client.get_task_monitor().wait_for_status(
task=resp,
timeout=60,
poll_frequency=2,
fail_on_statuses=None,
expected_target_statuses=[
TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
TaskStatus.CANCELED
],
callback=None)
st = task.get('status')
if st == TaskStatus.SUCCESS.value:
message = 'status : {0} '.format(st)
logging.info(message)
cresult.updated = True
else:
raise errors.VappUpdateError(
etree.tostring(task, pretty_print=True))
except Exception as e:
error_message = '__ERROR_updating [Vapp] power_on={0} for Vapp {1} . __ErrorMessage__ {2}'.format(
vappInfo.power_on, vappInfo.name, str(e))
logging.warn(error_message)
cresult.updated = False
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
context.set_details(error_message)
logging.info("__DONE__update[Vapp]")
return cresult
示例2: power_on
# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import power_on [as 别名]
def power_on(self):
vapp_name = self.params.get('vapp_name')
response = dict()
response['changed'] = False
try:
vapp_resource = self.vdc.get_vapp(vapp_name)
vapp = VApp(self.client, name=vapp_name, resource=vapp_resource)
power_on_vapp_task = vapp.power_on()
self.execute_task(power_on_vapp_task)
response['msg'] = 'Vapp {} has been powered on.'.format(vapp_name)
response['changed'] = True
except OperationNotSupportedException:
response['warnings'] = 'Vapp {} is already powered on.'.format(vapp_name)
return response
示例3: power_on
# 需要导入模块: from pyvcloud.vcd.vapp import VApp [as 别名]
# 或者: from pyvcloud.vcd.vapp.VApp import power_on [as 别名]
def power_on(ctx, name, vm_names):
try:
restore_session(ctx, vdc_required=True)
client = ctx.obj['client']
vdc_href = ctx.obj['profiles'].get('vdc_href')
vdc = VDC(client, href=vdc_href)
vapp_resource = vdc.get_vapp(name)
vapp = VApp(client, resource=vapp_resource)
if len(vm_names) == 0:
task = vapp.power_on()
stdout(task, ctx)
else:
for vm_name in vm_names:
vm = VM(client, resource=vapp.get_vm(vm_name))
task = vm.power_on()
stdout(task, ctx)
stdout(task, ctx)
except Exception as e:
stderr(e, ctx)