Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete_disk(self, id):
link = filter(lambda link: link.get_href().endswith(id), self.get_diskRefs())
if len(link)>0:
response = requests.delete(link[0].get_href(), headers=self.headers)
if response.status_code == requests.codes.accepted:
task = taskType.parseString(response.content, True)
return (True, task)
else:
return(False, response.content)
else:
return(False, 'disk not found')
headers = dict(self.headers)
headers['Accept'] = 'application/*+xml;version={0}'.format(api_version)
href = self.me.get_href() + '/action/manageExternalIpAddresses'
body = """
{0}
""".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
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
"").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(
vms[0].get_href() + '/guestCustomizationSection/',
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))
def get_task(self, task, mode=None):
response = requests.get(task.get_href(), headers = self.headers)
if response.status_code == requests.codes.ok:
task = taskType.parseString(response.content, True)
if mode == "json":
print ghf.task_json(response.content)
else:
if mode == "table":
print ghf.task_table(response.content)
else:
pass
return (True, task)
else:
ghf.print_xml_error(response.content, args["--json"])
return (False, None)
headers = dict(self.headers)
headers['Accept'] = 'application/*+xml;version={0}'.format(api_version)
href = self.me.get_href() + '/action/manageExternalIpAddresses'
body = """
1
"""
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
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
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)
link = filter(
lambda link: link.get_rel() == 'edit',
networkConnectionSection.get_Link())
body = output.getvalue().replace("vmw:Info", "ovf:Info")
headers = self.headers
headers['Content-type'] = link[0].get_type()
self.response = Http.put(
link[0].get_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')