Example #1
0
 def create(cls, context, values):
     values = cls._transpose_metadata(values)
     obj = db_api.node_create(context, values)
     # NOTE: We need an extra DB call to make sure the profile is loaded
     #       and bound to the node created.
     obj = db_api.node_get(context, obj.id)
     return cls._from_db_object(context, cls(), obj)
Example #2
0
 def _prepare_nodes(self, ctx, count=3, profile_id=None, **kwargs):
     '''Prepare nodes for add or delete.'''
     nodes = []
     for i in range(count):
         values = {
             'name': 'test_node_name',
             'physical_id': 'fake-phy-id-%s' % (i + 1),
             'cluster_id': None,
             'profile_id': profile_id or self.profile['id'],
             'project': ctx.project,
             'index': i + 1,
             'role': None,
             'created_time': None,
             'updated_time': None,
             'deleted_time': None,
             'status': 'ACTIVE',
             'status_reason': 'create complete',
             'metadata': {
                 'foo': '123'
             },
             'data': {
                 'key1': 'value1'
             },
         }
         values.update(kwargs)
         db_node = db_api.node_create(ctx, values)
         nodes.append(six.text_type(db_node.id))
     return nodes
Example #3
0
    def store(self, context):
        '''Store the node record into database table.

        The invocation of DB API could be a node_create or a node_update,
        depending on whether node has an ID assigned.
        '''

        values = {
            'name': self.name,
            'physical_id': self.physical_id,
            'cluster_id': self.cluster_id,
            'profile_id': self.profile_id,
            'user': self.user,
            'project': self.project,
            'domain': self.domain,
            'index': self.index,
            'role': self.role,
            'init_time': self.init_time,
            'created_time': self.created_time,
            'updated_time': self.updated_time,
            'deleted_time': self.deleted_time,
            'status': self.status,
            'status_reason': self.status_reason,
            'meta_data': self.metadata,
            'data': self.data,
        }

        if self.id:
            db_api.node_update(context, self.id, values)
            event_mod.info(context, self, 'update')
        else:
            init_time = timeutils.utcnow()
            self.init_time = init_time
            values['init_time'] = init_time
            node = db_api.node_create(context, values)
            event_mod.info(context, self, 'create')
            self.id = node.id

        self._load_runtime_data(context)
        return self.id
Example #4
0
    def store(self, context):
        '''Store the node record into database table.

        The invocation of DB API could be a node_create or a node_update,
        depending on whether node has an ID assigned.
        '''

        values = {
            'name': self.name,
            'physical_id': self.physical_id,
            'cluster_id': self.cluster_id,
            'profile_id': self.profile_id,
            'user': self.user,
            'project': self.project,
            'domain': self.domain,
            'index': self.index,
            'role': self.role,
            'init_time': self.init_time,
            'created_time': self.created_time,
            'updated_time': self.updated_time,
            'deleted_time': self.deleted_time,
            'status': self.status,
            'status_reason': self.status_reason,
            'meta_data': self.metadata,
            'data': self.data,
        }

        if self.id:
            db_api.node_update(context, self.id, values)
            event_mod.info(context, self, 'update')
        else:
            init_time = timeutils.utcnow()
            self.init_time = init_time
            values['init_time'] = init_time
            node = db_api.node_create(context, values)
            event_mod.info(context, self, 'create')
            self.id = node.id

        self._load_runtime_data(context)
        return self.id
Example #5
0
    def store(self, context):
        '''Store the node record into database table.

        The invocation of DB API could be a node_create or a node_update,
        depending on whether node has an ID assigned.
        '''

        values = {
            'name': self.name,
            'physical_id': self.physical_id,
            'cluster_id': self.cluster_id,
            'profile_id': self.profile_id,
            'project': self.project,
            'index': self.index,
            'role': self.role,
            'init_time': self.init_time,
            'created_time': self.created_time,
            'updated_time': self.updated_time,
            'deleted_time': self.deleted_time,
            'status': self.status,
            'status_reason': self.status_reason,
            'data': self.data,
            'tags': self.tags,
        }

        if self.id:
            db_api.node_update(context, self.id, values)
            # TODO(Qiming): create event/log
        else:
            init_time = datetime.datetime.utcnow()
            self.init_time = init_time
            values['init_time'] = init_time
            node = db_api.node_create(context, values)
            # TODO(Qiming): create event/log
            self.id = node.id

        self._load_runtime_data(context)
        return self.id
Example #6
0
 def _prepare_nodes(self, ctx, count=3, profile_id=None, **kwargs):
     '''Prepare nodes for add or delete.'''
     nodes = []
     for i in range(count):
         values = {
             'name': 'test_node_name',
             'physical_id': 'fake-phy-id-%s' % (i + 1),
             'cluster_id': None,
             'profile_id': profile_id or self.profile['id'],
             'project': ctx.project,
             'index': i + 1,
             'role': None,
             'created_time': None,
             'updated_time': None,
             'deleted_time': None,
             'status': 'ACTIVE',
             'status_reason': 'create complete',
             'metadata': {'foo': '123'},
             'data': {'key1': 'value1'},
         }
         values.update(kwargs)
         db_node = db_api.node_create(ctx, values)
         nodes.append(six.text_type(db_node.id))
     return nodes
Example #7
0
 def create(cls, context, values):
     obj = db_api.node_create(context, values)
     return cls._from_db_object(context, cls(context), obj)
Example #8
0
 def create(cls, context, values):
     values = cls._transpose_metadata(values)
     obj = db_api.node_create(context, values)
     return cls._from_db_object(context, cls(context), obj)
Example #9
0
 def create(cls, context, values):
     obj = db_api.node_create(context, values)
     return cls._from_db_object(context, cls(context), obj)