本文整理汇总了Python中pyvcloud.Log类的典型用法代码示例。如果您正苦于以下问题:Python Log类的具体用法?Python Log怎么用?Python Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Log类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_status
def get_status(self):
self.response = Http.get(self.url + '/status',
headers=self.get_headers(),
verify=self.verify, logger=self.logger)
Log.debug(self.logger, self.response.status_code)
Log.debug(self.logger, self.response.content)
return self.response.content
开发者ID:digideskio,项目名称:pyvcloud,代码行数:7,代码来源:score.py
示例2: block_until_completed
def block_until_completed(self, task):
progress = task.get_Progress()
status = task.get_status()
rnd = 0
while status != "success":
if status == "error":
error = task.get_Error()
Log.error(self.logger, "task error, major=%s, minor=%s, message=%s" % (error.get_majorErrorCode(), error.get_minorErrorCode(), error.get_message()))
return False
else:
# some task doesn't not report progress
if progress:
pass
else:
rnd += 1
time.sleep(1)
self.response = Http.get(task.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
task = taskType.parseString(self.response.content, True)
progress = task.get_Progress()
status = task.get_status()
else:
Log.error(self.logger, "can't get task")
return False
return True
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:25,代码来源:vcloudair.py
示例3: list
def list(self, deployment_id):
params = {'deployment_id': deployment_id}
self.score.response = Http.get(self.score.url + '/executions', headers=self.score.get_headers(), params=params, verify=self.score.verify, logger=self.logger)
if self.score.response.status_code == requests.codes.ok:
return json.loads(self.score.response.content)
else:
Log.error(self.logger, 'list executions returned %s' % self.score.response.status_code)
开发者ID:lasko,项目名称:pyvcloud,代码行数:7,代码来源:score.py
示例4: blueprint
def blueprint(cmd_proc, operation, blueprint, blueprint_file, include_plan):
"""Operations with Blueprints"""
scoreclient = None
if 'validate' != operation:
scoreclient = _authorize(cmd_proc)
else:
scoreclient = Score(cmd_proc.host_score)
Log.debug(cmd_proc.logger, 'using host score: %s' %
cmd_proc.host_score)
if 'validate' == operation:
_validate(cmd_proc, blueprint_file, scoreclient)
elif 'list' == operation:
_list_blueprints(cmd_proc, scoreclient)
elif 'upload' == operation:
_upload(cmd_proc, blueprint, blueprint_file, scoreclient)
elif 'delete' == operation:
_delete_blueprint(cmd_proc, blueprint, scoreclient)
elif 'info' == operation:
_info_blueprint(cmd_proc, scoreclient,
include_plan=include_plan)
elif 'status' == operation:
try:
scoreclient = _authorize(cmd_proc)
status = scoreclient.get_status()
print_utils.print_dict(json.loads(status))
except exceptions.ClientException as e:
utils.print_error("Unable to get blueprinting service status. "
"Reason: {0}"
.format(str(e)), cmd_proc)
开发者ID:amwelch,项目名称:vca-cli,代码行数:29,代码来源:vca_cli_blueprint.py
示例5: display_progress
def display_progress(self, task, cmd_proc=None, headers=None):
progress = task.get_Progress()
status = task.get_status()
rnd = 0
response = None
while status != "success":
if status == "error":
error = task.get_Error()
sys.stdout.write('\r' + ' ' * 120 + '\r')
sys.stdout.flush()
self.print_error(CommonUtils.convertPythonObjToStr(
error, name="Error"),
cmd_proc=cmd_proc)
return None
else:
# some task doesn't not report progress
if progress:
sys.stdout.write("\rprogress : [" + "*" *
int(progress) + " " *
(100 - int(progress - 1)) + "] " +
str(progress) + " %")
else:
sys.stdout.write("\rprogress : ")
if rnd % 4 == 0:
sys.stdout.write(
"[" + "*" * 25 + " " * 75 + "]")
elif rnd % 4 == 1:
sys.stdout.write(
"[" + " " * 25 + "*" * 25 + " " * 50 + "]")
elif rnd % 4 == 2:
sys.stdout.write(
"[" + " " * 50 + "*" * 25 + " " * 25 + "]")
elif rnd % 4 == 3:
sys.stdout.write(
"[" + " " * 75 + "*" * 25 + "]")
rnd += 1
sys.stdout.flush()
time.sleep(1)
response = Http.get(task.get_href(), headers=headers,
verify=cmd_proc.verify,
logger=cmd_proc.logger)
if response.status_code == requests.codes.ok:
task = parseString(response.content, True)
progress = task.get_Progress()
status = task.get_status()
else:
Log.error(cmd_proc.logger, "can't get task")
return
sys.stdout.write("\r" + " " * 120)
sys.stdout.flush()
if response is not None:
if cmd_proc is not None and cmd_proc.json_output:
sys.stdout.write("\r" +
self.task_to_json(response.content) + '\n')
else:
sys.stdout.write("\r" +
self.task_to_table(response.content) + '\n')
sys.stdout.flush()
开发者ID:tsugliani,项目名称:vca-cli,代码行数:58,代码来源:vca_cli_utils.py
示例6: blueprint
def blueprint(cmd_proc, operation, blueprint_id, blueprint_file, include_plan):
"""Operations with Blueprints"""
if "validate" != operation:
scoreclient = _authorize(cmd_proc)
else:
scoreclient = Score(cmd_proc.host_score)
Log.debug(cmd_proc.logger, "using host score: %s" % cmd_proc.host_score)
_run_operation(cmd_proc, operation, blueprint_id, blueprint_file, include_plan, scoreclient)
开发者ID:tsugliani,项目名称:vca-cli,代码行数:10,代码来源:vca_cli_blueprint.py
示例7: customize_guest_os
def customize_guest_os(self, vm_name, customization_script=None,
computer_name=None, admin_password=None,
reset_password_required=False):
"""
Associate a customization script with a guest OS and execute the script.
The VMware tools must be installed in the Guest OS.
:param vm_name: (str): The name of the vm to be customized.
:param customization_script: (str, Optional): The path to a file on the local file system containing the customization script.
:param computer_name: (str, Optional): A new value for the the computer name. A default value for the template is used if a value is not set.
:param admin_password: (str, Optional): A password value for the admin/root user. A password is autogenerated if a value is not supplied.
:param reset_password_required: (bool): Force the user to reset the password on first login.
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request. \n
if the task cannot be created a debug level log message is generated detailing the reason.
"""
children = self.me.get_Children()
if children:
vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
if len(vms) == 1:
sections = vms[0].get_Section()
customization_section = [section for section in sections
if (section.__class__.__name__ ==
"GuestCustomizationSectionType")
][0]
customization_section.set_Enabled(True)
customization_section.set_ResetPasswordRequired(
reset_password_required)
customization_section.set_AdminAutoLogonEnabled(False)
customization_section.set_AdminAutoLogonCount(0)
if customization_script:
customization_section.set_CustomizationScript(
customization_script)
if computer_name:
customization_section.set_ComputerName(computer_name)
if admin_password:
customization_section.set_AdminPasswordEnabled(True)
customization_section.set_AdminPasswordAuto(False)
customization_section.set_AdminPassword(admin_password)
output = StringIO()
customization_section.export(output,
0,
name_ = 'GuestCustomizationSection',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = True)
body = output.getvalue().\
replace("vmw:", "").replace('Info xmlns:vmw="http://www.vmware.com/vcloud/v1.5" msgid=""', "ovf:Info").\
replace("/Info", "/ovf:Info")
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.guestcustomizationsection+xml'
self.response = Http.put(customization_section.Link[0].href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "failed; response status=%d, content=%s" % (self.response.status_code, self.response.text))
开发者ID:kostya13,项目名称:pyvcloud,代码行数:55,代码来源:vapp.py
示例8: customize_on_next_poweron
def customize_on_next_poweron(self):
vm = self._get_vms()[0]
link = filter(lambda link: link.get_rel() == "customizeAtNextPowerOn",
vm.get_Link())
if link:
self.response = Http.post(link[0].get_href(), data=None,
headers=self.headers, logger=self.logger)
if self.response.status_code == requests.codes.no_content:
return True
Log.error(self.logger, "link not found")
return False
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:12,代码来源:vapp.py
示例9: modify_vm_memory
def modify_vm_memory(self, vm_name, new_size):
"""
Modify the virtual Memory allocation for VM.
:param vm_name: (str): The name of the vm to be customized.
:param new_size: (int): The new memory allocation in MB.
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request. \n
if the task cannot be created a debug level log message is generated detailing the reason.
:raises: Exception: If the named VM cannot be located or another error occured.
"""
children = self.me.get_Children()
if children:
vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
if len(vms) == 1:
sections = vm.get_Section()
virtualHardwareSection = filter(lambda section: section.__class__.__name__== "VirtualHardwareSection_Type", sections)[0]
items = virtualHardwareSection.get_Item()
memory = filter(lambda item: item.get_Description().get_valueOf_() == "Memory Size", items)[0]
href = memory.get_anyAttributes_().get('{http://www.vmware.com/vcloud/v1.5}href')
en = memory.get_ElementName()
en.set_valueOf_('%s MB of memory' % new_size)
memory.set_ElementName(en)
vq = memory.get_VirtualQuantity()
vq.set_valueOf_(new_size)
memory.set_VirtualQuantity(vq)
weight = memory.get_Weight()
weight.set_valueOf_(str(int(new_size)*10))
memory.set_Weight(weight)
memory_string = CommonUtils.convertPythonObjToStr(memory, 'Memory')
Log.debug(self.logger, "memory: \n%s" % memory_string)
output = StringIO()
memory.export(output,
0,
name_ = 'Item',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"',
pretty_print = True)
body = output.getvalue().\
replace('Info msgid=""', "ovf:Info").replace("/Info", "/ovf:Info").\
replace("vmw:", "").replace("class:", "rasd:").replace("ResourceType", "rasd:ResourceType")
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.rasdItem+xml'
self.response = Http.put(href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
raise Exception(self.response.status_code)
raise Exception('can\'t find vm')
开发者ID:kostya13,项目名称:pyvcloud,代码行数:48,代码来源:vapp.py
示例10: delete_vapp
def delete_vapp(self, vdc_name, vapp_name):
self.vdc = self.get_vdc(vdc_name)
if not self.vcloud_session or not self.vcloud_session.organization or not self.vdc: return False
vapp = self.get_vapp(self.vdc, vapp_name)
if not vapp: return False
#undeploy and remove
if vapp.me.deployed:
task = vapp.undeploy()
if task:
self.block_until_completed(task)
else:
Log.debug(self.logger, "vapp.undeploy() didn't return a task")
return False
vapp = self.get_vapp(self.vdc, vapp_name)
if vapp: return vapp.delete()
Log.debug(self.logger, "no vApp")
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:16,代码来源:vcloudair.py
示例11: customize_guest_os
def customize_guest_os(self, vm_name, customization_script=None,
computer_name=None, admin_password=None,
reset_password_required=False):
children = self.me.get_Children()
if children:
vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
if len(vms) == 1:
sections = vms[0].get_Section()
customization_section = [section for section in sections
if (section.__class__.__name__ ==
"GuestCustomizationSectionType")
][0]
customization_section.set_Enabled(True)
customization_section.set_ResetPasswordRequired(
reset_password_required)
customization_section.set_AdminAutoLogonEnabled(False)
customization_section.set_AdminAutoLogonCount(0)
if customization_script:
customization_section.set_CustomizationScript(
customization_script)
if computer_name:
customization_section.set_ComputerName(computer_name)
if admin_password:
customization_section.set_AdminPasswordEnabled(True)
customization_section.set_AdminPasswordAuto(False)
customization_section.set_AdminPassword(admin_password)
output = StringIO()
customization_section.export(output,
0,
name_ = 'GuestCustomizationSection',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = False)
body = output.getvalue().\
replace("vmw:", "").replace('Info xmlns:vmw="http://www.vmware.com/vcloud/v1.5" msgid=""', "ovf:Info").\
replace("/Info", "/ovf:Info")
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.guestcustomizationsection+xml'
self.response = Http.put(customization_section.Link[0].href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "failed; response status=%d, content=%s" % (self.response.status_code, self.response.text))
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:42,代码来源:vapp.py
示例12: get_vms_details
def get_vms_details(self):
"""
Return a list the details for all VMs contained in the vApp.
:return: (list) a list, one entry per vm containing a (dict) of properties for the VM. \n
Dictionary keys 'name','status','cpus','memory','memory_mb','os','owner','admin_password','reset_password_required'
"""
result = []
children = self.me.get_Children()
if children:
vms = children.get_Vm()
for vm in vms:
name = vm.get_name()
status = VCLOUD_STATUS_MAP[vm.get_status()]
owner = self.me.get_Owner().get_User().get_name()
sections = vm.get_Section()
virtualHardwareSection = filter(lambda section: section.__class__.__name__== "VirtualHardwareSection_Type", sections)[0]
items = virtualHardwareSection.get_Item()
cpu = filter(lambda item: item.get_Description().get_valueOf_() == "Number of Virtual CPUs", items)[0]
cpu_capacity = int(cpu.get_ElementName().get_valueOf_().split(" virtual CPU(s)")[0])
memory = filter(lambda item: item.get_Description().get_valueOf_() == "Memory Size", items)[0]
memory_capacity_mb = int(memory.get_ElementName().get_valueOf_().split(" MB of memory")[0])
memory_capacity = memory_capacity_mb / 1024
operatingSystemSection = filter(lambda section: section.__class__.__name__== "OperatingSystemSection_Type", sections)[0]
os = operatingSystemSection.get_Description().get_valueOf_()
customization_section = filter(lambda section: section.__class__.__name__== "GuestCustomizationSectionType", sections)[0]
result.append(
{'name': name,
'status': status,
'cpus': cpu_capacity,
'memory': memory_capacity,
'memory_mb': memory_capacity_mb,
'os': os,
'owner': owner,
'admin_password': customization_section.get_AdminPassword(),
'reset_password_required': customization_section.get_ResetPasswordRequired()
}
)
Log.debug(self.logger, "details of VMs: %s" % result)
return result
开发者ID:kostya13,项目名称:pyvcloud,代码行数:41,代码来源:vapp.py
示例13: customize_on_next_poweron
def customize_on_next_poweron(self):
"""
Force the guest OS customization script to be run for the first VM in the vApp.
A customization script must have been previously associated with the VM
using the pyvcloud customize_guest_os method or using the vCD console
The VMware tools must be installed in the Guest OS.
:return: (bool) True if the request was accepted, False otherwise. If False an error level log message is generated.
"""
vm = self._get_vms()[0]
link = filter(lambda link: link.get_rel() == "customizeAtNextPowerOn",
vm.get_Link())
if link:
self.response = Http.post(link[0].get_href(), data=None,
headers=self.headers, logger=self.logger)
if self.response.status_code == requests.codes.no_content:
return True
Log.error(self.logger, "link not found")
return False
开发者ID:piraz,项目名称:pyvcloud,代码行数:21,代码来源:vapp.py
示例14: disconnect_vms
def disconnect_vms(self, network_name=None):
"""
Disconnect the vm from the vapp network.
:param network_name: (string): The name of the vApp network. If None, then disconnect from all the networks.
:return: (bool): True if the user was vApp was successfully deployed, False otherwise.
"""
children = self.me.get_Children()
if children:
vms = children.get_Vm()
for vm in vms:
Log.debug(self.logger, "child VM name=%s" % vm.get_name())
networkConnectionSection = [section for section in vm.get_Section() if isinstance(section, NetworkConnectionSectionType)][0]
found = -1
if network_name is None:
networkConnectionSection.set_NetworkConnection([])
found = 1
else:
for index, networkConnection in enumerate(networkConnectionSection.get_NetworkConnection()):
if networkConnection.get_network() == network_name:
found = index
break
if found != -1:
networkConnectionSection.NetworkConnection.pop(found)
if found != -1:
output = StringIO()
networkConnectionSection.export(output,
0,
name_ = 'NetworkConnectionSection',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmw="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = True)
body=output.getvalue().replace("vmw:Info", "ovf:Info")
self.response = Http.put(vm.get_href() + "/networkConnectionSection/", data=body, headers=self.headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
task = TaskType()
task.set_status("success")
task.set_Progress("100")
return task
开发者ID:kostya13,项目名称:pyvcloud,代码行数:40,代码来源:vapp.py
示例15: force_customization
def force_customization(self, vm_name):
children = self.me.get_Children()
if children:
vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
if len(vms) == 1:
sections = vms[0].get_Section()
links = filter(lambda link: link.rel== "deploy", vms[0].Link)
if len(links) == 1:
forceCustomizationValue = 'true'
deployVAppParams = vcloudType.DeployVAppParamsType()
deployVAppParams.set_powerOn('true')
deployVAppParams.set_deploymentLeaseSeconds(0)
deployVAppParams.set_forceCustomization('true')
body = CommonUtils.convertPythonObjToStr(deployVAppParams, name = "DeployVAppParams",
namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"')
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.deployVAppParams+xml'
self.response = Http.post(links[0].href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "response status=%d, content=%s" % (self.response.status_code, self.response.text))
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:22,代码来源:vapp.py
示例16: login
def login(self, host, username, password, instance, org, version,
save_password=True):
self.vca = VCA(host=host, username=username, version=version,
verify=self.verify, log=self.debug)
service_type = self.vca.get_service_type()
if service_type == VCA.VCA_SERVICE_TYPE_UNKNOWN:
raise Exception('service type unknown')
self.vca.service_type = service_type
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type and \
org is None:
self.error_message = 'Org can\'t be null'
return False
result = self.vca.login(password=password, org=org)
if result:
Log.debug(self.logger, 'logged in, org=%s' % self.vca.org)
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.vcloud_session.login(token=self.vca.
vcloud_session.token)
assert result
if save_password:
self.password = password
self.save_config(self.profile, self.profile_file)
return result
开发者ID:digideskio,项目名称:vca-cli,代码行数:23,代码来源:cmd_proc.py
示例17: force_customization
def force_customization(self, vm_name, power_on=True):
"""
Force the guest OS customization script to be run for a specific vm in the vApp.
A customization script must have been previously associated with the VM
using the pyvcloud customize_guest_os method or using the vCD console
The VMware tools must be installed in the Guest OS.
:param vm_name: (str): The name of the vm to be customized.
:param power_on (bool): Wether to power the vm on after customization or not
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request.b\n
if the task cannot be created a debug level log message is generated detailing the reason.
"""
children = self.me.get_Children()
if children:
vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
if len(vms) == 1:
sections = vms[0].get_Section()
links = filter(lambda link: link.rel== "deploy", vms[0].Link)
if len(links) == 1:
forceCustomizationValue = 'true'
deployVAppParams = vcloudType.DeployVAppParamsType()
if power_on:
deployVAppParams.set_powerOn('true')
else:
deployVAppParams.set_powerOn('false')
deployVAppParams.set_deploymentLeaseSeconds(0)
deployVAppParams.set_forceCustomization('true')
body = CommonUtils.convertPythonObjToStr(deployVAppParams, name = "DeployVAppParams",
namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"')
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.deployVAppParams+xml'
self.response = Http.post(links[0].href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "response status=%d, content=%s" % (self.response.status_code, self.response.text))
开发者ID:kostya13,项目名称:pyvcloud,代码行数:37,代码来源:vapp.py
示例18: modify_vm_name
def modify_vm_name(self, vm_index, vm_name):
"""
Modify the name of a VM in a vApp
:param vm_index: (int):The index of the VM in the vApp 1==first VM
:param vm_name: (str): The new name of the VM.
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request. \n
if the task cannot be created a debug level log message is generated detailing the reason.
:raises: Exception: If the named VM cannot be located or another error occured.
"""
children = self.me.get_Children()
if children:
assert len(children.get_Vm()) >= vm_index
vm = children.get_Vm()[vm_index-1]
assert vm
href = vm.get_href()
vm_name_old = vm.get_name()
Log.debug(self.logger, "VM name change (%s) %s -> %s" % (vm_index, vm_name_old, vm_name))
vm.set_name(vm_name)
vm.set_Section([])
output = StringIO()
vm.export(output,
0,
name_ = 'Vm',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmw="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = True)
body = output.getvalue()
headers = self.headers
headers['Content-type'] = 'application/vnd.vmware.vcloud.vm+xml'
self.response = Http.post(href+'/action/reconfigureVm', data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
raise Exception(self.response.status_code)
raise Exception('can\'t find vm')
开发者ID:kostya13,项目名称:pyvcloud,代码行数:36,代码来源:vapp.py
示例19: execute
def execute(self, operation, http, body=None, targetVM=None):
"""
Execute an operation against a VM as an Asychronous Task.
:param operation: (str): The command to execute
:param http: (str): The http operation.
:param body: (str, optional): a body for the http request
:param targetVM: (str, optional): The name of the VM that will be the target of the request.
:return: (TaskType or Bool) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request. \n
Or False if the request failed, error and debug level messages are logged.
"""
vApp = targetVM if targetVM else self.me
link = filter(lambda link: link.get_rel() == operation, vApp.get_Link())
if not link:
Log.error(self.logger, "link not found; rel=%s" % operation)
Log.debug(self.logger, "vApp href=%s, name=%s" % (vApp.get_href(), vApp.get_name()))
return False
else:
if http == "post":
headers = self.headers
if body and body.startswith('<DeployVAppParams '):
headers['Content-type'] = 'application/vnd.vmware.vcloud.deployVAppParams+xml'
elif body and body.startswith('<UndeployVAppParams '):
headers['Content-type'] = 'application/vnd.vmware.vcloud.undeployVAppParams+xml'
elif body and body.startswith('<CreateSnapshotParams '):
headers['Content-type'] = 'application/vnd.vmware.vcloud.createSnapshotParams+xml'
self.response = Http.post(link[0].get_href(), data=body, headers=headers, verify=self.verify, logger=self.logger)
elif http == "put":
self.response = Http.put(link[0].get_href(), data=body, headers=self.headers, verify=self.verify, logger=self.logger)
else:
self.response = Http.delete(link[0].get_href(), headers=self.headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "failed; response status=%d, content=%s" % (self.response.status_code, self.response.text))
return False
开发者ID:kostya13,项目名称:pyvcloud,代码行数:37,代码来源:vapp.py
示例20: execute
def execute(self, operation, http, body=None, targetVM=None):
vApp = targetVM if targetVM else self.me
link = filter(lambda link: link.get_rel() == operation, vApp.get_Link())
if not link:
Log.error(self.logger, "link not found; rel=%s" % operation)
Log.debug(self.logger, "vApp href=%s, name=%s" % (vApp.get_href(), vApp.get_name()))
return False
else:
if http == "post":
headers = self.headers
if body and body.startswith('<DeployVAppParams '):
headers['Content-type'] = 'application/vnd.vmware.vcloud.deployVAppParams+xml'
elif body and body.startswith('<UndeployVAppParams '):
headers['Content-type'] = 'application/vnd.vmware.vcloud.undeployVAppParams+xml'
self.response = Http.post(link[0].get_href(), data = body, headers=headers, verify=self.verify, logger=self.logger)
elif http == "put":
self.response = Http.put(link[0].get_href(), data = body, headers=self.headers, verify=self.verify, logger=self.logger)
else:
self.response = Http.delete(link[0].get_href(), headers=self.headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
else:
Log.debug(self.logger, "failed; response status=%d, content=%s" % (self.response.status_code, response.text))
return False
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:24,代码来源:vapp.py
注:本文中的pyvcloud.Log类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论