本文整理汇总了Python中pyvcloud.Http.put方法的典型用法代码示例。如果您正苦于以下问题:Python Http.put方法的具体用法?Python Http.put怎么用?Python Http.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.Http
的用法示例。
在下文中一共展示了Http.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disconnect_from_network
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def disconnect_from_network(self, network_name):
"""
Disconnect the vApp from an existing virtual network in the VDC.
:param network_name: (str): The name of the virtual network.
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request.
"""
networkConfigSection = [section for section in self.me.get_Section() if section.__class__.__name__ == "NetworkConfigSectionType"][0]
link = [link for link in networkConfigSection.get_Link() if link.get_type() == "application/vnd.vmware.vcloud.networkConfigSection+xml"][0]
found = -1
for index, networkConfig in enumerate(networkConfigSection.get_NetworkConfig()):
if networkConfig.get_networkName() == network_name:
found = index
if found != -1:
networkConfigSection.NetworkConfig.pop(found)
output = StringIO()
networkConfigSection.export(output,
0,
name_ = 'NetworkConfigSection',
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")
self.response = Http.put(link.get_href(), 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)
示例2: _upload
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def _upload(self, tar_file_obj,
blueprint_id,
application_file_name=None):
query_params = {}
if application_file_name is not None:
query_params['application_file_name'] = \
urllib.quote(application_file_name)
def file_gen():
buffer_size = 8192
while True:
read_bytes = tar_file_obj.read(buffer_size)
yield read_bytes
if len(read_bytes) < buffer_size:
return
uri = '/blueprints/{0}'.format(blueprint_id)
url = '{0}{1}'.format(self.score.url, uri)
headers = self.score.get_headers()
self.score.response = Http.put(url, headers=headers, params=query_params, data=file_gen(), verify=self.score.verify, logger=self.logger)
if self.score.response.status_code != 201:
raise Exception(self.score.response.status_code)
return self.score.response.json()
示例3: connect_vms
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def connect_vms(self, network_name, connection_index,
connections_primary_index=None, ip_allocation_mode='DHCP',
mac_address=None, ip_address=None):
children = self.me.get_Children()
if children:
vms = children.get_Vm()
for vm in vms:
new_connection = self._create_networkConnection(
network_name, connection_index, ip_allocation_mode,
mac_address, ip_address)
networkConnectionSection = [section for section in vm.get_Section() if isinstance(section, NetworkConnectionSectionType)][0]
self._modify_networkConnectionSection(
networkConnectionSection,
new_connection,
connections_primary_index)
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 = False)
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)
示例4: connect_to_network
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def connect_to_network(self, network_name, network_href, fence_mode='bridged'):
"""
Connect the vApp to an existing virtual network in the VDC.
:param network_name: (str): The name of the virtual network.
:param network_href: (str): A uri that points to the network resource.
:param fence_mode: (str, optional):
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request.
"""
vApp_NetworkConfigSection = [section for section in self.me.get_Section() if section.__class__.__name__ == "NetworkConfigSectionType"][0]
link = [link for link in vApp_NetworkConfigSection.get_Link() if link.get_type() == "application/vnd.vmware.vcloud.networkConfigSection+xml"][0]
for networkConfig in vApp_NetworkConfigSection.get_NetworkConfig():
if networkConfig.get_networkName() == network_name:
task = TaskType()
task.set_status("success")
task.set_Progress("100")
return task
networkConfigSection = VAPP.create_networkConfigSection(network_name, network_href, fence_mode, vApp_NetworkConfigSection)
output = StringIO()
networkConfigSection.export(output,
0,
name_ = 'NetworkConfigSection',
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('Info msgid=""', "ovf:Info").replace("Info", "ovf:Info").replace(":vmw", "").replace("vmw:","")\
.replace("RetainNetovf", "ovf").replace("ovf:InfoAcrossDeployments","RetainNetInfoAcrossDeployments")
self.response = Http.put(link.get_href(), 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)
示例5: _put
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def _put(self, href, body):
response = Http.put(
href,
data=body,
headers=self._session.vca.vcloud_session.get_vcloud_headers(),
verify=CONF.vcloud.verify)
if response.status_code == requests.codes.accepted:
return taskType.parseString(response.content, True)
return None
示例6: customize_guest_os
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
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))
示例7: connect_vms
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def connect_vms(self, network_name, connection_index,
connections_primary_index=None, ip_allocation_mode='DHCP',
mac_address=None, ip_address=None):
"""
Attach vms to a virtual network.
something helpful.
:param network_name: (str): The network name to connect the VM to.
:param connection_index: (str): Virtual slot number associated with this NIC. First slot number is 0.
:param connections_primary_index: (str): Virtual slot number associated with the NIC that should be considered this \n
virtual machine's primary network connection. Defaults to slot 0.
:param ip_allocation_mode: (str, optional): IP address allocation mode for this connection.
* One of:
- POOL (A static IP address is allocated automatically from a pool of addresses.)
- DHCP (The IP address is obtained from a DHCP service.)
- MANUAL (The IP address is assigned manually in the IpAddress element.)
- NONE (No IP addressing mode specified.)
:param mac_address: (str): the MAC address associated with the NIC.
:param ip_address: (str): the IP address assigned to this NIC.
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request.
"""
children = self.me.get_Children()
if children:
vms = children.get_Vm()
for vm in vms:
new_connection = self._create_networkConnection(
network_name, connection_index, ip_allocation_mode,
mac_address, ip_address)
networkConnectionSection = [section for section in vm.get_Section() if isinstance(section, NetworkConnectionSectionType)][0]
self._modify_networkConnectionSection(
networkConnectionSection,
new_connection,
connections_primary_index)
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)
示例8: create
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def create(self, blueprint_id, deployment_id, inputs=None):
assert blueprint_id
assert deployment_id
data = {
'blueprint_id': blueprint_id
}
if inputs:
data['inputs'] = inputs
headers = self.score.get_headers()
headers['Content-type'] = 'application/json'
self.score.response = Http.put(self.score.url + '/deployments/{0}'.format(deployment_id), data=json.dumps(data), headers=headers, verify=self.score.verify, logger=self.logger)
if self.score.response.status_code == requests.codes.ok:
return json.loads(self.score.response.content)
示例9: modify_vm_memory
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
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')
示例10: disconnect_from_networks
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def disconnect_from_networks(self):
networkConfigSection = [section for section in self.me.get_Section() if section.__class__.__name__ == "NetworkConfigSectionType"][0]
link = [link for link in networkConfigSection.get_Link() if link.get_type() == "application/vnd.vmware.vcloud.networkConfigSection+xml"][0]
networkConfigSection.NetworkConfig[:] = []
output = StringIO()
networkConfigSection.export(output,
0,
name_ = 'NetworkConfigSection',
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")
self.response = Http.put(link.get_href(), 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)
示例11: create
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def create(self, blueprint_id, deployment_id, inputs=None):
data = {
'blueprint_id': blueprint_id
}
if inputs:
data['inputs'] = inputs
headers = self.score.get_headers()
headers['Content-type'] = 'application/json'
self.score.response = Http.put(self.score.url +
'/deployments/%s' % deployment_id,
data=json.dumps(data),
headers=headers,
verify=self.score.verify,
logger=self.logger)
if self.score.response.status_code != requests.codes.ok:
raise exceptions.from_response(self.score.response)
return json.loads(self.score.response.content)
示例12: allocate_public_ip
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def allocate_public_ip(self):
api_version = "5.11"
headers = dict(self.headers)
headers["Accept"] = "application/*+xml;version={0}".format(api_version)
href = self.me.get_href() + "/action/manageExternalIpAddresses"
body = """
<ExternalIpAddressActionList
xmlns="http://www.vmware.com/vcloud/networkservice/1.0">
<Allocation>
<NumberOfExternalIpAddressesToAllocate>1</NumberOfExternalIpAddressesToAllocate>
</Allocation>
</ExternalIpAddressActionList>
"""
self.response = Http.put(href, data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
task = taskType.parseString(self.response.content, True)
return task
示例13: _upload
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def _upload(self, tar_file,
blueprint_id,
application_file_name=None):
query_params = {}
if application_file_name is not None:
query_params['application_file_name'] = \
urllib.quote(application_file_name)
uri = '/blueprints/{0}'.format(blueprint_id)
url = '{0}{1}'.format(self.score.url, uri)
headers = self.score.get_headers()
with open(tar_file, 'rb') as f:
self.score.response = Http.put(url, headers=headers, params=query_params,
data=f, verify=self.score.verify, logger=self.logger)
if self.score.response.status_code != 201:
raise Exception(self.score.response.status_code)
return self.score.response.json()
示例14: deallocate_public_ip
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
def deallocate_public_ip(self, ip_address):
api_version = '5.11'
headers = dict(self.headers)
headers['Accept']='application/*+xml;version={0}'.format(api_version)
href = self.me.get_href() + '/action/manageExternalIpAddresses'
body = """
<ExternalIpAddressActionList
xmlns="http://www.vmware.com/vcloud/networkservice/1.0">
<Deallocation>
<ExternalIpAddress>{0}</ExternalIpAddress>
</Deallocation>
</ExternalIpAddressActionList>
""".format(ip_address)
self.response = Http.put(href, data=body, headers=headers,
verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
task = taskType.parseString(self.response.content, True)
return task
示例15: customize_guest_os
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import put [as 别名]
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))