Пример #1
0
    def create(cls, client_obj, schema=None, parent_id=None, sync=False,
               timeout=None, client_class=None, schema_class=None, id_=None,
               **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))
        client_class_obj = cls.get_sdk_client_object(
            client_obj, parent_id=parent_id, client_class=client_class,
            schema_class=schema_class, id_=id_)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.POST,
                                                **kwargs)
        payload = utilities.map_attributes(cls._attribute_map, schema)
        pylogger.debug("Payload: %s" % payload)
        schema_class = (schema_class if schema_class else cls._schema_class)
        schema_class_obj = schema_class(payload)
        schema_object = client_class_obj.create(schema_object=schema_class_obj,
                                                url_parameters=url_parameters)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        if sync:
            cls.wait_for_realized_state(
                client_obj, id_=result_dict['id_'], timeout=timeout)
        return result_dict
Пример #2
0
    def get_allocations(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        cls._allocate_client_class = listallocations.ListIpPoolAllocations
        cls._allocate_schema_class = allocation_schema.\
            AllocationIpAddressListResultSchema

        pylogger.info("%s.get_allocations(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        allocate_client_class_obj = cls._allocate_client_class(
            connection_object=client_obj.connection,
            ippool_id=client_obj.id_)

        allocate_schema_object = cls._allocate_schema_class(payload)
        allocate_schema_object = allocate_client_class_obj.query(
            allocate_schema_object)

        schema_dict = allocate_schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            allocate_client_class_obj.last_calls_status_code)
        return result_dict
Пример #3
0
    def ping_client(cls, client_object, **kwargs):
        cls._client_class = ping.Ping
        cls._response_schema_class = pingstatus_schema.PingStatusSchema

        cls.sanity_check()
        client_class_obj = cls._client_class(
            connection_object=client_object.
            connection, addmessagingclient_id=client_object.id_)

        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        schema_object = client_class_obj.create()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        if verification_form['client_status'] == 'SUCCESS':
            verification_form['client_status'] = 'true'
        else:
            time.sleep(60)
            schema_object = client_class_obj.create()
            schema_dict = schema_object.get_py_dict_from_object()
            verification_form = utilities.map_attributes(
                cls._attribute_map, schema_dict, reverse_attribute_map=True)
            if verification_form['client_status'] == 'SUCCESS':
                verification_form['client_status'] = 'true'
            else:
                verification_form['client_status'] = 'false'

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #4
0
    def create(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        csr_id = schema['csr_id']

        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            generatecsr_id=csr_id)

        schema_object = cls._schema_class(payload)
        schema_object = client_class_obj.create(
            schema_object)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #5
0
    def get_allocations(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        cls._allocate_client_class = listallocations.ListIpPoolAllocations
        cls._allocate_schema_class = allocation_schema.\
            AllocationIpAddressListResultSchema

        pylogger.info("%s.get_allocations(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        allocate_client_class_obj = cls._allocate_client_class(
            connection_object=client_obj.connection, ippool_id=client_obj.id_)

        allocate_schema_object = cls._allocate_schema_class(payload)
        allocate_schema_object = allocate_client_class_obj.query(
            allocate_schema_object)

        schema_dict = allocate_schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            allocate_client_class_obj.last_calls_status_code)
        return result_dict
Пример #6
0
    def create(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        if kwargs['csr_id'] is None:
            raise ValueError('csr_id parameter is missing')

        csr_id = kwargs['csr_id']

        client_class_obj = cls._client_class(
            connection_object=client_obj.connection, generatecsr_id=csr_id)

        schema_object = cls._schema_class(payload)
        schema_object = client_class_obj.create(schema_object)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #7
0
    def ping_client(cls, client_object, **kwargs):
        cls._client_class = ping.Ping
        cls._response_schema_class = pingstatus_schema.PingStatusSchema

        cls.sanity_check()
        client_class_obj = cls._client_class(
            connection_object=client_object.connection,
            addmessagingclient_id=client_object.id_)

        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        schema_object = client_class_obj.create()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        if verification_form['client_status'] == 'SUCCESS':
            verification_form['client_status'] = 'true'
        else:
            time.sleep(60)
            schema_object = client_class_obj.create()
            schema_dict = schema_object.get_py_dict_from_object()
            verification_form = utilities.map_attributes(
                cls._attribute_map, schema_dict, reverse_attribute_map=True)
            if verification_form['client_status'] == 'SUCCESS':
                verification_form['client_status'] = 'true'
            else:
                verification_form['client_status'] = 'false'

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
    def test_attribute_mapping(self):
        self.log = logger.setup_logging(self.__class__.__name__)
        #Attribute map
        attribute_map = {
            'name': 'display_name',
            'summary': 'description',
            'begin': 'start',
            'ipv': 'ip_version',
            'ranges': 'allocation_ranges',
            'dns': 'dns_nameservers',
            'hop': 'next_hop'
        }

        #User dictionary
        py_dict = {'subnets':
                       [{'static_routes': [{'hop': '192.168.10.5', 'destination_cidr': '192.168.10.0/24'}],
                         'ranges': [{'start': '192.168.1.2', 'end': '192.168.1.6'},
                                    {'start': '192.168.1.10', 'end': '192.168.1.100'}],
                         'dns': ['10.10.10.11', '10.10.10.12'],
                         'gateway_ip': '192.168.1.1',
                         'ipv': 4,
                         'cidr': '192.168.1.0/24'},
                         {'cidr': '192.175.1.0/24'}],
                         'name': 'TestIPPool-1-2091',
                         'summary': 'Test IPPool'}

        self.log.debug("User dictionary: %s" % py_dict)

        #Convert user dictionary to product expected form using map_attributes function
        py_dict = utilities.map_attributes(attribute_map, py_dict)

        #Dictionary in product expected form
        self.log.debug("Dictionary in product expected form:: %s" % py_dict)

        self.assertTrue("name" not in py_dict.keys())
        self.assertTrue("display_name" in py_dict.keys())
        self.assertEqual(py_dict["display_name"], "TestIPPool-1-2091")
        self.assertTrue("summary" not in py_dict.keys())
        self.assertTrue("description" in py_dict.keys())
        self.assertEqual(py_dict["description"], "Test IPPool")

        #Convert product expected dictionary in user dictionary form using map_attributes function
        py_dict = utilities.map_attributes(attribute_map, py_dict, reverse_attribute_map=True)

        #Dictionary in user expected form
        self.log.debug("Dictionary in user expected form:: %s" % py_dict)

        self.assertTrue("display_name" not in py_dict.keys())
        self.assertTrue("name" in py_dict.keys())
        self.assertEqual(py_dict["name"], "TestIPPool-1-2091")
        self.assertTrue("description" not in py_dict.keys())
        self.assertTrue("summary" in py_dict.keys())
        self.assertEqual(py_dict["summary"], "Test IPPool")
Пример #9
0
 def get_logical_switch(cls, client_object, get_logical_switch=None):
     """
     Fetches logical switch information.
     """
     _ = get_logical_switch
     header_keys = ['VNI', 'Controller IP Address', 'Link Status']
     attribute_map = {
         'vni': 'switch_vni',
         'controller ip address': 'controller_ip',
         'link status': 'controller_status'
     }
     nsxa_socket = cls._get_nsxa_socket(client_object)
     cmd = ('%s -t %s vni/list ' % (cls.CLI, nsxa_socket))
     out = client_object.connection.request(cmd).response_data
     horizontal_parser = horizontal_table_parser.HorizontalTableParser()
     switch_dicts = horizontal_parser.get_parsed_data(
         out, header_keys=header_keys)['table']
     for switch_dict in switch_dicts:
         replication_mode = cls.get_replication_mode(
             client_object, switch_vni=switch_dict['vni'])
         switch_dict['replication_mode'] = replication_mode
         for dict_key in switch_dict.keys():
             switch_dict[dict_key] = switch_dict[dict_key].lower()
     mapped_pydict = utilities.map_attributes(attribute_map,
                                              {'table': switch_dicts})
     return logical_switch_schema.LogicalSwitchSchema(py_dict=mapped_pydict)
Пример #10
0
    def get_vtep_detail(cls, client_object, **kwargs):
        """
        Returns parsed data as dictionary for all vtep(vxlan vmknic)
        information that exists on the host.
        """
        cmd = 'net-vdl2 -l'
        raw_data = client_object.connection.request(cmd).response_data
        vertical_data = vertical_parser.get_parsed_data(
            raw_data, delimiter=':\t', lowercase_data=False)['table']

        segmentid = None
        for key in vertical_data.keys():
            if 'vxlan vds' in key:
                segmentid = vertical_data.get(key)['Segment ID']
                break

        adapterinfo = cls.get_adapter_info(client_object)['table']
        merged_info = []
        for adpter in adapterinfo:
            if adpter['netstack'] == 'vxlan' and adpter['ip_family'] == 'IPv4':
                adpter.update({'segment_id': segmentid})
                merged_info.append(adpter)

        attribute_map = {'ip': 'adapter_ip', 'mac': 'adapter_mac'}

        mapped_pydicts = []
        for info in merged_info:
            mapped_pydicts.append(utilities.map_attributes(
                attribute_map, info))

        return vtep_table_schema.VtepTableSchema({'table': mapped_pydicts})
Пример #11
0
    def get_key_sizes(cls, client_obj, **kwargs):
        cls._client_class = getkeysizes.GetKeySizes
        cls._schema_class = intlist_schema.IntListSchema
        cls._list_schema_class = intlist_schema.IntListSchema
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s " %
                            cls.__name__)

        pylogger.info("%s.get_key_sizes" % cls.__name__)

        client_class_obj = cls._client_class(
            connection_object=client_obj.connection, param_1_id=client_obj.id_)

        list_schema_object = cls._list_schema_class()
        list_schema_object = client_class_obj.query(list_schema_object)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #12
0
    def query(cls, client_obj, parent_id=None, **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s " %
                            cls.__name__)

        pylogger.info("%s.query" % cls.__name__)

        client_class_obj = cls.get_sdk_client_object(client_obj,
                                                     parent_id=parent_id)

        list_schema_object = cls._list_schema_class()
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)
        list_schema_object = client_class_obj.query(
            schema_object=list_schema_object, url_parameters=url_parameters)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #13
0
    def update(cls,
               client_obj,
               id_=None,
               schema=None,
               parent_id=None,
               merge=None,
               client_class=None,
               schema_class=None,
               **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        if merge is None:
            merge = cls._merge_flag_default
        payload = utilities.map_attributes(cls._attribute_map, schema)
        client_class_obj = cls.get_sdk_client_object(client_obj,
                                                     parent_id=parent_id,
                                                     client_class=client_class,
                                                     schema_class=schema_class,
                                                     id_=id_)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.PUT,
                                                **kwargs)
        _ = kwargs.pop('query_params', None)
        merged_object = client_class_obj.update(py_dict=payload,
                                                object_id=id_,
                                                merge=merge,
                                                url_parameters=url_parameters,
                                                **kwargs)

        result_dict = merged_object.get_py_dict_from_object()
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #14
0
    def read(cls,
             client_obj,
             id_=None,
             parent_id=None,
             client_class=None,
             schema_class=None,
             **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        client_class_obj = cls.get_sdk_client_object(client_obj,
                                                     parent_id=parent_id,
                                                     client_class=client_class,
                                                     schema_class=schema_class,
                                                     **kwargs)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)

        schema_object = client_class_obj.read(object_id=id_,
                                              url_parameters=url_parameters)
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #15
0
    def get_arp_table(cls, client_object, switch_vni=None):
        """
        Fetches the ARP table for the logical switch.

        @param switch_vni: VNI to identify the logical switch.
        @type switch_vni: int
        @return: Returns the ARPTableSchema object.
        @rtype: arp_table_schema.ARPTableSchema
        """
        attribute_map = {
            'mac address': 'adapter_mac',
            'ip address': 'adapter_ip'
        }
        nsxa_socket = cls._get_nsxa_socket(client_object)
        cmd = ('%s -t %s vni/arp-table %s' %
               (cls.CLI, nsxa_socket, switch_vni))
        out = client_object.connection.request(cmd).response_data.split('\n')
        # Skip the VNI number in the output.
        raw_table_data = '\n'.join(out[1:])
        header_keys = ["IP Address", "Mac Address"]
        parser = horizontal_table_parser.HorizontalTableParser()
        parsed_data = parser.get_parsed_data(raw_table_data,
                                             header_keys=header_keys)
        mapped_pydict = utilities.map_attributes(attribute_map, parsed_data)
        return arp_table_schema.ARPTableSchema(py_dict=mapped_pydict)
Пример #16
0
    def query(cls, client_obj, **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s " %
                            cls.__name__)

        pylogger.info("%s.query" % cls.__name__)

        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            url_prefix=cls._url_prefix)
        client_class_obj.set_endpoints("/trust-management/crls")

        list_schema_object = cls._list_schema_class()
        list_schema_object = client_class_obj.query(list_schema_object)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #17
0
    def get_distributed_clients(cls,
                                client_object,
                                broker_list=None,
                                **kwargs):
        if type(broker_list) is not list:
            raise ValueError('Incorrect value provided for broker_list. '
                             'Incorrect Type: %s' % type(broker_list))

        client_count = 0
        cls._response_schema_class = messagingclientlistresult_schema.\
            MessagingClientListResultSchema
        client_class_obj = cls._client_class(
            connection_object=client_object.connection)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        for broker in broker_list:
            parameters = {'broker_id': broker['broker_id']}
            schema_object = client_class_obj.read(url_parameters=parameters)
            schema_dict = schema_object.get_py_dict_from_object()
            verification_form = utilities.map_attributes(
                cls._attribute_map, schema_dict, reverse_attribute_map=True)
            client_count += verification_form['result_count']
            pylogger.info(
                "Broker-id: %s , Client count:%s" %
                (broker['broker_id'], verification_form['result_count']))

        result_dict = dict()
        result_dict['result_count'] = client_count
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #18
0
    def get_vtep_detail(cls, client_object, **kwargs):
        """
        Returns parsed data as dictionary for all vtep(vxlan vmknic)
        information that exists on the host.
        """
        cmd = 'net-vdl2 -l'
        raw_data = client_object.connection.request(cmd).response_data
        vertical_data = vertical_parser.get_parsed_data(
            raw_data, delimiter=':\t', lowercase_data=False)['table']

        segmentid = None
        for key in vertical_data.keys():
            if 'vxlan vds' in key:
                segmentid = vertical_data.get(key)['Segment ID']
                break

        adapterinfo = cls.get_adapter_info(client_object)['table']
        merged_info = []
        for adpter in adapterinfo:
            if adpter['netstack'] == 'vxlan' and adpter['ip_family'] == 'IPv4':
                adpter.update({'segment_id': segmentid})
                merged_info.append(adpter)

        attribute_map = {
            'ip': 'adapter_ip',
            'mac': 'adapter_mac'
        }

        mapped_pydicts = []
        for info in merged_info:
            mapped_pydicts.append(utilities.map_attributes(attribute_map,
                                                           info))

        return vtep_table_schema.VtepTableSchema({'table': mapped_pydicts})
Пример #19
0
    def update(cls, client_obj, id_=None, schema=None, parent_id=None,
               merge=None, client_class=None, schema_class=None, **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        if merge is None:
            merge = cls._merge_flag_default
        payload = utilities.map_attributes(cls._attribute_map, schema)
        client_class_obj = cls.get_sdk_client_object(
            client_obj, parent_id=parent_id, client_class=client_class,
            schema_class=schema_class, id_=id_)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.PUT,
                                                **kwargs)
        _ = kwargs.pop('query_params', None)
        merged_object = client_class_obj.update(py_dict=payload,
                                                object_id=id_,
                                                merge=merge,
                                                url_parameters=url_parameters,
                                                **kwargs)

        result_dict = merged_object.get_py_dict_from_object()
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #20
0
    def query(cls, client_obj, parent_id=None, **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s "
                            % cls.__name__)

        pylogger.info("%s.query" % cls.__name__)

        client_class_obj = cls.get_sdk_client_object(
            client_obj, parent_id=parent_id)

        list_schema_object = cls._list_schema_class()
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)
        list_schema_object = client_class_obj.query(
            schema_object=list_schema_object,
            url_parameters=url_parameters)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
    def get_aggregation_transportnode_status(cls, client_obj, **kwargs):
        """
        Get status summary of all transport nodes under MP.

        @type client_object: ManagerAPIClient
        @param client_object: Client object
        @rtype: dict
        @return: Dict having status details of all TNs.

        Endpoint:
        /aggregations/transport-node-status
        """
        attr_map = {'node_uuid': 'uuid',
                    'bfd_admin_down_count': 'admin_down_count',
                    'bfd_init_count': 'init_count',
                    'bfd_up_count': 'up_count',
                    'bfd_down_count': 'down_count'}
        client_class_obj = listtransportnodestatus.ListTransportNodeStatus(
            connection_object=client_obj.connection)
        status_schema_object = client_class_obj.read()
        status_schema_dict = status_schema_object.get_py_dict_from_object()
        mapped_dict = utilities.map_attributes(attr_map, status_schema_dict)
        result_dict = dict()
        result_dict['response'] = mapped_dict
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #22
0
    def query(cls, client_obj, **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s "
                            % cls.__name__)

        pylogger.info("%s.query" % cls.__name__)

        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            url_prefix=cls._url_prefix)
        client_class_obj.set_endpoints("/trust-management/certificates")

        list_schema_object = cls._list_schema_class()
        list_schema_object = client_class_obj.query(list_schema_object)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #23
0
    def get_distributed_clients(cls, client_object, broker_list=None,
                                **kwargs):
        if type(broker_list) is not list:
            raise ValueError('Incorrect value provided for broker_list. '
                             'Incorrect Type: %s' % type(broker_list))

        client_count = 0
        cls._response_schema_class = messagingclientlistresult_schema.\
            MessagingClientListResultSchema
        client_class_obj = cls._client_class(
            connection_object=client_object.connection)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        for broker in broker_list:
            parameters = {'broker_id': broker['broker_id']}
            schema_object = client_class_obj.read(url_parameters=parameters)
            schema_dict = schema_object.get_py_dict_from_object()
            verification_form = utilities.map_attributes(
                cls._attribute_map, schema_dict, reverse_attribute_map=True)
            client_count += verification_form['result_count']
            pylogger.info("Broker-id: %s , Client count:%s" %
                          (broker['broker_id'],
                           verification_form['result_count']))

        result_dict = dict()
        result_dict['result_count'] = client_count
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #24
0
    def get_aggregation_status(cls, client_obj, get_aggregation_status=None):
        """
        Get status summary of given transport node.

        @type client_object: TransportNodeAPIClient
        @param client_object: Client object
        @rtype: dict
        @return: Dict having status details of TN.

        Endpoint:
        /aggregations/<node-id>/transport-node-status
        """
        attr_map = {'node_uuid': 'uuid',
                    'bfd_admin_down_count': 'admin_down_count',
                    'bfd_init_count': 'init_count',
                    'bfd_up_count': 'up_count',
                    'bfd_down_count': 'down_count'}
        node_id = client_obj.id_
        # TODO(gangarm): Check if we can use a better name in product sdk for
        # param_1_id, which is essentially node id.
        client_class_obj = gettransportnodestatus.GetTransportNodeStatus(
            connection_object=client_obj.connection, param_1_id=node_id)
        status_schema_object = client_class_obj.read()
        status_schema_dict = status_schema_object.get_py_dict_from_object()
        mapped_dict = utilities.map_attributes(attr_map, status_schema_dict)
        result_dict = dict()
        result_dict['response'] = mapped_dict
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #25
0
    def create(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        if kwargs['ippool_id'] is None:
            raise Exception('ippool_id parameter is missing')

        if kwargs['allocation_action'] is None:
            raise Exception('allocation_action parameter is missing')

        allocate_ippool_id = kwargs['ippool_id']
        allocation_action = kwargs['allocation_action']

        allocate_client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            ippool_id=allocate_ippool_id)

        allocate_schema_object = cls._schema_class(payload)
        allocate_schema_object = allocate_client_class_obj.create(
            allocate_schema_object,
            url_parameters={'action': allocation_action})

        #
        # For both operations - IP address Allocate and Release
        # create method is used.
        # While Allocation it returns schema with allocation id
        # While Release it does not return any schema
        #

        if allocate_schema_object is not None:
            schema_dict = allocate_schema_object.get_py_dict_from_object()
        else:
            schema_dict = {'id_': ''}

        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            allocate_client_class_obj.last_calls_status_code)
        return result_dict
Пример #26
0
    def create(cls, client_obj, schema=None, **kwargs):
        cls.sanity_check()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))

        payload = utilities.map_attributes(cls._attribute_map, schema)

        if kwargs['ippool_id'] is None:
            raise Exception('ippool_id parameter is missing')

        if kwargs['allocation_action'] is None:
            raise Exception('allocation_action parameter is missing')

        allocate_ippool_id = kwargs['ippool_id']
        allocation_action = kwargs['allocation_action']

        allocate_client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            ippool_id=allocate_ippool_id)

        allocate_schema_object = cls._schema_class(payload)
        allocate_schema_object = allocate_client_class_obj.create(
            allocate_schema_object,
            url_parameters={'action': allocation_action})

        #
        # For both operations - IP address Allocate and Release
        # create method is used.
        # While Allocation it returns schema with allocation id
        # While Release it does not return any schema
        #

        if allocate_schema_object is not None:
            schema_dict = allocate_schema_object.get_py_dict_from_object()
        else:
            schema_dict = {'id_': ''}

        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            allocate_client_class_obj.last_calls_status_code)
        return result_dict
Пример #27
0
    def get_id_from_schema(cls,
                           client_obj,
                           schema=None,
                           parent_id=None,
                           **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s " %
                            cls.__name__)
        else:
            pylogger.debug("Getting ID with _list_schema_class: %r" %
                           cls._list_schema_class)

        pylogger.info("%s.get_id_from_schema(name=%s)" %
                      (cls.__name__, schema))
        user_schema = utilities.map_attributes(cls._attribute_map, schema)
        client_class_obj = cls.get_sdk_client_object(client_obj,
                                                     parent_id=parent_id)

        #
        # Creating list_schema_object of client and
        # sending it to query method. Query method will
        # fill this list_schema_object and return it back
        #
        list_schema_object = cls._list_schema_class()
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)
        list_schema_object = client_class_obj.query(
            schema_object=list_schema_object, url_parameters=url_parameters)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        #
        # Iterating through dictionary to match user_schema
        # with product_schema and get corresponding id
        #
        id_ = None
        for attribute in list_schema_dict:
            if type(list_schema_dict[attribute]) in [list]:
                for element in list_schema_dict[attribute]:
                    result = utilities.compare_schema(user_schema, element)
                    if result:
                        id_ = element['id']
                        pylogger.info('Id of matching object %s, %s' %
                                      (cls.__name__, id_))
                        break
        if id_ is None:
            pylogger.debug(
                "Failed to get ID from schema: %r\nlist_schema_dict:\n%s" %
                (list_schema_object, pprint.pformat(list_schema_dict)))
            raise errors.APIError(status_code=common.status_codes.NOT_FOUND)

        result_dict = dict()
        result_dict['id_'] = id_
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] =\
            client_class_obj.last_calls_status_code
        return result_dict
Пример #28
0
    def get_id_from_schema(cls, client_obj, schema=None, parent_id=None,
                           **kwargs):
        cls.sanity_check()
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s "
                            % cls.__name__)
        else:
            pylogger.debug("Getting ID with _list_schema_class: %r" %
                           cls._list_schema_class)

        pylogger.info("%s.get_id_from_schema(name=%s)" %
                      (cls.__name__, schema))
        user_schema = utilities.map_attributes(cls._attribute_map, schema)
        client_class_obj = cls.get_sdk_client_object(
            client_obj, parent_id=parent_id)

        #
        # Creating list_schema_object of client and
        # sending it to query method. Query method will
        # fill this list_schema_object and return it back
        #
        list_schema_object = cls._list_schema_class()
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)
        list_schema_object = client_class_obj.query(
            schema_object=list_schema_object,
            url_parameters=url_parameters)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        #
        # Iterating through dictionary to match user_schema
        # with product_schema and get corresponding id
        #
        id_ = None
        for attribute in list_schema_dict:
            if type(list_schema_dict[attribute]) in [list]:
                for element in list_schema_dict[attribute]:
                    result = utilities.compare_schema(user_schema, element)
                    if result:
                        id_ = element['id']
                        pylogger.info('Id of matching object %s, %s'
                                      % (cls.__name__, id_))
                        break
        if id_ is None:
            pylogger.debug(
                "Failed to get ID from schema: %r\nlist_schema_dict:\n%s" %
                (list_schema_object, pprint.pformat(list_schema_dict)))
            raise errors.APIError(status_code=common.status_codes.NOT_FOUND)

        result_dict = dict()
        result_dict['id_'] = id_
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] =\
            client_class_obj.last_calls_status_code
        return result_dict
    def get_ipfix_capture_data(cls,
                               client_object,
                               file_name=None,
                               read_filter=None,
                               port=None,
                               stop_capture=None,
                               **kwargs):
        """
        Fetches the IPFIX data captured by TShark.

        @type client_object: BaseClient
        @param client_object: Used to pass commands to the host.
        @type file_name: string
        @param file_name: Name/path of the capture file.
        @type read_filter: string
        @param read_filter: Read filter to use while reading the captured file.
        @type port: integer
        @param port: port for which captured traffic will be decoded as cflow.
        @type stop_capture: boolean
        @param stop_capture: Flag indicating whether an attempt should be made
            to stop the capture process first.
        """
        attribute_map = {
            'cflow.od_id': 'domain_id',
            'cflow.packets64': 'pktcount',
            'cflow.srcmac': 'src_mac',
            'cflow.dstmac': 'dst_mac',
            'cflow.dstaddr': 'dst_ip',
            'cflow.srcaddr': 'src_ip',
            'cflow.ip_version': 'ip_version',
            'cflow.protocol': 'protocol',
            'cflow.srcaddrv6': 'src_ipv6',
            'cflow.dstaddrv6': 'dst_ipv6',
            'ip.src': 'exporter_ip',
            'cflow.octets64': 'octets',
            'cflow.length_min': 'min_length',
            'cflow.length_max': 'max_length',
            'cflow.flowset_id': 'flowset_id'
        }
        if stop_capture:
            if not cls.stop_capture(client_object):
                pylogger.error('Failed to stop TShark capture process.')
        if port:
            read_filter = "-d udp.port==%s,cflow %s" % (port, read_filter)
        raw_data = cls.extract_capture_results(client_object,
                                               file_name=file_name,
                                               read_filter=read_filter)
        # Handle missing elements in a table by adding NULL string for parsing.
        while "\t\t" in raw_data:
            raw_data = raw_data.replace("\t\t", "\tNULL\t")
        while "\n\t" in raw_data:
            raw_data = raw_data.replace("\n\t", "\nNULL\t")
        parser = horizontal_table_parser.HorizontalTableParser()
        parsed_data = parser.get_parsed_data(raw_data)
        return utilities.map_attributes(attribute_map, parsed_data)
Пример #30
0
    def create(cls,
               client_obj,
               schema=None,
               parent_id=None,
               sync=False,
               timeout=None,
               client_class=None,
               schema_class=None,
               id_=None,
               **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                      (cls.__name__, schema, kwargs))
        client_class_obj = cls.get_sdk_client_object(client_obj,
                                                     parent_id=parent_id,
                                                     client_class=client_class,
                                                     schema_class=schema_class,
                                                     id_=id_)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.POST,
                                                **kwargs)
        payload = utilities.map_attributes(cls._attribute_map, schema)
        pylogger.debug("Payload: %s" % payload)
        schema_class = (schema_class if schema_class else cls._schema_class)
        schema_class_obj = schema_class(payload)
        schema_object = client_class_obj.create(schema_object=schema_class_obj,
                                                url_parameters=url_parameters)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        if sync:
            cls.wait_for_realized_state(client_obj,
                                        id_=result_dict['id_'],
                                        timeout=timeout)
        return result_dict
Пример #31
0
 def update_with_param_id(cls, client_obj, param_id='', schema=None,
                          **kwargs):
     cls.sanity_check()
     pylogger.info("%s.update_with_param_id" % cls.__name__)
     payload = utilities.map_attributes(cls._attribute_map, schema)
     client_class_obj = cls._client_class(client_obj.connection,
                                          '/api/v1', param_id)
     client_class_obj.schema_class = (cls._schema_class.__module__ + '.' +
                                      cls._schema_class.__name__)
     merged_object = client_class_obj.update(payload, **kwargs)
     result_dict = merged_object.get_py_dict_from_object()
     result_dict['response_data'] = dict()
     result_dict['response_data']['status_code'] = (
         client_class_obj.last_calls_status_code)
     return result_dict
Пример #32
0
 def get_vtep_table(cls, client_object, switch_vni=None,
                    host_switch_name=None):
     """
     Fetches the VTEP table i.e. the IP addresses of the VTEPs in this
     logical switch/VNI.
     """
     vtep_labels = cls.get_vtep_label(
         client_object, switch_vni=switch_vni)
     attribute_map = {'vtep label': 'adapter_ip'}
     for vtep_label in vtep_labels['table']:
         label = vtep_label['vtep label']
         vtep_label['vtep label'] = cls.get_vtep_ip_by_label(
             client_object, label=label)
     mapped_pydict = utilities.map_attributes(attribute_map, vtep_labels)
     return vtep_table_schema.VtepTableSchema(py_dict=mapped_pydict)
Пример #33
0
    def _perform_action(cls, client_obj, credential=None, host_id=None):
        cls.sanity_check()
        cls.assign_response_schema_class()

        client_class_obj = cls.get_sdk_client_object(
            client_object=client_obj,
            host_id=host_id)

        payload = utilities.map_attributes(cls._attribute_map, credential)
        pylogger.debug("Payload: %s" % payload)

        schema_class_obj = cls._schema_class(payload)
        response_schema_object = client_class_obj.create(
            schema_object=schema_class_obj)

        schema_dict = response_schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #34
0
 def purge(cls, client_obj, schema=None, **kwargs):
     cls.sanity_check()
     cls._client_class = purgeclusterbackups.PurgeClusterBackups
     cls._schema_class = restorerequestschema.RestoreRequestSchema
     pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                   (cls.__name__, schema, kwargs))
     client_class_obj = cls.get_sdk_client_object(client_obj)
     payload = utilities.map_attributes(cls._attribute_map, schema)
     pylogger.debug("Payload: %s" % payload)
     schema_class_obj = cls._schema_class(payload)
     client_class_obj.create(schema_object=schema_class_obj)
     result_dict = dict()
     result_dict['response_data'] = dict()
     result_dict['response_data']['status_code'] = \
         client_class_obj.last_calls_status_code
     return result_dict
Пример #35
0
 def get_vtep_table(cls,
                    client_object,
                    switch_vni=None,
                    host_switch_name=None):
     """
     Fetches the VTEP table i.e. the IP addresses of the VTEPs in this
     logical switch/VNI.
     """
     vtep_labels = cls.get_vtep_label(client_object, switch_vni=switch_vni)
     attribute_map = {'vtep label': 'adapter_ip'}
     for vtep_label in vtep_labels['table']:
         label = vtep_label['vtep label']
         vtep_label['vtep label'] = cls.get_vtep_ip_by_label(client_object,
                                                             label=label)
     mapped_pydict = utilities.map_attributes(attribute_map, vtep_labels)
     return vtep_table_schema.VtepTableSchema(py_dict=mapped_pydict)
Пример #36
0
    def read_with_param_id(cls, client_obj, param_id='', **kwargs):
        cls.sanity_check()
        pylogger.info("%s.read_with_param_id" % cls.__name__)
        client_class_obj = cls._client_class(client_obj.connection, '/api/v1',
                                             param_id)
        client_class_obj.schema_class = (cls._schema_class.__module__ + '.' +
                                         cls._schema_class.__name__)
        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #37
0
    def get_interface_statistics(cls, client_object, interface_id=None,
                                 **kwargs):
        cls.sanity_check()
        client_class_obj = readnodeinterfacestatistics.\
            ReadNodeInterfaceStatistics(connection_object=client_object.
                                        connection,
                                        listnodeinterfaces_id=interface_id)
        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #38
0
    def read_with_param_id(cls, client_obj, param_id='', **kwargs):
        cls.sanity_check()
        pylogger.info("%s.read_with_param_id" % cls.__name__)
        client_class_obj = cls._client_class(client_obj.connection,
                                             '/api/v1', param_id)
        client_class_obj.schema_class = (cls._schema_class.__module__ + '.' +
                                         cls._schema_class.__name__)
        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #39
0
 def purge(cls, client_obj, schema=None, **kwargs):
     cls.sanity_check()
     cls._client_class = purgenodebackups.PurgeNodeBackups
     cls._schema_class = restorerequestschema.RestoreRequestSchema
     pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                   (cls.__name__, schema, kwargs))
     client_class_obj = cls.get_sdk_client_object(
         client_obj)
     payload = utilities.map_attributes(cls._attribute_map, schema)
     pylogger.debug("Payload: %s" % payload)
     schema_class_obj = cls._schema_class(payload)
     client_class_obj.create(schema_object=schema_class_obj)
     result_dict = dict()
     result_dict['response_data'] = dict()
     result_dict['response_data']['status_code'] = \
         client_class_obj.last_calls_status_code
     return result_dict
Пример #40
0
 def update_with_param_id(cls,
                          client_obj,
                          param_id='',
                          schema=None,
                          **kwargs):
     cls.sanity_check()
     pylogger.info("%s.update_with_param_id" % cls.__name__)
     payload = utilities.map_attributes(cls._attribute_map, schema)
     client_class_obj = cls._client_class(client_obj.connection, '/api/v1',
                                          param_id)
     client_class_obj.schema_class = (cls._schema_class.__module__ + '.' +
                                      cls._schema_class.__name__)
     merged_object = client_class_obj.update(payload, **kwargs)
     result_dict = merged_object.get_py_dict_from_object()
     result_dict['response_data'] = dict()
     result_dict['response_data']['status_code'] = (
         client_class_obj.last_calls_status_code)
     return result_dict
Пример #41
0
    def read(cls, client_object, **kwargs):
        client_type = None
        broker_id = None
        try:
            client_type = kwargs['client_type']
        except Exception:
            pass

        try:
            broker_id = kwargs['broker_id']
        except Exception:
            pass

        cls.sanity_check()
        if client_type is not None or broker_id is not None:
            cls._response_schema_class = messagingclientlistresult_schema.\
                MessagingClientListResultSchema
            cls.assign_response_schema_class()

        client_class_obj = cls._client_class(
            connection_object=client_object.connection)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        if client_type is not None:
            parameters = {'client_type': client_type}
            schema_object = client_class_obj.read(url_parameters=parameters)
        elif broker_id is not None:
            parameters = {'broker_id': broker_id}
            schema_object = client_class_obj.read(url_parameters=parameters)
        else:
            schema_object = client_class_obj.read(object_id=client_object.id_)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #42
0
    def get_interface_statistics(cls,
                                 client_object,
                                 interface_id=None,
                                 **kwargs):
        cls.sanity_check()
        client_class_obj = readnodeinterfacestatistics.\
            ReadNodeInterfaceStatistics(connection_object=client_object.
                                        connection,
                                        listnodeinterfaces_id=interface_id)
        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #43
0
 def restore(cls, client_obj, schema=None, **kwargs):
     cls.sanity_check()
     cls._client_class = clusterrestore.ClusterRestore
     cls._schema_class = restorerequestschema.RestoreRequestSchema
     kwargs.update({'filename': 'cluster_backup.zip'})
     schema = kwargs
     pylogger.info("%s.create(schema=%s, kwargs=%s)" %
                   (cls.__name__, schema, kwargs))
     client_class_obj = cls.get_sdk_client_object(
         client_obj)
     payload = utilities.map_attributes(cls._attribute_map, schema)
     pylogger.debug("Payload: %s" % payload)
     schema_class_obj = cls._schema_class(payload)
     client_class_obj.create(schema_object=schema_class_obj)
     result_dict = dict()
     result_dict['response_data'] = dict()
     result_dict['response_data']['status_code'] = \
         client_class_obj.last_calls_status_code
     return result_dict
Пример #44
0
    def read(cls, client_object, **kwargs):
        client_type = None
        broker_id = None
        try:
            client_type = kwargs['client_type']
        except Exception:
            pass

        try:
            broker_id = kwargs['broker_id']
        except Exception:
            pass

        cls.sanity_check()
        if client_type is not None or broker_id is not None:
            cls._response_schema_class = messagingclientlistresult_schema.\
                MessagingClientListResultSchema
            cls.assign_response_schema_class()

        client_class_obj = cls._client_class(
            connection_object=client_object.connection)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        if client_type is not None:
            parameters = {'client_type': client_type}
            schema_object = client_class_obj.read(url_parameters=parameters)
        elif broker_id is not None:
            parameters = {'broker_id': broker_id}
            schema_object = client_class_obj.read(url_parameters=parameters)
        else:
            schema_object = client_class_obj.read(object_id=client_object.id_)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #45
0
    def create(cls, client_object, **kwargs):
        cls._response_schema_class = \
            messagingclientlistresult_schema.MessagingClientListResultSchema
        cls.sanity_check()
        client_class_obj = cls._client_class(
            connection_object=client_object.connection)

        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #46
0
    def create(cls, client_object, **kwargs):
        cls._response_schema_class = \
            messagingclientlistresult_schema.MessagingClientListResultSchema
        cls.sanity_check()
        client_class_obj = cls._client_class(
            connection_object=client_object.connection)

        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)

        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #47
0
 def get_adapter_info(cls, client_object):
     """
     Returns parsed data as dictionary for all vmknic that exists on the
     host.
     """
     horizontal_parser = horizontal_table_parser.HorizontalTableParser()
     cmd = 'esxcfg-vmknic -l'
     header_keys = [
         'Interface', 'Port Group/DVPort', 'IP Family', 'IP Address',
         'Netmask', 'Broadcast', 'MAC Address', 'MTU', 'TSO MSS', 'Enabled',
         'Type'
     ]
     raw_data = client_object.connection.request(cmd).response_data
     horizontal_data = horizontal_parser.get_parsed_data(
         raw_data, expect_empty_fields=True,
         header_keys=header_keys)['table']
     vertical_parser = vertical_table_parser.VerticalTableParser()
     cmd = 'esxcli network ip interface list'
     raw_data = client_object.connection.request(cmd).response_data
     vertical_data = vertical_parser.get_parsed_data(
         raw_data, lowercase_data=False)['table']
     merged_info = []
     for horizontal_info in horizontal_data:
         for key in vertical_data:
             if horizontal_info['interface'] == key:
                 horizontal_info.update(vertical_data[key])
                 merged_info.append(horizontal_info)
     attribute_map = {
         'port group/dvport': 'dvport',
         'ip family': 'ip_family',
         'ip address': 'ip',
         'mac address': 'mac',
         'tso mss': 'tso_mss',
         'Netstack Instance': 'netstack'
     }
     mapped_pydicts = []
     for info in merged_info:
         mapped_pydicts.append(utilities.map_attributes(
             attribute_map, info))
     return {'table': mapped_pydicts}
Пример #48
0
    def query_with_param_id(cls, client_obj, param_id='', **kwargs):
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s " %
                            cls.__name__)
        pylogger.info("%s.query_with_param_id" % cls.__name__)
        client_class_obj = cls._client_class(client_obj.connection, '/api/v1',
                                             param_id)

        list_schema_object = cls._list_schema_class()
        list_schema_object = client_class_obj.query(list_schema_object)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #49
0
    def query_with_param_id(cls, client_obj, param_id='', **kwargs):
        if cls._list_schema_class is None:
            raise TypeError("List schema class is not defined for %s "
                            % cls.__name__)
        pylogger.info("%s.query_with_param_id" % cls.__name__)
        client_class_obj = cls._client_class(client_obj.connection,
                                             '/api/v1', param_id)

        list_schema_object = cls._list_schema_class()
        list_schema_object = client_class_obj.query(list_schema_object)

        list_schema_dict = list_schema_object.get_py_dict_from_object()

        verification_form = utilities.map_attributes(
            cls._attribute_map, list_schema_dict, reverse_attribute_map=True)

        result_dict = dict()
        result_dict['response'] = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #50
0
    def update(cls, client_obj, id_=None, schema=None, **kwargs):
        cls._response_schema_class = crl_schema.CrlSchema
        cls.sanity_check()
        cls.assign_response_schema_class()

        payload = utilities.map_attributes(cls._attribute_map, schema)
        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            url_prefix=cls._url_prefix)
        client_class_obj.set_endpoints("/trust-management/crls")
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        merged_object = client_class_obj.update(payload,
                                                object_id=id_,
                                                **kwargs)

        result_dict = merged_object.get_py_dict_from_object()
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #51
0
    def read(cls, client_obj, id_=None, **kwargs):
        cls._response_schema_class = crl_schema.CrlSchema
        cls.sanity_check()
        cls.assign_response_schema_class()
        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            url_prefix=cls._url_prefix)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        client_class_obj.set_endpoints("/trust-management/crls")
        schema_object = client_class_obj.read(id_)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #52
0
    def read(cls, client_obj, id_=None, **kwargs):
        cls._response_schema_class = certificate_schema.CertificateSchema
        cls.sanity_check()
        cls.assign_response_schema_class()
        client_class_obj = cls._client_class(
            connection_object=client_obj.connection,
            url_prefix=cls._url_prefix)
        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        client_class_obj.set_endpoints("/trust-management/certificates")
        schema_object = client_class_obj.read(id_)

        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #53
0
    def read(cls, client_obj, id_=None, parent_id=None,
             client_class=None, schema_class=None, **kwargs):
        cls.sanity_check()
        cls.assign_response_schema_class()

        client_class_obj = cls.get_sdk_client_object(
            client_obj, parent_id=parent_id, client_class=client_class,
            schema_class=schema_class, **kwargs)
        url_parameters = cls.get_url_parameters(constants.HTTPVerb.GET,
                                                **kwargs)

        schema_object = client_class_obj.read(object_id=id_,
                                              url_parameters=url_parameters)
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #54
0
 def get_adapter_info(cls, client_object):
     """
     Returns parsed data as dictionary for all vmknic that exists on the
     host.
     """
     horizontal_parser = horizontal_table_parser.HorizontalTableParser()
     cmd = 'esxcfg-vmknic -l'
     header_keys = ['Interface', 'Port Group/DVPort', 'IP Family',
                    'IP Address', 'Netmask', 'Broadcast', 'MAC Address',
                    'MTU', 'TSO MSS', 'Enabled', 'Type']
     raw_data = client_object.connection.request(cmd).response_data
     horizontal_data = horizontal_parser.get_parsed_data(
         raw_data, expect_empty_fields=True,
         header_keys=header_keys)['table']
     vertical_parser = vertical_table_parser.VerticalTableParser()
     cmd = 'esxcli network ip interface list'
     raw_data = client_object.connection.request(cmd).response_data
     vertical_data = vertical_parser.get_parsed_data(
         raw_data, lowercase_data=False)['table']
     merged_info = []
     for horizontal_info in horizontal_data:
         for key in vertical_data:
             if horizontal_info['interface'] == key:
                 horizontal_info.update(vertical_data[key])
                 merged_info.append(horizontal_info)
     attribute_map = {
         'port group/dvport': 'dvport',
         'ip family': 'ip_family',
         'ip address': 'ip',
         'mac address': 'mac',
         'tso mss': 'tso_mss',
         'Netstack Instance': 'netstack'
     }
     mapped_pydicts = []
     for info in merged_info:
         mapped_pydicts.append(utilities.map_attributes(
             attribute_map, info))
     return {'table': mapped_pydicts}
Пример #55
0
    def heartbeat_status(cls, client_object, **kwargs):
        cls._client_class = getheartbeatstatus.GetHeartbeatStatus
        cls._response_schema_class = \
            heartbeatstatus_schema.HeartbeatStatusSchema

        cls.sanity_check()
        client_class_obj = cls._client_class(
            connection_object=client_object.
            connection, addmessagingclient_id=client_object.id_)

        client_class_obj.schema_class = (
            cls._response_schema_class.__module__ + '.' +
            cls._response_schema_class.__name__)
        schema_object = client_class_obj.read()
        schema_dict = schema_object.get_py_dict_from_object()
        verification_form = utilities.map_attributes(
            cls._attribute_map, schema_dict, reverse_attribute_map=True)

        result_dict = verification_form
        result_dict['response_data'] = dict()
        result_dict['response_data']['status_code'] = (
            client_class_obj.last_calls_status_code)
        return result_dict
Пример #56
0
    def get_arp_table(cls, client_object, switch_vni=None):
        """
        Fetches the ARP table for the logical switch.

        @param switch_vni: VNI to identify the logical switch.
        @type switch_vni: int
        @return: Returns the ARPTableSchema object.
        @rtype: arp_table_schema.ARPTableSchema
        """
        attribute_map = {'mac address': 'adapter_mac',
                         'ip address': 'adapter_ip'}
        nsxa_socket = cls._get_nsxa_socket(client_object)
        cmd = ('%s -t %s vni/arp-table %s' %
               (cls.CLI, nsxa_socket, switch_vni))
        out = client_object.connection.request(cmd).response_data.split('\n')
        # Skip the VNI number in the output.
        raw_table_data = '\n'.join(out[1:])
        header_keys = ["IP Address", "Mac Address"]
        parser = horizontal_table_parser.HorizontalTableParser()
        parsed_data = parser.get_parsed_data(raw_table_data,
                                             header_keys=header_keys)
        mapped_pydict = utilities.map_attributes(attribute_map, parsed_data)
        return arp_table_schema.ARPTableSchema(py_dict=mapped_pydict)
Пример #57
0
 def get_logical_switch(cls, client_object, get_logical_switch=None):
     """
     Fetches logical switch information.
     """
     _ = get_logical_switch
     header_keys = ['VNI', 'Controller IP Address', 'Link Status']
     attribute_map = {'vni': 'switch_vni',
                      'controller ip address': 'controller_ip',
                      'link status': 'controller_status'}
     nsxa_socket = cls._get_nsxa_socket(client_object)
     cmd = ('%s -t %s vni/list ' % (cls.CLI, nsxa_socket))
     out = client_object.connection.request(cmd).response_data
     horizontal_parser = horizontal_table_parser.HorizontalTableParser()
     switch_dicts = horizontal_parser.get_parsed_data(
         out, header_keys=header_keys)['table']
     for switch_dict in switch_dicts:
         replication_mode = cls.get_replication_mode(
             client_object, switch_vni=switch_dict['vni'])
         switch_dict['replication_mode'] = replication_mode
         for dict_key in switch_dict.keys():
             switch_dict[dict_key] = switch_dict[dict_key].lower()
     mapped_pydict = utilities.map_attributes(
         attribute_map, {'table': switch_dicts})
     return logical_switch_schema.LogicalSwitchSchema(py_dict=mapped_pydict)