Ejemplo n.º 1
0
    def calculate_template_fields(object_type: ObjectType, templ_type: TemplateType, templ_fields: dict,
                                  mandatory_fields: list) -> dict:
        """
        Creates the sets of fields to be used in a template. The set includes mandatory and those that have been chosen
        by the user for the auction
        :param object_type          Object type
        :param templ_type:          Template type (data, options)
        :param templ_fields:        Field to include given by the user
        :param mandatory_fields:    Mandatory fields to include given by the template type
        :return: dictionary with key and field key
        """

        dict_return = {}
        # 1. insert the template mandatory fields.
        for field in mandatory_fields:
            dict_return[field.get_key()] = field

        # 2. insert other configurated fields.
        for field_key in templ_fields:
            include = False

            field = templ_fields[field_key]
            for (object_type_field, templ_type_field) in field.field_belong_to:
                if (object_type_field == object_type) and (templ_type_field == templ_type):
                    include = True
                    break

            if include:
                field_key = IpapFieldKey(field.field['eno'], field.field['ftype'])
                # Excludes field_keys already in the dictionary.
                if field_key.get_key() not in dict_return.keys():
                    dict_return[field_key.get_key()] = field_key

        return dict_return
Ejemplo n.º 2
0
    def get_non_mandatory_fields(self, action: Action, mandatory_fields: list) -> list:
        """
        Gets non mandatory fields from the action's config items.

        :param action: action associated with the auction
        :param mandatory_fields: mandatory fields for an option template.
        :return: non_mandatory field list.
        """
        non_mandatory = []

        items = action.get_config_params()
        for item in items.values():
            field = self.field_def_manager.get_field(item.name)

            # Checks it is not a mandatory field.
            is_mandatory: bool = False
            for mandatory_field in mandatory_fields:
                if mandatory_field.get_eno() == field['eno'] and mandatory_field.get_ftype() == field['ftype']:
                    is_mandatory = True
                    break

            if not is_mandatory:
                non_mandatory.append(IpapFieldKey(field['eno'], field['ftype']))

        return non_mandatory
Ejemplo n.º 3
0
 def get_field_at_pos(self, pos: int) -> IpapFieldKey:
     obj = lib.ipap_data_record_get_field_at_pos(self.obj, c_int(pos))
     if obj:
         value = IpapFieldKey(obj=obj)
         return value
     else:
         raise ValueError("Field at pos {0} was not found in data record".format(str(pos)))
Ejemplo n.º 4
0
    def build_field_sets(self):
        """
        Builds the field sets required for managing message between the server and the agents.
        """
        # Fill data auctions fields
        agent_session = set()
        agent_session.add(IpapFieldKey(self.field_def_manager.get_field('ipversion')['eno'],
                                       self.field_def_manager.get_field('ipversion')['ftype']))
        agent_session.add(IpapFieldKey(self.field_def_manager.get_field('srcipv4')['eno'],
                                       self.field_def_manager.get_field('srcipv4')['ftype']))
        agent_session.add(IpapFieldKey(self.field_def_manager.get_field('srcipv6')['eno'],
                                       self.field_def_manager.get_field('srcipv6')['ftype']))
        agent_session.add(IpapFieldKey(self.field_def_manager.get_field('srcauctionport')['eno'],
                                       self.field_def_manager.get_field('srcauctionport')['ftype']))
        self.field_sets[AgentFieldSet.SESSION_FIELD_SET_NAME] = agent_session

        # Fill option auctions fields
        agent_search_fields = set()
        agent_search_fields.add(IpapFieldKey(self.field_def_manager.get_field('start')['eno'],
                                             self.field_def_manager.get_field('start')['ftype']))
        agent_search_fields.add(IpapFieldKey(self.field_def_manager.get_field('stop')['eno'],
                                             self.field_def_manager.get_field('stop')['ftype']))
        agent_search_fields.add(IpapFieldKey(self.field_def_manager.get_field('resourceid')['eno'],
                                             self.field_def_manager.get_field('resourceid')['ftype']))
        self.field_sets[AgentFieldSet.REQUEST_FIELD_SET_NAME] = agent_search_fields
Ejemplo n.º 5
0
class IpapFieldKeyTest(unittest.TestCase):
    """
    IpapFieldKeyTest
    """
    def setUp(self):
        self.ipap_field_key1 = IpapFieldKey(1, 30)

    def test_get_eno(self):
        val = self.ipap_field_key1.get_eno()
        self.assertEqual(val, 1)

    def test_get_ftype(self):
        val = self.ipap_field_key1.get_ftype()
        self.assertEqual(val, 30)

    def test_get_key(self):
        val = self.ipap_field_key1.get_key()
        self.assertEqual(val, "1-30")
Ejemplo n.º 6
0
    def get_template_type_key_field(self, temp_type: TemplateType) -> list:
        size = self._get_template_type_key_size(temp_type)
        if size < 0:
            raise ValueError('The template type given is not valid')

        list_return = []

        for i in range(0, size):
            obj = lib.ipap_template_get_template_type_key(self.obj, c_int(temp_type.value), c_int(i))
            if obj:  # not null
                field_key = IpapFieldKey(obj=obj)
                list_return.append(field_key)
            else:
                raise ValueError('Field key not found')
        return list_return
Ejemplo n.º 7
0
 def setUp(self):
     self.ipap_field_key1 = IpapFieldKey(1, 30)