class ClusterPayload(NotificationObject): VERSION = '1.0' fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'min_size': fields.IntegerField(), 'max_size': fields.IntegerField(), 'desired_capacity': fields.IntegerField(), 'timeout': fields.IntegerField(), 'status': fields.StringField(), 'status_reason': fields.StringField(), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), } @classmethod def from_cluster(cls, cluster): values = {} for field in cls.fields: values[field] = getattr(cluster, field) obj = cls(**values) obj.obj_reset_changes(recursive=False) return obj
class ActionPayload(NotificationObject): VERSION = '1.0' fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'created_at': fields.DateTimeField(nullable=True), 'target': fields.UUIDField(), 'action': fields.StringField(), 'start_time': fields.FloatField(), 'end_time': fields.FloatField(nullable=True), 'timeout': fields.IntegerField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(), 'inputs': fields.JsonField(nullable=True), 'outputs': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), } @classmethod def from_action(cls, action): values = {} for field in cls.fields: values[field] = getattr(action, field) obj = cls(**values) obj.obj_reset_changes(recursive=False) return obj
class NodePayload(NotificationObject): VERSION = '1.0' fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), 'cluster_id': fields.StringField(), 'physical_id': fields.UUIDField(nullable=True), 'index': fields.IntegerField(), 'role': fields.StringField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), } @classmethod def from_node(cls, node): values = {} for field in cls.fields: values[field] = getattr(node, field) obj = cls(**values) obj.obj_reset_changes(recursive=False) return obj
class HealthRegistry(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin health registry object.""" fields = { 'id': fields.UUIDField(), 'cluster_id': fields.UUIDField(), 'check_type': fields.StringField(), 'interval': fields.IntegerField(nullable=True), 'params': fields.JsonField(nullable=True), 'engine_id': fields.UUIDField(), } @classmethod def create(cls, context, cluster_id, check_type, interval, params, engine_id): obj = db_api.registry_create(context, cluster_id, check_type, interval, params, engine_id) return cls._from_db_object(context, cls(context), obj) @classmethod def claim(cls, context, engine_id): objs = db_api.registry_claim(context, engine_id) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def delete(cls, context, cluster_id): db_api.registry_delete(context, cluster_id)
class HealthRegistry(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin health registry object.""" fields = { 'id': fields.UUIDField(), 'cluster_id': fields.UUIDField(), 'check_type': fields.StringField(), 'interval': fields.IntegerField(nullable=True), 'params': fields.JsonField(nullable=True), 'engine_id': fields.UUIDField(), 'enabled': fields.BooleanField(), } @classmethod def create(cls, context, cluster_id, check_type, interval, params, engine_id, enabled=True): obj = db_api.registry_create(context, cluster_id, check_type, interval, params, engine_id, enabled=enabled) return cls._from_db_object(context, cls(), obj) @classmethod def update(cls, context, cluster_id, values): db_api.registry_update(context, cluster_id, values) @classmethod def claim(cls, context, engine_id): objs = db_api.registry_claim(context, engine_id) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def delete(cls, context, cluster_id): db_api.registry_delete(context, cluster_id) @classmethod def get(cls, context, cluster_id): obj = db_api.registry_get(context, cluster_id) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_engine(cls, context, engine_id, cluster_id): params = { "cluster_id": cluster_id, "engine_id": engine_id, } obj = db_api.registry_get_by_param(context, params) return cls._from_db_object(context, cls(), obj) @classmethod def disable_registry(cls, context, cluster_id): cls.update(context, cluster_id, {'enabled': False}) @classmethod def enable_registry(cls, context, cluster_id): cls.update(context, cluster_id, {"enabled": True})
class EventListRequest(base.SenlinObject): action_name_list = list(consts.CLUSTER_ACTION_NAMES) action_name_list.extend(list(consts.NODE_ACTION_NAMES)) fields = { 'oid': fields.ListOfStringsField(nullable=True), 'oname': fields.ListOfStringsField(nullable=True), 'otype': fields.ListOfStringsField(nullable=True), 'action': fields.ListOfEnumField(valid_values=action_name_list, nullable=True), 'cluster_id': fields.ListOfStringsField(nullable=True), 'level': fields.ListOfEnumField(valid_values=list(consts.EVENT_LEVELS.keys()), nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField(valid_keys=list(consts.EVENT_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True) }
class Receiver(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin receiver object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'type': fields.StringField(), 'cluster_id': fields.UUIDField(), 'actor': fields.JsonField(nullable=True), 'action': fields.StringField(), 'params': fields.JsonField(nullable=True), 'channel': fields.JsonField(nullable=True), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.receiver_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, receiver_id, **kwargs): obj = db_api.receiver_get(context, receiver_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.receiver_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.receiver_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): return db_api.receiver_get_all(context, **kwargs) @classmethod def delete(cls, context, receiver_id): db_api.receiver_delete(context, receiver_id)
class Event(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin event object.""" fields = { 'id': fields.UUIDField(), 'timestamp': fields.DateTimeField(), 'oid': fields.UUIDField(), 'oname': fields.StringField(), 'otype': fields.StringField(), 'cluster_id': fields.UUIDField(nullable=True), 'level': fields.StringField(), 'user': fields.StringField(), 'project': fields.StringField(), 'action': fields.StringField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(), 'metadata': fields.JsonField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.event_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, event_id, **kwargs): return db_api.event_get(context, event_id, **kwargs) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): return db_api.event_get_by_short_id(context, short_id, **kwargs) @classmethod def get_all(cls, context, **kwargs): return db_api.event_get_all(context, **kwargs) @classmethod def count_by_cluster(cls, context, cluster_id, **kwargs): return db_api.event_count_by_cluster(context, cluster_id, **kwargs) @classmethod def get_all_by_cluster(cls, context, cluster_id, **kwargs): objs = db_api.event_get_all_by_cluster(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs]
class NodeLock(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin node lock object.""" fields = { 'node_id': fields.UUIDField(), 'action_id': fields.UUIDField(), } @classmethod def acquire(cls, node_id, action_id): return db_api.node_lock_acquire(node_id, action_id) @classmethod def release(cls, node_id, action_id): return db_api.node_lock_release(node_id, action_id) @classmethod def steal(cls, node_id, action_id): return db_api.node_lock_steal(node_id, action_id)
class Dependency(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin action dependency object.""" fields = { 'id': fields.UUIDField(), 'depended': fields.UUIDField(), 'dependent': fields.UUIDField(), } @classmethod def create(cls, context, depended, dependent): return db_api.dependency_add(context, depended, dependent) @classmethod def get_depended(cls, context, action_id): return db_api.dependency_get_depended(context, action_id) @classmethod def get_dependents(cls, context, action_id): return db_api.dependency_get_dependents(context, action_id)
class ProfileListRequest(base.SenlinObject): fields = { 'name': fields.ListOfStringsField(nullable=True), 'type': fields.ListOfStringsField(nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField( valid_keys=list(consts.PROFILE_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True), }
class ClusterListRequest(base.SenlinObject): fields = { 'name': fields.ListOfStringsField(nullable=True), 'status': fields.ListOfEnumField( valid_values=list(consts.CLUSTER_STATUSES), nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField( valid_keys=list(consts.CLUSTER_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True), }
class Policy(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin policy object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'type': fields.StringField(), 'spec': fields.JsonField(), 'cooldown': fields.IntegerField(nullable=True), 'level': fields.IntegerField(nullable=True), 'data': fields.JsonField(nullable=True), 'created_at': fields.DateTimeField(), 'updated_at': fields.DateTimeField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.policy_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, policy_id, **kwargs): obj = db_api.policy_get(context, policy_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.policy_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.policy_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.policy_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def update(cls, context, obj_id, values): obj = db_api.policy_update(context, obj_id, values) return cls._from_db_object(context, cls(), obj) @classmethod def delete(cls, context, obj_id): db_api.policy_delete(context, obj_id)
class Service(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin service object.""" fields = { 'id': fields.UUIDField(), 'host': fields.StringField(), 'binary': fields.StringField(), 'topic': fields.StringField(), 'disabled': fields.BooleanField(), 'disabled_reason': fields.StringField(nullable=True), 'created_at': fields.DateTimeField(), 'updated_at': fields.DateTimeField(), } @classmethod def create(cls, context, service_id, host=None, binary=None, topic=None): obj = db_api.service_create(service_id, host=host, binary=binary, topic=topic) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, service_id): obj = db_api.service_get(service_id) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context): objs = db_api.service_get_all() return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def update(cls, context, obj_id, values=None): obj = db_api.service_update(obj_id, values=values) return cls._from_db_object(context, cls(), obj) @classmethod def delete(cls, obj_id): db_api.service_delete(obj_id) @classmethod def gc_by_engine(cls, engine_id): db_api.gc_by_engine(engine_id)
class ClusterLock(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin cluster lock object.""" fields = { 'cluster_id': fields.UUIDField(), 'action_ids': fields.ListOfStringsField(), 'semaphore': fields.IntegerField(), } @classmethod def acquire(cls, cluster_id, action_id, scope): return db_api.cluster_lock_acquire(cluster_id, action_id, scope) @classmethod def release(cls, cluster_id, action_id, scope): return db_api.cluster_lock_release(cluster_id, action_id, scope) @classmethod def steal(cls, cluster_id, action_id): return db_api.cluster_lock_steal(cluster_id, action_id)
class ReceiverListRequest(base.SenlinObject): # VERSION 1.0: Initial version # VERSION 1.1: Add field 'user' VERSION = '1.1' VERSION_MAP = { '1.4': '1.1', } fields = { 'name': fields.ListOfStringsField(nullable=True), 'type': fields.ListOfEnumField(valid_values=list(consts.RECEIVER_TYPES), nullable=True), 'action': fields.ListOfEnumField(valid_values=list(consts.CLUSTER_ACTION_NAMES), nullable=True), 'cluster_id': fields.ListOfStringsField(nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField(valid_keys=list(consts.RECEIVER_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True), 'user': fields.ListOfStringsField(nullable=True), } def obj_make_compatible(self, primitive, target_version): super(ReceiverListRequest, self).obj_make_compatible(primitive, target_version) target_version = versionutils.convert_version_to_tuple(target_version) if target_version < (1, 1): if 'user' in primitive['senlin_object.data']: del primitive['senlin_object.data']['user']
class ReceiverListRequest(base.SenlinObject): fields = { 'name': fields.ListOfStringsField(nullable=True), 'type': fields.ListOfEnumField(valid_values=list(consts.RECEIVER_TYPES), nullable=True), 'action': fields.ListOfEnumField(valid_values=list(consts.CLUSTER_ACTION_NAMES), nullable=True), 'cluster_id': fields.ListOfStringsField(nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField(valid_keys=list(consts.RECEIVER_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True) }
class ActionListRequest(base.SenlinObject): action_name_list = list(consts.CLUSTER_ACTION_NAMES) action_name_list.extend(list(consts.NODE_ACTION_NAMES)) VERSION = '1.1' VERSION_MAP = {'1.14': '1.1'} fields = { 'name': fields.ListOfStringsField(nullable=True), 'cluster_id': fields.ListOfStringsField(nullable=True), 'action': fields.ListOfEnumField(valid_values=action_name_list, nullable=True), 'target': fields.ListOfStringsField(nullable=True), 'status': fields.ListOfEnumField(valid_values=list(consts.ACTION_STATUSES), nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField(valid_keys=list(consts.ACTION_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True) } def obj_make_compatible(self, primitive, target_version): super(ActionListRequest, self).obj_make_compatible(primitive, target_version) target_version = versionutils.convert_version_to_tuple(target_version) if target_version < (1, 14): if 'cluster_id' in primitive['senlin_object.data']: del primitive['senlin_object.data']['cluster_id']
class ActionListRequest(base.SenlinObject): action_name_list = list(consts.CLUSTER_ACTION_NAMES) action_name_list.extend(list(consts.NODE_ACTION_NAMES)) fields = { 'name': fields.ListOfStringsField(nullable=True), 'action': fields.ListOfEnumField(valid_values=action_name_list, nullable=True), 'target': fields.ListOfStringsField(nullable=True), 'status': fields.ListOfEnumField(valid_values=list(consts.ACTION_STATUSES), nullable=True), 'limit': fields.NonNegativeIntegerField(nullable=True), 'marker': fields.UUIDField(nullable=True), 'sort': fields.SortField(valid_keys=list(consts.ACTION_SORT_KEYS), nullable=True), 'project_safe': fields.FlexibleBooleanField(default=True) }
class Cluster(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin cluster object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), 'parent': fields.UUIDField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'min_size': fields.IntegerField(nullable=True), 'max_size': fields.IntegerField(nullable=True), 'desired_capacity': fields.IntegerField(nullable=True), 'next_index': fields.IntegerField(nullable=True), 'timeout': fields.IntegerField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), } @classmethod def create(cls, context, values): values = cls._transpose_metadata(values) obj = db_api.cluster_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, project_safe=True): cluster = None if uuidutils.is_uuid_like(identity): cluster = cls.get(context, identity, project_safe=project_safe) if not cluster: cluster = cls.get_by_name(context, identity, project_safe=project_safe) else: cluster = cls.get_by_name(context, identity, project_safe=project_safe) # maybe it is a short form of UUID if not cluster: cluster = cls.get_by_short_id(context, identity, project_safe=project_safe) if not cluster: raise exc.ResourceNotFound(type='cluster', id=identity) return cluster @classmethod def get(cls, context, cluster_id, **kwargs): obj = db_api.cluster_get(context, cluster_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.cluster_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.cluster_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.cluster_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_next_index(cls, context, cluster_id): return db_api.cluster_next_index(context, cluster_id) @classmethod def count_all(cls, context, **kwargs): return db_api.cluster_count_all(context, **kwargs) @classmethod def update(cls, context, obj_id, values): values = cls._transpose_metadata(values) return db_api.cluster_update(context, obj_id, values) @classmethod def delete(cls, context, obj_id): db_api.cluster_delete(context, obj_id)
class Receiver(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin receiver object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'type': fields.StringField(), 'cluster_id': fields.UUIDField(nullable=True), 'actor': fields.JsonField(nullable=True), 'action': fields.StringField(nullable=True), 'params': fields.JsonField(nullable=True), 'channel': fields.JsonField(nullable=True), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.receiver_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, **kwargs): """Find a receiver with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of a receiver. :param project_safe: A boolean indicating whether receiver from other projects other than the requesting one can be returned. :return: A DB object of receiver or an exception `ResourceNotFound` if no matching receiver is found. """ if uuidutils.is_uuid_like(identity): receiver = cls.get(context, identity, **kwargs) if not receiver: receiver = cls.get_by_name(context, identity, **kwargs) else: receiver = cls.get_by_name(context, identity, **kwargs) if not receiver: receiver = cls.get_by_short_id(context, identity, **kwargs) if not receiver: raise exception.ResourceNotFound(type='receiver', id=identity) return receiver @classmethod def get(cls, context, receiver_id, **kwargs): obj = db_api.receiver_get(context, receiver_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.receiver_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.receiver_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.receiver_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def delete(cls, context, receiver_id): db_api.receiver_delete(context, receiver_id) def to_dict(self): receiver_dict = { 'id': self.id, 'name': self.name, 'type': self.type, 'user': self.user, 'project': self.project, 'domain': self.domain, 'created_at': utils.isotime(self.created_at), 'updated_at': utils.isotime(self.updated_at), 'cluster_id': self.cluster_id, 'actor': self.actor, 'action': self.action, 'params': self.params, 'channel': self.channel, } return receiver_dict
class Cluster(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin cluster object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), 'parent': fields.UUIDField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'min_size': fields.IntegerField(nullable=True), 'max_size': fields.IntegerField(nullable=True), 'desired_capacity': fields.IntegerField(nullable=True), 'next_index': fields.IntegerField(nullable=True), 'timeout': fields.IntegerField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), 'config': fields.JsonField(nullable=True), } @classmethod def create(cls, context, values): values = cls._transpose_metadata(values) values['init_at'] = timeutils.utcnow(True) obj = db_api.cluster_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, project_safe=True): cluster = None if uuidutils.is_uuid_like(identity): cluster = cls.get(context, identity, project_safe=project_safe) if not cluster: cluster = cls.get_by_name(context, identity, project_safe=project_safe) else: cluster = cls.get_by_name(context, identity, project_safe=project_safe) # maybe it is a short form of UUID if not cluster: cluster = cls.get_by_short_id(context, identity, project_safe=project_safe) if not cluster: raise exc.ResourceNotFound(type='cluster', id=identity) return cluster @classmethod def get(cls, context, cluster_id, **kwargs): obj = db_api.cluster_get(context, cluster_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.cluster_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.cluster_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.cluster_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_next_index(cls, context, cluster_id): return db_api.cluster_next_index(context, cluster_id) @classmethod def count_all(cls, context, **kwargs): return db_api.cluster_count_all(context, **kwargs) @classmethod def update(cls, context, obj_id, values): values = cls._transpose_metadata(values) values['updated_at'] = timeutils.utcnow(True) return db_api.cluster_update(context, obj_id, values) @classmethod def delete(cls, context, obj_id): db_api.cluster_delete(context, obj_id) def to_dict(self): context = senlin_context.get_admin_context() profile = db_api.profile_get(context, self.profile_id, project_safe=False) return { 'id': self.id, 'name': self.name, 'profile_id': self.profile_id, 'user': self.user, 'project': self.project, 'domain': self.domain, 'init_at': utils.isotime(self.init_at), 'created_at': utils.isotime(self.created_at), 'updated_at': utils.isotime(self.updated_at), 'min_size': self.min_size, 'max_size': self.max_size, 'desired_capacity': self.desired_capacity, 'timeout': self.timeout, 'status': self.status, 'status_reason': self.status_reason, 'metadata': self.metadata or {}, 'data': self.data or {}, 'dependents': self.dependents or {}, 'config': self.config or {}, 'profile_name': profile.name, 'nodes': db_api.node_ids_by_cluster(context, self.id), 'policies': db_api.cluster_policy_ids_by_cluster(context, self.id) }
class Profile(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin profile object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'type': fields.StringField(), 'context': fields.JsonField(), 'spec': fields.JsonField(), 'created_at': fields.DateTimeField(), 'updated_at': fields.DateTimeField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'permission': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), } @classmethod def create(cls, context, values): values = cls._transpose_metadata(values) obj = db_api.profile_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, **kwargs): """Find a profile with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of a profile. :param project_safe: A boolean indicating whether profile from projects other than the requesting one can be returned. :return: A DB object of profile or an exception `ResourceNotFound` if no matching object is found. """ if uuidutils.is_uuid_like(identity): profile = cls.get(context, identity, **kwargs) if not profile: profile = cls.get_by_name(context, identity, **kwargs) else: profile = cls.get_by_name(context, identity, **kwargs) if not profile: profile = cls.get_by_short_id(context, identity, **kwargs) if not profile: raise exception.ResourceNotFound(type='profile', id=identity) return profile @classmethod def get(cls, context, profile_id, **kwargs): obj = db_api.profile_get(context, profile_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.profile_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.profile_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.profile_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def update(cls, context, obj_id, values): values = cls._transpose_metadata(values) obj = db_api.profile_update(context, obj_id, values) return cls._from_db_object(context, cls(), obj) @classmethod def delete(cls, context, obj_id): db_api.profile_delete(context, obj_id) def to_dict(self): profile_dict = { 'id': self.id, 'name': self.name, 'type': self.type, 'user': self.user, 'project': self.project, 'domain': self.domain, 'spec': self.spec, 'metadata': self.metadata, 'created_at': utils.isotime(self.created_at), 'updated_at': utils.isotime(self.updated_at) } return profile_dict
class Action(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin action object.""" fields = { 'id': fields.UUIDField(), 'created_at': fields.DateTimeField(), 'updated_at': fields.DateTimeField(nullable=True), 'name': fields.StringField(), 'context': fields.JsonField(), 'target': fields.UUIDField(), 'action': fields.StringField(), 'cause': fields.StringField(), 'owner': fields.UUIDField(nullable=True), 'interval': fields.IntegerField(nullable=True), 'start_time': fields.FloatField(nullable=True), 'end_time': fields.FloatField(nullable=True), 'timeout': fields.IntegerField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'control': fields.StringField(nullable=True), 'inputs': fields.JsonField(nullable=True), 'outputs': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dep_on': fields.CustomListField(attr_name='depended', nullable=True), 'dep_by': fields.CustomListField(attr_name='dependent', nullable=True), } @classmethod def create(cls, context, values): obj = db_api.action_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, **kwargs): """Find an action with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of an action. :param dict kwargs: Other query parameters. :return: A DB object of action or an exception `ResourceNotFound` if no matching action is found. """ if uuidutils.is_uuid_like(identity): action = cls.get(context, identity, **kwargs) if not action: action = cls.get_by_name(context, identity, **kwargs) else: action = cls.get_by_name(context, identity, **kwargs) if not action: action = cls.get_by_short_id(context, identity, **kwargs) if not action: raise exception.ResourceNotFound(type='action', id=identity) return action @classmethod def get(cls, context, action_id, **kwargs): obj = db_api.action_get(context, action_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.action_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.action_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def action_list_active_scaling(cls, context, cluster_id, **kwargs): objs = db_api.action_list_active_scaling(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all(cls, context, **kwargs): objs = db_api.action_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all_by_owner(cls, context, owner): objs = db_api.action_get_all_by_owner(context, owner) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all_active_by_target(cls, context, target): objs = db_api.action_get_all_active_by_target(context, target) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def check_status(cls, context, action_id, timestamp): return db_api.action_check_status(context, action_id, timestamp) @classmethod def mark_succeeded(cls, context, action_id, timestamp): return db_api.action_mark_succeeded(context, action_id, timestamp) @classmethod def mark_ready(cls, context, action_id, timestamp): return db_api.action_mark_ready(context, action_id, timestamp) @classmethod def mark_failed(cls, context, action_id, timestamp, reason=None): return db_api.action_mark_failed(context, action_id, timestamp, reason) @classmethod def mark_cancelled(cls, context, action_id, timestamp): return db_api.action_mark_cancelled(context, action_id, timestamp) @classmethod def acquire(cls, context, action_id, owner, timestamp): return db_api.action_acquire(context, action_id, owner, timestamp) @classmethod def acquire_random_ready(cls, context, owner, timestamp): return db_api.action_acquire_random_ready(context, owner, timestamp) @classmethod def acquire_first_ready(cls, context, owner, timestamp): return db_api.action_acquire_first_ready(context, owner, timestamp) @classmethod def abandon(cls, context, action_id, values=None): return db_api.action_abandon(context, action_id, values) @classmethod def signal(cls, context, action_id, value): return db_api.action_signal(context, action_id, value) @classmethod def signal_query(cls, context, action_id): return db_api.action_signal_query(context, action_id) @classmethod def lock_check(cls, context, action_id, owner=None): return db_api.action_lock_check(context, action_id, owner) @classmethod def update(cls, context, action_id, values): return db_api.action_update(context, action_id, values) @classmethod def delete(cls, context, action_id): db_api.action_delete(context, action_id) @classmethod def delete_by_target(cls, context, target, action=None, action_excluded=None, status=None): """Delete an action with the target and other given params. :param target: The ID of the target cluster/node :param action: A list of actions to be included. :param action_excluded: A list of actions to be excluded. :param status: A list of statuses to be delete filtered. :return: None. """ return db_api.action_delete_by_target(context, target, action=action, action_excluded=action_excluded, status=status) def to_dict(self): action_dict = { 'id': self.id, 'name': self.name, 'action': self.action, 'target': self.target, 'cause': self.cause, 'owner': self.owner, 'interval': self.interval, 'start_time': self.start_time, 'end_time': self.end_time, 'timeout': self.timeout, 'status': self.status, 'status_reason': self.status_reason, 'inputs': self.inputs, 'outputs': self.outputs, 'depends_on': self.dep_on, 'depended_by': self.dep_by, 'created_at': utils.isotime(self.created_at), 'updated_at': utils.isotime(self.updated_at), 'data': self.data, 'user': self.user, 'project': self.project, } return action_dict
class Node(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin node object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), # This field is treated as string because we may store '' into it 'cluster_id': fields.StringField(), 'physical_id': fields.UUIDField(nullable=True), 'index': fields.IntegerField(), 'role': fields.StringField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.node_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, node_id, **kwargs): obj = db_api.node_get(context, node_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.node_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.node_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.node_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all_by_cluster(cls, context, cluster_id, **kwargs): objs = db_api.node_get_all_by_cluster(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def count_by_cluster(cls, context, cluster_id, **kwargs): return db_api.node_count_by_cluster(context, cluster_id, **kwargs) @classmethod def update(cls, context, obj_id, values): db_api.node_update(context, obj_id, values) @classmethod def migrate(cls, context, obj_id, to_cluster, timestamp, role=None): return db_api.node_migrate(context, obj_id, to_cluster, timestamp, role=role) @classmethod def delete(cls, context, obj_id): db_api.node_delete(context, obj_id)
class Node(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin node object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), # This field is treated as string because we may store '' into it 'cluster_id': fields.StringField(), 'physical_id': fields.UUIDField(nullable=True), 'index': fields.IntegerField(), 'role': fields.StringField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), } @classmethod 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) @classmethod def find(cls, context, identity, project_safe=True): """Find a node with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of a node. :param project_safe: A boolean indicating whether only nodes from the same project as the requesting one are qualified to be returned. :return: A DB object of Node. :raises: An exception of ``ResourceNotFound`` if no matching node is or an exception of ``MultipleChoices`` more than one node found matching the criteria. """ node = None if uuidutils.is_uuid_like(identity): node = cls.get(context, identity, project_safe=project_safe) if not node: node = cls.get_by_name(context, identity, project_safe=project_safe) else: node = cls.get_by_name(context, identity, project_safe=project_safe) if not node: node = cls.get_by_short_id(context, identity, project_safe=project_safe) if node is None: raise exception.ResourceNotFound(type='node', id=identity) return node @classmethod def get(cls, context, node_id, **kwargs): obj = db_api.node_get(context, node_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.node_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.node_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.node_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all_by_cluster(cls, context, cluster_id, **kwargs): objs = db_api.node_get_all_by_cluster(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def count_by_cluster(cls, context, cluster_id, **kwargs): return db_api.node_count_by_cluster(context, cluster_id, **kwargs) @classmethod def update(cls, context, obj_id, values): values = cls._transpose_metadata(values) db_api.node_update(context, obj_id, values) @classmethod def migrate(cls, context, obj_id, to_cluster, timestamp, role=None): return db_api.node_migrate(context, obj_id, to_cluster, timestamp, role=role) @classmethod def delete(cls, context, obj_id): db_api.node_delete(context, obj_id)
class ClusterPolicy(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin cluster-policy binding object.""" fields = { 'id': fields.UUIDField(), 'cluster_id': fields.UUIDField(), 'policy_id': fields.UUIDField(), 'cluster': fields.ObjectField('Cluster', nullable=True), 'policy': fields.ObjectField('Policy', nullable=True), 'enabled': fields.BooleanField(), 'priority': fields.IntegerField(), 'data': fields.JsonField(nullable=True), 'last_op': fields.DateTimeField(nullable=True), } @staticmethod def _from_db_object(context, binding, db_obj): if db_obj is None: return None for field in binding.fields: if field == 'cluster': c = cluster_obj.Cluster.get(context, db_obj['cluster_id']) binding['cluster'] = c elif field == 'policy': p = policy_obj.Policy.get(context, db_obj['policy_id']) binding['policy'] = p else: binding[field] = db_obj[field] binding._context = context binding.obj_reset_changes() return binding @classmethod def create(cls, context, cluster_id, policy_id, values): obj = db_api.cluster_policy_attach(context, cluster_id, policy_id, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, cluster_id, policy_id): obj = db_api.cluster_policy_get(context, cluster_id, policy_id) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_type(cls, context, cluster_id, policy_type, filters=None): objs = db_api.cluster_policy_get_by_type(context, cluster_id, policy_type, filters=filters) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all(cls, context, cluster_id, **kwargs): objs = db_api.cluster_policy_get_all(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def update(cls, context, cluster_id, policy_id, values): db_api.cluster_policy_update(context, cluster_id, policy_id, values) @classmethod def delete(cls, context, cluster_id, policy_id): db_api.cluster_policy_detach(context, cluster_id, policy_id) def cooldown_inprogress(self, cooldown): last_op = self.last_op if last_op and not timeutils.is_older_than(last_op, cooldown): return True return False def to_dict(self): binding_dict = { 'id': self.id, 'cluster_id': self.cluster.id, 'policy_id': self.policy.id, 'enabled': self.enabled, 'data': self.data, 'last_op': self.last_op, 'priority': self.priority, # below are derived data for user's convenience 'cluster_name': self.cluster.name, 'policy_name': self.policy.name, 'policy_type': self.policy.type, } return binding_dict
class Event(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin event object.""" fields = { 'id': fields.UUIDField(), 'timestamp': fields.DateTimeField(), 'oid': fields.UUIDField(), 'oname': fields.StringField(), 'otype': fields.StringField(), 'cluster_id': fields.StringField(nullable=True), 'level': fields.StringField(), 'user': fields.StringField(), 'project': fields.StringField(), 'action': fields.StringField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(), 'metadata': fields.JsonField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.event_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def find(cls, context, identity, **kwargs): """Find an event with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of the event. :param dict kwargs: Other keyword query parameters. :return: A dictionary containing the details of the event. """ event = None if uuidutils.is_uuid_like(identity): event = cls.get(context, identity, **kwargs) if not event: event = cls.get_by_short_id(context, identity, **kwargs) if not event: raise exception.ResourceNotFound(type='event', id=identity) return event @classmethod def get(cls, context, event_id, **kwargs): return db_api.event_get(context, event_id, **kwargs) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): return db_api.event_get_by_short_id(context, short_id, **kwargs) @classmethod def get_all(cls, context, **kwargs): return db_api.event_get_all(context, **kwargs) @classmethod def count_by_cluster(cls, context, cluster_id, **kwargs): return db_api.event_count_by_cluster(context, cluster_id, **kwargs) @classmethod def get_all_by_cluster(cls, context, cluster_id, **kwargs): objs = db_api.event_get_all_by_cluster(context, cluster_id, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs]
class Node(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin node object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), # This field is treated as string because we may store '' into it 'cluster_id': fields.StringField(), 'physical_id': fields.StringField(nullable=True), 'index': fields.IntegerField(), 'role': fields.StringField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), 'dependents': fields.JsonField(nullable=True), 'profile_name': fields.StringField(nullable=True), 'profile_created_at': fields.StringField(nullable=True), } @staticmethod def _from_db_object(context, obj, db_obj): if db_obj is None: return None for field in obj.fields: if field == 'metadata': obj['metadata'] = db_obj['meta_data'] elif field == 'profile_name': p = db_obj['profile'] obj['profile_name'] = p.name if p else 'Unknown' elif field == 'profile_created_at': p = db_obj['profile'] obj['profile_created_at'] = p.created_at if p else None else: obj[field] = db_obj[field] obj._context = context obj.obj_reset_changes() return obj @classmethod 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) @classmethod def find(cls, context, identity, project_safe=True): """Find a node with the given identity. :param context: An instance of the request context. :param identity: The UUID, name or short-id of a node. :param project_safe: A boolean indicating whether only nodes from the same project as the requesting one are qualified to be returned. :return: A DB object of Node. :raises: An exception of ``ResourceNotFound`` if no matching node is or an exception of ``MultipleChoices`` more than one node found matching the criteria. """ node = None if uuidutils.is_uuid_like(identity): node = cls.get(context, identity, project_safe=project_safe) if not node: node = cls.get_by_name(context, identity, project_safe=project_safe) else: node = cls.get_by_name(context, identity, project_safe=project_safe) if not node: node = cls.get_by_short_id(context, identity, project_safe=project_safe) if node is None: raise exception.ResourceNotFound(type='node', id=identity) return node @classmethod def get(cls, context, node_id, **kwargs): obj = db_api.node_get(context, node_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.node_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.node_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.node_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_all_by_cluster(cls, context, cluster_id, filters=None, project_safe=True): objs = db_api.node_get_all_by_cluster( context, cluster_id, filters=filters, project_safe=project_safe) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def ids_by_cluster(cls, context, cluster_id, filters=None): """An internal API for retrieving node ids only.""" return db_api.node_ids_by_cluster(context, cluster_id, filters=filters) @classmethod def count_by_cluster(cls, context, cluster_id, **kwargs): return db_api.node_count_by_cluster(context, cluster_id, **kwargs) @classmethod def update(cls, context, obj_id, values): values = cls._transpose_metadata(values) db_api.node_update(context, obj_id, values) @classmethod def migrate(cls, context, obj_id, to_cluster, timestamp, role=None): return db_api.node_migrate(context, obj_id, to_cluster, timestamp, role=role) @classmethod def delete(cls, context, obj_id): return db_api.node_delete(context, obj_id) def to_dict(self): return { 'id': self.id, 'name': self.name, 'cluster_id': self.cluster_id, 'physical_id': self.physical_id, 'profile_id': self.profile_id, 'user': self.user, 'project': self.project, 'domain': self.domain, 'index': self.index, 'role': self.role, 'init_at': utils.isotime(self.init_at), 'created_at': utils.isotime(self.created_at), 'updated_at': utils.isotime(self.updated_at), 'status': self.status, 'status_reason': self.status_reason, 'data': self.data, 'metadata': self.metadata, 'dependents': self.dependents, 'profile_name': self.profile_name, }
class Cluster(base.SenlinObject, base.VersionedObjectDictCompat): """Senlin cluster object.""" fields = { 'id': fields.UUIDField(), 'name': fields.StringField(), 'profile_id': fields.UUIDField(), 'parent': fields.UUIDField(nullable=True), 'init_at': fields.DateTimeField(), 'created_at': fields.DateTimeField(nullable=True), 'updated_at': fields.DateTimeField(nullable=True), 'min_size': fields.IntegerField(nullable=True), 'max_size': fields.IntegerField(nullable=True), 'desired_capacity': fields.IntegerField(nullable=True), 'next_index': fields.IntegerField(nullable=True), 'timeout': fields.IntegerField(nullable=True), 'status': fields.StringField(), 'status_reason': fields.StringField(nullable=True), 'metadata': fields.JsonField(nullable=True), 'data': fields.JsonField(nullable=True), 'user': fields.StringField(), 'project': fields.StringField(), 'domain': fields.StringField(nullable=True), } @classmethod def create(cls, context, values): obj = db_api.cluster_create(context, values) return cls._from_db_object(context, cls(context), obj) @classmethod def get(cls, context, cluster_id, **kwargs): obj = db_api.cluster_get(context, cluster_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_name(cls, context, name, **kwargs): obj = db_api.cluster_get_by_name(context, name, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_by_short_id(cls, context, short_id, **kwargs): obj = db_api.cluster_get_by_short_id(context, short_id, **kwargs) return cls._from_db_object(context, cls(), obj) @classmethod def get_all(cls, context, **kwargs): objs = db_api.cluster_get_all(context, **kwargs) return [cls._from_db_object(context, cls(), obj) for obj in objs] @classmethod def get_next_index(cls, context, cluster_id): return db_api.cluster_next_index(context, cluster_id) @classmethod def count_all(cls, context, **kwargs): return db_api.cluster_count_all(context, **kwargs) @classmethod def update(cls, context, obj_id, values): db_api.cluster_update(context, obj_id, values) @classmethod def delete(cls, context, obj_id): db_api.cluster_delete(context, obj_id)