コード例 #1
0
ファイル: client.py プロジェクト: hitsumabushi/nsxramlclient
 def extract_resource_body_schema(self, searched_resource, method):
     # NOTE: THis method is deprecated and will be removed in future version
     xml_schema_result = self._nsxraml.get_xml_schema_by_displayname(searched_resource, method)
     print '\033[91m' + "DEPRECATION WARNING: This method is deprecated in nsxramlclient v2.x and " \
                        "will be removed in future.\nPlease start using the method extract_resource_body_example " \
                        "instead.\nThis method does not support the NSXv 6.2.4 and later RAML specs" + '\033[0m'
     return xmloperations.xml_to_dict(xml_schema_result)
コード例 #2
0
    def do_request(self, method, url, data=None, headers=None, params=None):
        """
        Handle API requests / responses transport

        :param method: HTTP method to use as string
        :param data: Any data as PyDict (will be converted to XML string)
        :param headers: Any data as PyDict
        :return: If response is XML then an xml.etree.ElementTree else the raw content
        :raise: Any unsuccessful HTTP response code if fail_mode=raise
        """

        response_content = None
        if data:
            if headers:
                headers.update({'Content-Type': 'application/xml'})
            else:
                headers = {'Content-Type': 'application/xml'}

            if self._debug:
                print md.parseString(data).toprettyxml()

        response = self._session.request(method,
                                         url,
                                         headers=headers,
                                         params=params,
                                         data=data)

        if 'content-type' in response.headers:
            if response.headers['content-type'].find('application/xml') != -1:
                response_content = xmloperations.xml_to_dict(
                    et.fromstring(response.content))
            elif response.headers['content-type'].find(
                    'application/json') != -1:
                response_content = json.loads(response.content)
            else:
                response_content = response.content

        response_odict = OrderedDict([('status', response.status_code),
                                      ('body', response_content),
                                      ('location', None), ('objectId', None),
                                      ('Etag', None)])

        if 'location' in response.headers:
            response_odict['location'] = response.headers['location']
            response_odict['objectId'] = response.headers['location'].split(
                '/')[-1]

        if 'Etag' in response.headers:
            response_odict['Etag'] = response.headers['Etag']

        if response.status_code not in [200, 201, 204]:
            if self.fail_mode == 'exit':
                sys.exit('receive bad status code {}\n{}'.format(
                    response.status_code, response_content))
            elif self.fail_mode == 'raise':
                raise NsxError(response.status_code, response_content)
            elif self.fail_mode == 'continue':
                pass

        return response_odict
コード例 #3
0
    def do_request(self, method, url, data=None, headers=None, params=None):
        """
        Handle API requests / responses transport

        :param method: HTTP method to use as string
        :param data: Any data as PyDict (will be converted to XML string)
        :param headers: Any data as PyDict
        :return: If response is XML then an xml.etree.ElementTree else the raw content
        :raise: Any unsuccessful HTTP response code
        """

        response_content = None
        if data:
            if headers:
                headers.update({"Content-Type": "application/xml"})
            else:
                headers = {"Content-Type": "application/xml"}

            if self._debug:
                print md.parseString(data).toprettyxml()

        response = self._session.request(method, url, headers=headers, params=params, data=data)

        if response.status_code not in [200, 201, 204]:
            if "content-type" in response.headers:
                if response.headers["content-type"].find("text/html") != -1:
                    response_content = self._html2text(response.content)
                elif response.headers["content-type"].find("application/xml") != -1:
                    response_content = xmloperations.pretty_xml(response.content)
                else:
                    response_content = response.content
            else:
                response_content = response.content

            sys.exit("receive bad status code {}\n{}".format(response.status_code, response_content))

        elif "content-type" in response.headers:
            if response.headers["content-type"].find("application/xml") != -1:
                response_content = xmloperations.xml_to_dict(et.fromstring(response.content))
            else:
                response_content = response.content

        response_odict = OrderedDict(
            [
                ("status", response.status_code),
                ("body", response_content),
                ("location", None),
                ("objectId", None),
                ("Etag", None),
            ]
        )

        if "location" in response.headers:
            response_odict["location"] = response.headers["location"]
            response_odict["objectId"] = response.headers["location"].split("/")[-1]

        if "Etag" in response.headers:
            response_odict["Etag"] = response.headers["Etag"]

        return response_odict
コード例 #4
0
 def extract_resource_body_schema(self, searched_resource, method):
     # NOTE: THis method is deprecated and will be removed in future version
     xml_schema_result = self._nsxraml.get_xml_schema_by_displayname(searched_resource, method)
     print '\033[91m' + "DEPRECATION WARNING: This method is deprecated in nsxramlclient v2.x and " \
                        "will be removed in future.\nPlease start using the method extract_resource_body_example " \
                        "instead.\nThis method does not support the NSXv 6.2.4 and later RAML specs" + '\033[0m'
     return xmloperations.xml_to_dict(xml_schema_result)
コード例 #5
0
ファイル: client.py プロジェクト: horizonair/nsxramlclient
 def extract_resource_body_example(self,
                                   searched_resource,
                                   method,
                                   remove_content=None,
                                   remove_comments=None):
     xml_schema_result = self._nsxraml.get_xml_example_by_displayname(
         searched_resource,
         method,
         remove_comments=remove_comments,
         remove_content=remove_content)
     return xmloperations.xml_to_dict(xml_schema_result)
コード例 #6
0
    def do_request(self, method, url, data=None, headers=None, params=None):
        """
        Handle API requests / responses transport

        :param method: HTTP method to use as string
        :param data: Any data as PyDict (will be converted to XML string)
        :param headers: Any data as PyDict
        :return: If response is XML then an xml.etree.ElementTree else the raw content
        :raise: Any unsuccessful HTTP response code
        """

        response_content = None
        if data:
            if headers:
                headers.update({'Content-Type': 'application/xml'})
            else:
                headers = {'Content-Type': 'application/xml'}

            if self._debug:
                print md.parseString(data).toprettyxml()

        response = self._session.request(method, url, headers=headers, params=params, data=data)

        if response.status_code not in [200, 201, 204]:
            if 'content-type' in response.headers:
                if response.headers['content-type'].find('text/html') != -1:
                    response_content = self._html2text(response.content)
                elif response.headers['content-type'].find('application/xml') != -1:
                    response_content = xmloperations.pretty_xml(response.content)
                else:
                    response_content = response.content
            else:
                response_content = response.content

            sys.exit('receive bad status code {}\n{}'.format(response.status_code, response_content))

        elif 'content-type' in response.headers:
            if response.headers['content-type'].find('application/xml') != -1:
                response_content = xmloperations.xml_to_dict(et.fromstring(response.content))
            else:
                response_content = response.content

        response_odict = OrderedDict([('status', response.status_code), ('body', response_content),
                                      ('location', None), ('objectId', None), ('Etag', None)])

        if 'location' in response.headers:
            response_odict['location'] = response.headers['location']
            response_odict['objectId'] = response.headers['location'].split('/')[-1]

        if 'Etag' in response.headers:
            response_odict['Etag'] = response.headers['Etag']

        return response_odict
コード例 #7
0
 def extract_resource_body_schema(self, searched_resource, method):
     xml_schema_result = self._nsxraml.get_xml_schema_by_displayname(
         searched_resource, method)
     return xmloperations.xml_to_dict(xml_schema_result)
コード例 #8
0
ファイル: client.py プロジェクト: YOMOGItaro/nsxramlclient
 def extract_resource_body_schema(self, searched_resource, method):
     xml_schema_result = self._nsxraml.get_xml_schema_by_displayname(searched_resource, method)
     return xmloperations.xml_to_dict(xml_schema_result)