How to use the pyvcloud.Http.get function in pyvcloud

To help you get started, we’ve selected a few pyvcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
"""
        Request a list of the Networks within a Virtual Data Center.

        :param vdc_name: (str): The virtual data center name.
        :return: (list of OrgVdcNetworkType)  A list of :class:`pyvcloud.schema.vcd.v1_5.schemas.vcloud.networkType.OrgVdcNetworkType` objects describing the available networks.

        **service type:** ondemand, subscription, vcd

        """
        result = []
        vdc = self.get_vdc(vdc_name)
        if not vdc:
            return result
        networks = vdc.get_AvailableNetworks().get_Network()
        for n in networks:
            self.response = Http.get(
                n.get_href(),
                headers=self.vcloud_session.get_vcloud_headers(),
                verify=self.verify,
                logger=self.logger)
            if self.response.status_code == requests.codes.ok:
                network = networkType.parseString(self.response.content, True)
                result.append(network)
            else:
                error = errorType.parseString(self.response.content, True)
                raise Exception(error.message)
        return result
github vmware / pyvcloud / pyvcloud / score.py View on Github external
def list(self):
        self.score.response = Http.get(self.score.url + '/blueprints',
                                       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)
github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
if not vdc:
            return gateway
        link = filter(lambda link: link.get_rel() ==
                      "edgeGateways", vdc.get_Link())
        self.response = Http.get(
            link[0].get_href(),
            headers=self.vcloud_session.get_vcloud_headers(),
            verify=self.verify,
            logger=self.logger)
        if self.response.status_code == requests.codes.ok:
            queryResultRecords = queryRecordViewType.parseString(
                self.response.content, True)
            if queryResultRecords.get_Record():
                for edgeGatewayRecord in queryResultRecords.get_Record():
                    if edgeGatewayRecord.get_name() == gateway_name:
                        self.response = Http.get(
                            edgeGatewayRecord.get_href(),
                            headers=self.vcloud_session.get_vcloud_headers(),
                            verify=self.verify,
                            logger=self.logger)
                        if self.response.status_code == requests.codes.ok:
                            gateway = Gateway(
                                networkType.parseString(
                                    self.response.content,
                                    True),
                                headers=self.vcloud_session.get_vcloud_headers(),
                                verify=self.verify,
                                busy=edgeGatewayRecord.isBusy,
                                log=self.log)
                            break
        else:
            error = errorType.parseString(self.response.content, True)
github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
catalog_items = filter(
                    lambda catalogItemRef: catalogItemRef.get_name() == template_name,
                    catalog.get_CatalogItems().get_CatalogItem())
                if len(catalog_items) == 1:
                    self.response = Http.get(
                        catalog_items[0].get_href(),
                        headers=self.vcloud_session.get_vcloud_headers(),
                        verify=self.verify,
                        logger=self.logger)
                    # use ElementTree instead because none of the types inside resources (not
                    # even catalogItemType) is able to parse the response
                    # correctly
                    catalogItem = ET.fromstring(self.response.content)
                    entity = [child for child in catalogItem if child.get(
                        "type") == "application/vnd.vmware.vcloud.vAppTemplate+xml"][0]
                    self.response = Http.get(
                        entity.get('href'),
                        headers=self.vcloud_session.get_vcloud_headers(),
                        verify=self.verify,
                        logger=self.logger)
                    if self.response.status_code == requests.codes.ok:
                        vAppTemplate = ET.fromstring(self.response.content)
                        for vm in vAppTemplate.iter(
                                '{http://www.vmware.com/vcloud/v1.5}Vm'):
                            return vm.get('href')

        return None
github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
Request the details of a specific Gateway Appliance within a Virtual Data Center.

        :param vdc_name: (str): The virtual data center name.
        :param gateway_name: (str): The requested gateway name.
        :return: (Gateway)  A :class:`.pyvcloud.gateway.Gateway` object describing the requested gateway.

        **service type:** ondemand, subscription, vcd

        """
        gateway = None
        vdc = self.get_vdc(vdc_name)
        if not vdc:
            return gateway
        link = filter(lambda link: link.get_rel() ==
                      "edgeGateways", vdc.get_Link())
        self.response = Http.get(
            link[0].get_href(),
            headers=self.vcloud_session.get_vcloud_headers(),
            verify=self.verify,
            logger=self.logger)
        if self.response.status_code == requests.codes.ok:
            queryResultRecords = queryRecordViewType.parseString(
                self.response.content, True)
            if queryResultRecords.get_Record():
                for edgeGatewayRecord in queryResultRecords.get_Record():
                    if edgeGatewayRecord.get_name() == gateway_name:
                        self.response = Http.get(
                            edgeGatewayRecord.get_href(),
                            headers=self.vcloud_session.get_vcloud_headers(),
                            verify=self.verify,
                            logger=self.logger)
                        if self.response.status_code == requests.codes.ok:
github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
def get_users(self):
        """
        Retrieves a collection of all users the authenticated API user has access to.

        :return: (list of str): list of users.

        **service type:**  vca

        """

        headers = self._get_vcloud_headers()
        headers['Accept'] = "application/json;version=%s;class=com.vmware.vchs.iam.api.schema.v2.classes.user.Users" % self.version
        self.response = Http.get(
            self.host + "/api/iam/Users",
            headers=headers,
            verify=self.verify,
            logger=self.logger)
        if self.response.status_code == requests.codes.ok:
            return json.loads(self.response.content)['users']
        else:
            error = errorType.parseString(self.response.content, True)
            raise Exception(error.message)
github vmware / pyvcloud / pyvcloud / vcloudair.py View on Github external
def get_template_href_from_catalog(self, catalog_name, template_name):

        catalogs = filter(lambda link: catalog_name == link.get_name() and link.get_type(
        ) == "application/vnd.vmware.vcloud.catalog+xml",
            self.vcloud_session.organization.get_Link())
        if len(catalogs) == 1:
            self.response = Http.get(
                catalogs[0].get_href(),
                headers=self.vcloud_session.get_vcloud_headers(),
                verify=self.verify,
                logger=self.logger)
            if self.response.status_code == requests.codes.ok:
                catalog = catalogType.parseString(self.response.content, True)
                catalog_items = filter(
                    lambda catalogItemRef: catalogItemRef.get_name() == template_name,
                    catalog.get_CatalogItems().get_CatalogItem())
                if len(catalog_items) == 1:
                    self.response = Http.get(
                        catalog_items[0].get_href(),
                        headers=self.vcloud_session.get_vcloud_headers(),
                        verify=self.verify,
                        logger=self.logger)
                    # use ElementTree instead because none of the types inside resources (not
github vmware / pyvcloud / pyvcloud / vcloudsession.py View on Github external
def login(self, password=None, token=None):
        if token:
            headers = {}
            headers["x-vcloud-authorization"] = token
            headers["Accept"] = "application/*+xml;version=" + self.version
            self.response = Http.get(self.org_url, headers=headers, verify=self.verify, logger=self.logger)
            if self.response.status_code == requests.codes.ok:
                self.token = token
                self.organization = organizationType.parseString(self.response.content, True)
                return True
            else:
                return False
        else:
            headers = {}
            headers["Accept"] = "application/*+xml;version=" + self.version
            self.response = Http.post(self.url, headers=headers, auth=(self.username + "@" + self.org, password), verify=self.verify, logger=self.logger)
            if self.response.status_code == requests.codes.ok:
                self.token = self.response.headers["x-vcloud-authorization"]
                self.session = sessionType.parseString(self.response.content, True)
                self.org_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.org+xml', self.session.Link)[0].href
                return True
            else:
github vmware / pyvcloud / pyvcloud / cluster.py View on Github external
def get_clusters(self):
        headers = self.vcloud_session.get_vcloud_headers()
        self.response = Http.get(self.api_url, headers=headers,
                                 verify=self.verify, logger=self.logger)
        if self.response.status_code == requests.codes.ok:
            return json.loads(self.response.content)
        else:
            raise Exception(self.response.status_code)