Beispiel #1
0
 def add_to_ironic_node_store(self, **attributes):
     """
     Create a new Node object and add it to the
     :obj: `ironic_node_store`
     """
     if not attributes.get('chassis_uuid'):
         attributes['chassis_uuid'] = str(uuid4())
     if (attributes.get("flavor_id", None) is None and
             attributes.get("memory_mb")):
         attributes['flavor_id'] = self.memory_to_flavor_map.get(
             attributes['memory_mb'], "onmetal-mimic")
     node = Node(**attributes)
     self.ironic_node_store.append(node)
     return node
Beispiel #2
0
    def _new_session(self, username_key=None, **attributes):
        """
        Create a new session and persist it according to its username and token
        values.

        :param attributes: Keyword parameters containing zero or more of
            ``username``, ``token``, and ``tenant_id``.  Any fields that are
            not specified will be filled out automatically.

        :return: A new session with all fields filled out and an expiration
                 time 1 day in the future (according to the clock associated
                 with this :obj:`MimicCore`).
        :rtype: :obj:`Session`
        """
        for key in ['username', 'token', 'tenant_id']:
            if attributes.get(key, None) is None:
                attributes[key] = key + "_" + text_type(uuid4())
                if key == 'tenant_id':
                    # integer tenant IDs - uuid4 ints are too long
                    attributes[key] = text_type(int(uuid4().int % 1e15))

        if 'expires' not in attributes:
            attributes['expires'] = (
                datetime.utcfromtimestamp(self.clock.seconds())
                + timedelta(days=1)
            )

        session = Session(**attributes)
        if username_key is None:
            username_key = session.username
        self._username_to_token[username_key] = session.token
        self._token_to_session[session.token] = session
        self._userid_to_session[session.user_id] = session
        self._tenant_to_session[session.tenant_id] = session
        return session