class Subnet(model.Model): object_id = model.PrimaryKey() network = model.Dependency(Network, required=True, backref='subnets') tenant = model.Dependency(identity.Tenant) name = model.String(required=True) enable_dhcp = model.Boolean(required=True) dns_nameservers = model.List(model.String(), missing=list) allocation_pools = model.Nested(AllocationPool, many=True) host_routes = model.List(model.String(), missing=list) ip_version = model.Integer(required=True) gateway_ip = model.String(required=True, allow_none=True) cidr = model.String(required=True) def equals(self, other): # pylint: disable=no-member,not-an-iterable if super(Subnet, self).equals(other): return True if len(self.allocation_pools) != len(other.allocation_pools): return False for allocation_pool1 in self.allocation_pools: for allocation_pool2 in other.allocation_pools: if allocation_pool1.equals(allocation_pool2): break else: return False return self.network.equals(other.network) and \ self.tenant.equals(other.tenant) and \ self.cidr == other.cidr and \ self.ip_version == other.ip_version
class Example(model.Model): object_id = model.PrimaryKey() bar = model.String(required=True) baz = model.Nested(ExampleNested) ref = model.Dependency(ExampleReferenced, required=True) refs = model.Dependency(ExampleReferenced, required=True, many=True) ref_none = model.Dependency(ExampleReferenced, missing=None, allow_none=True) refs_none = model.Dependency(ExampleReferenced, missing=None, many=True, allow_none=True) count = 0 @classmethod def generate_data(cls, object_id=None, cloud='test_cloud'): cls.count += 1 if object_id is None: object_id = uuid.uuid5(uuid.NAMESPACE_DNS, 'test%d' % cls.count) ref1 = uuid.uuid5(uuid.NAMESPACE_DNS, 'ref1_%d' % cls.count) ref2 = uuid.uuid5(uuid.NAMESPACE_DNS, 'ref2_%d' % cls.count) ExampleReferenced.create_object(cloud, str(ref1)) ExampleReferenced.create_object(cloud, str(ref2)) return { 'object_id': { 'cloud': cloud, 'id': str(object_id), 'type': Example.get_class_qualname(), }, 'bar': 'some non-random string', 'baz': { 'foo': 'other non-random string', 'ref': { 'cloud': cloud, 'id': str(ref1), 'type': ExampleReferenced.get_class_qualname(), }, 'refs': [{ 'cloud': cloud, 'id': str(ref2), 'type': ExampleReferenced.get_class_qualname(), }], }, 'ref': { 'cloud': cloud, 'id': str(ref1), 'type': ExampleReferenced.get_class_qualname(), }, 'refs': [{ 'cloud': cloud, 'id': str(ref2), 'type': ExampleReferenced.get_class_qualname(), }], }
class ExampleNested(model.Model): foo = model.String(required=True) ref = model.Dependency(ExampleReferenced, required=True) refs = model.Dependency(ExampleReferenced, required=True, many=True) ref_none = model.Dependency(ExampleReferenced, missing=None, allow_none=True) refs_none = model.Dependency(ExampleReferenced, missing=None, many=True, allow_none=True)
class UserRole(model.Model): object_id = model.PrimaryKey() tenant = model.Dependency(Tenant) user = model.Dependency(User) role = model.Dependency(Role) def equals(self, other): # pylint: disable=no-member if super(UserRole, self).equals(other): return True return self.tenant.equals(other.tenant) \ and self.user.equals(other.user) \ and self.role.equals(other.role)
class Image(model.Model): object_id = model.PrimaryKey() name = model.String(allow_none=True) tenant = model.Dependency(identity.Tenant) checksum = model.String(allow_none=True) size = model.Integer() virtual_size = model.Integer(allow_none=True, missing=None) is_public = model.Boolean() protected = model.Boolean() container_format = model.String(missing='qcow2') disk_format = model.String(missing='bare') min_disk = model.Integer(required=True) min_ram = model.Integer(required=True) properties = model.Dict() members = model.Reference(ImageMember, many=True, missing=list) status = model.String() def equals(self, other): # pylint: disable=no-member if super(Image, self).equals(other): return True # TODO: consider comparing properties return self.tenant.equals(other.tenant) and \ self.name == other.name and \ self.checksum == other.checksum and \ self.size == other.size and \ self.is_public == other.is_public and \ self.container_format == other.container_format and \ self.disk_format == other.disk_format
class ImageMember(model.Model): object_id = model.PrimaryKey() image = model.Dependency('cloudferry.model.image.Image') member = model.Dependency('cloudferry.model.identity.Tenant') can_share = model.Boolean(missing=False) @staticmethod def make_uuid(image, tenant): return '{0}:{1}'.format(image.object_id.id, tenant.object_id.id) def equals(self, other): # pylint: disable=no-member if super(ImageMember, self).equals(other): return True return self.image.equals(other.image) and \ self.member.equals(other.member) and \ self.can_share == other.can_share
class Server(model.Model): object_id = model.PrimaryKey() name = model.String(required=True) security_groups = model.Nested(SecurityGroup, many=True, missing=list) status = model.String(required=True) tenant = model.Dependency(identity.Tenant) image = model.Dependency(image_model.Image, allow_none=True) image_membership = model.Dependency(image_model.ImageMember, allow_none=True) user_id = model.String(required=True) # TODO: user reference key_name = model.String(required=True, allow_none=True) flavor = model.Dependency(Flavor) config_drive = model.String(required=True) availability_zone = model.String(required=True, allow_none=True) host = model.String(required=True) hypervisor_hostname = model.String(required=True) instance_name = model.String(required=True) metadata = model.Dict(missing=dict) ephemeral_disks = model.Nested(EphemeralDisk, many=True, missing=list) attached_volumes = model.Dependency(storage.Attachment, many=True, missing=list) compute_node = model.Reference(ComputeNode, required=True, ensure_existence=True) # TODO: ports def equals(self, other): # pylint: disable=no-member if super(Server, self).equals(other): return True # TODO: consider comparing metadata # TODO: consider comparing security_groups if not self.tenant.equals(other.tenant): return False if not self.flavor.equals(other.flavor): return False if not self.image.equals(other.image): return False if self.key_name != other.key_name or self.name != other.name: return False return True
class Volume(model.Model): object_id = model.PrimaryKey() name = model.String(required=True, allow_none=True) description = model.String(required=True, allow_none=True) availability_zone = model.String(required=True) encrypted = model.Boolean(missing=False) host = model.String(required=True) size = model.Integer(required=True) tenant = model.Dependency(identity.Tenant, required=True) metadata = model.Dict(missing=dict) volume_type = model.String(required=True)
class Attachment(model.Model): object_id = model.PrimaryKey() server = model.Reference('cloudferry.model.compute.Server', ensure_existence=False) volume = model.Dependency('cloudferry.model.storage.Volume') device = model.String(required=True) def equals(self, other): # pylint: disable=no-member if super(Attachment, self).equals(other): return True if self.server is None: return False return self.server.equals(other.server) and self.device == other.device
class Quota(model.Model): object_id = model.PrimaryKey() tenant = model.Dependency(identity.Tenant) floatingip = model.Integer(required=True) network = model.Integer(required=True) port = model.Integer(required=True) router = model.Integer(required=True) security_group = model.Integer(required=True) security_group_rule = model.Integer(required=True) subnet = model.Integer(required=True) def equals(self, other): # pylint: disable=no-member if super(Quota, self).equals(other): return True return self.tenant.equals(other.tenant) \ and self.floatingip == other.floatingip \ and self.network == other.network \ and self.port == other.port \ and self.router == other.router \ and self.security_group == other.security_group \ and self.security_group_rule == other.security_group_rule \ and self.subnet == other.subnet
class Network(model.Model): object_id = model.PrimaryKey() tenant = model.Dependency(identity.Tenant) name = model.String(required=True) is_external = model.Boolean(required=True) is_shared = model.Boolean(required=True) admin_state_up = model.Boolean(required=True) status = model.String(required=True) physical_network = model.String(required=True, allow_none=True) network_type = model.String(required=True) segmentation_id = model.Integer(required=True) subnets = model.Reference('cloudferry.model.network.Subnet', many=True, missing=[]) def equals(self, other): # pylint: disable=no-member,not-an-iterable if super(Network, self).equals(other): return True if len(self.subnets) != len(other.subnets): return False for subnet1 in self.subnets: for subnet2 in other.subnets: if subnet1.equals(subnet2): break else: return False return self.tenant.equals(other.tenant) and \ self.name == other.name and \ self.is_external == other.is_external and \ self.is_shared == other.is_shared and \ self.admin_state_up == other.admin_state_up and \ self.status == other.status and \ self.physical_network == other.physical_network and \ self.network_type == other.network_type
class ExampleNameRef(model.Model): object_id = model.PrimaryKey() ref = model.Dependency(Example.get_class_qualname())