def delete_catalog(self, catalog_name): admin_url = None if not self.vcloud_session or not self.vcloud_session.organization: return False if 'ondemand' == self.service_type: refs = filter(lambda ref: ref.type_ == 'application/vnd.vmware.admin.organization+xml', self.vcloud_session.organization.Link) if len(refs) == 1: admin_url = refs[0].href else: refs = filter(lambda ref: ref.type_ == 'application/vnd.vmware.admin.catalog+xml', self.vcloud_session.organization.Link) if len(refs) == 1: admin_url = refs[0].href[:refs[0].href.rindex('/')] if admin_url: self.response = Http.get(admin_url, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.ok: adminOrg = vCloudEntities.parseString(self.response.content, True) if adminOrg and adminOrg.Catalogs and adminOrg.Catalogs.CatalogReference: catRefs = filter(lambda ref: ref.name == catalog_name and ref.type_ == 'application/vnd.vmware.admin.catalog+xml', adminOrg.Catalogs.CatalogReference) if len(catRefs) == 1: self.response = Http.delete(catRefs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.no_content: return True return False
def unregister_extension(self, name, href): self.response = Http.delete(href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.no_content: return self.response.content else: raise Exception(self.response.status_code)
def delete(self, blueprint_id): self.score.response = Http.delete(self.score.url + '/blueprints/%s' % blueprint_id, headers=self.score.get_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)
def delete_catalog_item(self, catalog_name, item_name): for catalog in self.get_catalogs(): if catalog.CatalogItems and catalog.CatalogItems.CatalogItem: for item in catalog.CatalogItems.CatalogItem: if item_name == item.name: self.response = Http.delete(item.href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.no_content: return True return False
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
def delete_vdc_network(self, vdc_name, network_name): netref = self.get_admin_network_href(vdc_name, network_name) if netref is None: return (False, 'network not found') self.response = Http.delete(netref, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.accepted: task = taskType.parseString(self.response.content, True) return (True, task) else: return (False, self.response.content)
def delete_cluster(self, cluster_id): url = '%s/%s' % (self.api_url, cluster_id) self.response = Http.delete( url, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.accepted: return json.loads(self.response.content) else: raise Exception(self.response.status_code)
def delete(self, deployment_id, force_delete=False): self.score.response = Http.delete( self.score.url + '/deployments/%s' % deployment_id, params={"ignore_live_nodes": force_delete}, headers=self.score.get_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)
def delete_disk(self, vdc_name, name, id=None): vdc = self.get_vdc(vdc_name) refs = self.get_diskRefs(vdc) link = [] if id is not None: link = filter(lambda link: link.get_href().endswith('/'+id), refs) elif name is not None: link = filter(lambda link: link.get_name() == name, refs) if len(link) == 1: self.response = Http.delete(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger) if self.response.status_code == requests.codes.accepted: task = taskType.parseString(self.response.content, True) return (True, task) else: return(False, self.response.content) elif len(link) == 0: return(False, 'disk not found') elif len(link) > 1: return(False, 'more than one disks found with that name, use the disk id')
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
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
def delete(self, blueprint_id): self.score.response = Http.delete(self.score.url + '/blueprints/{0}'.format(blueprint_id), headers=self.score.get_headers(), verify=self.score.verify, logger=self.logger) if self.score.response.status_code == requests.codes.ok: return json.loads(self.score.response.content)
def delete_instance(self, instance): self.response = Http.delete(self.host + "/api/sc/instances/" + instance, headers=self._get_vcloud_headers(), verify=self.verify, logger=self.logger) print self.response.status_code, self.response.content