class IPReservation(network.NetworkResource): attributes = attr.AttributeCollection({ "occi.ipreservation.address": attr.MutableAttribute("occi.ipreservation.address", description="Internet Protocol(IP) network" " address re-served for Compute instances" " linking with this IPReservation instance", attr_type=attr.AttributeType.string_type), "occi.ipreservation.used": attr.InmutableAttribute("occi.ipreservation.used", description="Indication whether" " the reserved address is currently in use.", attr_type=attr.AttributeType.boolean_type), "occi.ipreservation.state": attr.InmutableAttribute( "occi.ipreservation.state", description="Indicates the state of the resource.", attr_type=attr.AttributeType.string_type), }) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'ipreservation', 'IPReservation', attributes, 'ipreservation/', parent=network.NetworkResource.kind) def __init__(self, title, address, id=None, used=False, state=None, mixins=[]): super(IPReservation, self).__init__(title, id=id, mixins=mixins) self.address = address self.attributes["occi.ipreservation.used"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.ipreservation.used"], used)) self.attributes["occi.ipreservation.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.ipreservation.state"], state)) @property def address(self): return self.attributes["occi.ipreservation.address"].value @address.setter def address(self, value): self.attributes["occi.ipreservation.address"].value = value @property def used(self): return self.attributes["occi.ipreservation.used"].value @property def state(self): return self.attributes["occi.ipreservation.state"].value
def __init__(self, mixins, source, target, id=None, interface=None, mac=None, state=None): super(NetworkInterface, self).__init__(None, mixins, source, target, id) self.attributes["occi.networkinterface.interface"] = ( attr.InmutableAttribute("occi.networkinterface.interface", interface)) self.attributes["occi.networkinterface.mac"] = attr.MutableAttribute( "occi.networkinterface.mac", mac) self.attributes["occi.networkinterface.state"] = ( attr.InmutableAttribute("occi.networkinterface.state", state))
def __init__(self, name=None, data=None): attrs = [ attribute.InmutableAttribute( "org.openstack.credentials.publickey.name", name), attribute.InmutableAttribute( "org.openstack.credentials.publickey.data", data), ] attrs = attribute.AttributeCollection({a.name: a for a in attrs}) super(OpenStackPublicKey, self).__init__(OpenStackPublicKey.scheme, OpenStackPublicKey.term, "Contextualization extension - public_key", attributes=attrs)
class SecurityGroupLink(link.Link): attributes = attr.AttributeCollection({ "occi.securitygrouplink.state": attr.InmutableAttribute("occi.securitygrouplink.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type) }) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'securitygrouplink', 'security group link resource', attributes, 'securitygrouplink/', parent=link.Link.kind) def __init__(self, source, target, state=None): link_id = '_'.join([source.id, target.id]) super(SecurityGroupLink, self).__init__(None, [], source, target, link_id) self.attributes["occi.securitygrouplink.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.securitygrouplink.state"], state)) @property def state(self): return self.attributes["occi.securitygrouplink.state"].value
def __init__(self, title, summary=None, id=None, architecture=None, cores=None, hostname=None, share=None, memory=None, state=None, message=None, mixins=[]): super(ComputeResource, self).__init__(title, mixins, summary=summary, id=id) self.architecture = architecture self.cores = cores self.hostname = hostname self.share = share self.memory = memory self.attributes["occi.compute.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.compute.state"], state)) self.attributes["occi.compute.state.message"] = ( attr.InmutableAttribute( self.attributes["occi.compute.state.message"], message))
def test_inmutable(self): attr = attribute.InmutableAttribute("occi.foo.bar", "bar") def set_val(): attr.value = "bazonk" self.assertRaises(AttributeError, set_val)
def __init__(self, title, summary=None, id=None, architecture=None, cores=None, hostname=None, speed=None, memory=None, state=None, mixins=[]): super(ComputeResource, self).__init__(title, mixins, summary=summary, id=id) self.attributes["occi.compute.architecture"] = attr.MutableAttribute( "occi.compute.architecture", architecture) self.attributes["occi.compute.cores"] = attr.MutableAttribute( "occi.compute.cores", cores) self.attributes["occi.compute.hostname"] = attr.MutableAttribute( "occi.compute.hostname", hostname) self.attributes["occi.compute.speed"] = attr.MutableAttribute( "occi.compute.speed", speed) self.attributes["occi.compute.memory"] = attr.MutableAttribute( "occi.compute.memory", memory) self.attributes["occi.compute.state"] = attr.InmutableAttribute( "occi.compute.state", state)
def test_inmutable(self): attr = attribute.InmutableAttribute("occi.foo.bar", "bar") self.assertEqual(attribute.AttributeType.object_type, attr.attr_type) def set_val(): attr.value = "bazonk" self.assertRaises(AttributeError, set_val)
class Entity(object): """OCCI Entity. Entity is an abstract type, which both Resource and Link inherit. Each sub-type of Entity is identified by a unique Kind instance """ attributes = attribute.AttributeCollection({ "occi.core.id": attribute.InmutableAttribute( "occi.core.id", description="A unique identifier", attr_type=attribute.AttributeType.string_type), "occi.core.title": attribute.MutableAttribute( "occi.core.title", description="The display name of the instance", attr_type=attribute.AttributeType.string_type), }) kind = kind.Kind(helpers.build_scheme('core'), 'entity', 'entity', attributes, 'entity/') actions = None def __init__(self, title, mixins, id=None): helpers.check_type(mixins, mixin.Mixin) self.mixins = mixins # NOTE(aloga): we need a copy of the attributes, otherwise we will be # using the class ones instead of the object ones. self.attributes = self.attributes.copy() # damn, we're shading a builtin if id is None: id = uuid.uuid4().hex self.attributes["occi.core.id"] = ( attribute.InmutableAttribute.from_attr( self.attributes["occi.core.id"], id)) self.title = title @property def id(self): return self.attributes["occi.core.id"].value @property def title(self): return self.attributes["occi.core.title"].value @title.setter def title(self, value): self.attributes["occi.core.title"].value = value @property def location(self): return utils.join_url(self.kind.location, self.id)
def __init__(self, title, summary=None, id=None, size=None, state=None): mixins = [] super(StorageResource, self).__init__(title, mixins, summary=summary, id=id) self.attributes["occi.storage.size"] = attr.MutableAttribute( "occi.storage.size", size) self.attributes["occi.storage.state"] = attr.InmutableAttribute( "occi.storage.state", state)
def __init__(self, user_data=None): attrs = [ attribute.InmutableAttribute("org.openstack.compute.user_data", user_data), ] attrs = attribute.AttributeCollection({a.name: a for a in attrs}) super(OpenStackUserData, self).__init__(OpenStackUserData.scheme, OpenStackUserData.term, "Contextualization extension - user_data", attributes=attrs)
def __init__(self, title, mixins, id=None): helpers.check_type(mixins, mixin.Mixin) self.mixins = mixins # NOTE(aloga): we need a copy of the attributes, otherwise we will be # using the class ones instead of the object ones. self.attributes = self.attributes.copy() # damn, we're shading a builtin if id is None: id = uuid.uuid4().hex self.attributes["occi.core.id"] = attribute.InmutableAttribute( "occi.core.id", id) self.attributes["occi.core.title"] = attribute.MutableAttribute( "occi.core.title", title)
def __init__(self, source, target, deviceid=None, mountpoint=None, state=None): # TODO(enolfc): is this a valid link id? link_id = '_'.join([source.id, target.id]) super(StorageLink, self).__init__(None, [], source, target, link_id) self.attributes["occi.storagelink.deviceid"] = attr.MutableAttribute( "occi.storagelink.deviceid", deviceid) self.attributes["occi.storagelink.mountpoint"] = attr.MutableAttribute( "occi.storagelink.mountpoint", mountpoint) self.attributes["occi.storagelink.state"] = attr.InmutableAttribute( "occi.storagelink.state", state)
class SecurityGroupResource(resource.Resource): attributes = attr.AttributeCollection({ "occi.securitygroup.rules": attr.MutableAttribute("occi.securitygroup.rules", description="Security Rules", attr_type=attr.AttributeType.list_type), "occi.securitygroup.state": attr.InmutableAttribute("occi.securitygroup.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type) }) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'securitygroup', 'securitygroup resource', attributes, 'securitygroup/', parent=resource.Resource.kind) def __init__(self, title, id=None, rules=None, summary=None, state=None, mixins=[]): super(SecurityGroupResource, self).__init__(title, mixins, summary=summary, id=id) self.rules = rules self.attributes["occi.securitygroup.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.securitygroup.state"], state)) @property def rules(self): return self.attributes["occi.securitygroup.rules"].value @rules.setter def rules(self, value): self.attributes["occi.securitygroup.rules"].value = value @property def state(self): return self.attributes["occi.securitygroup.state"].value
def __init__(self, title, summary=None, id=None, vlan=None, label=None, state=None, mixins=[]): super(NetworkResource, self).__init__(title, mixins, summary=summary, id=id) self.attributes["occi.network.vlan"] = attr.MutableAttribute( "occi.network.vlan", vlan) self.attributes["occi.network.label"] = attr.MutableAttribute( "occi.network.label", label) self.attributes["occi.network.state"] = attr.InmutableAttribute( "occi.network.state", state)
def __init__(self, title, summary=None, id=None, vlan=None, label=None, state=None, message=None, mixins=[]): super(NetworkResource, self).__init__(title, mixins, summary=summary, id=id) self.vlan = vlan self.label = label self.attributes["occi.network.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.network.state"], state)) self.attributes["occi.network.state.message"] = ( attr.InmutableAttribute( self.attributes["occi.network.state.message"], message))
def __init__(self, id, name, cores, memory, disk, ephemeral=0, swap=0): attrs = [ attribute.InmutableAttribute("occi.compute.cores", cores), attribute.InmutableAttribute("occi.compute.memory", memory), attribute.InmutableAttribute("occi.compute.disk", disk), attribute.InmutableAttribute("occi.compute.ephemeral", ephemeral), attribute.InmutableAttribute("occi.compute.swap", swap), attribute.InmutableAttribute("org.openstack.flavor.name", name) ] attrs = attribute.AttributeCollection({a.name: a for a in attrs}) super(OpenStackResourceTemplate, self).__init__(OpenStackResourceTemplate.scheme, id, "Flavor: %s" % name, related=[templates.resource_tpl], attributes=attrs)
def __init__(self, id, name, cores, memory, disk, ephemeral=0, swap=0): attrs = [ attribute.InmutableAttribute( "occi.compute.cores", cores, attr_type=attribute.AttributeType.number_type), attribute.InmutableAttribute( "occi.compute.memory", memory, attr_type=attribute.AttributeType.number_type), attribute.InmutableAttribute( "org.openstack.flavor.disk", disk, attr_type=attribute.AttributeType.number_type), attribute.InmutableAttribute( "org.openstack.flavor.ephemeral", ephemeral, attr_type=attribute.AttributeType.number_type), attribute.InmutableAttribute( "org.openstack.flavor.swap", swap, attr_type=attribute.AttributeType.number_type), attribute.InmutableAttribute( "org.openstack.flavor.name", name, attr_type=attribute.AttributeType.string_type), ] attrs = attribute.AttributeCollection({a.name: a for a in attrs}) location = "%s/%s" % (self._location, id) super(OpenStackResourceTemplate, self).__init__(id, "Flavor: %s" % name, depends=[templates.resource_tpl], attributes=attrs, location=location)
class NetworkInterface(link.Link): attributes = attr.AttributeCollection({ "occi.networkinterface.interface": attr.InmutableAttribute( "occi.networkinterface.interface", description=("Identifier that relates the link to the link's " "device interface."), attr_type=attr.AttributeType.string_type), "occi.networkinterface.mac": attr.MutableAttribute( "occi.networkinterface.mac", description=("MAC address associated with the link's device " "interface."), attr_type=attr.AttributeType.string_type), "occi.networkinterface.state": attr.InmutableAttribute("occi.networkinterface.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type), "occi.networkinterface.state.message": attr.InmutableAttribute( "occi.networkinterface.state.message", description=("Human-readable explanation of the current instance " "state"), attr_type=attr.AttributeType.string_type), }) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'networkinterface', 'network link resource', attributes, 'networklink/', parent=link.Link.kind) def __init__(self, mixins, source, target, id=None, interface=None, mac=None, state=None, message=None): super(NetworkInterface, self).__init__(None, mixins, source, target, id) self.attributes["occi.networkinterface.interface"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.networkinterface.interface"], interface)) self.mac = mac self.attributes["occi.networkinterface.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.networkinterface.state"], state)) self.attributes["occi.networkinterface.state.message"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.networkinterface.state.message"], message)) @property def interface(self): return self.attributes["occi.networkinterface.interface"].value @property def mac(self): return self.attributes["occi.networkinterface.mac"].value @mac.setter def mac(self, value): self.attributes["occi.networkinterface.mac"].value = value @property def state(self): return self.attributes["occi.networkinterface.state"].value @property def message(self): return self.attributes["occi.networkinterface.state.message"].value
class ComputeResource(resource.Resource): attributes = attr.AttributeCollection({ "occi.compute.architecture": attr.MutableAttribute("occi.compute.architecture", description="CPU architecture of the instance", attr_type=attr.AttributeType.string_type), "occi.compute.cores": attr.MutableAttribute( "occi.compute.cores", description="Number of virtual cores assigned to the instance", attr_type=attr.AttributeType.number_type), "occi.compute.hostname": attr.MutableAttribute( "occi.compute.hostname", description="Fully Qualified DNS hostname for the instance", attr_type=attr.AttributeType.string_type), "occi.compute.share": attr.MutableAttribute( "occi.compute.share", description="Relative number of CPU shares for the instance", attr_type=attr.AttributeType.number_type), "occi.compute.memory": attr.MutableAttribute( "occi.compute.memory", description="Maximum RAM in gigabytes allocated to the instance", attr_type=attr.AttributeType.number_type), "occi.compute.state": attr.InmutableAttribute("occi.compute.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type), "occi.compute.state.message": attr.InmutableAttribute( "occi.compute.state.message", description=("Human-readable explanation of the current instance " "state"), attr_type=attr.AttributeType.string_type), }) actions = (start, stop, restart, suspend) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'compute', 'compute resource', attributes, 'compute/', actions=actions, parent=resource.Resource.kind) def __init__(self, title, summary=None, id=None, architecture=None, cores=None, hostname=None, share=None, memory=None, state=None, message=None, mixins=[]): super(ComputeResource, self).__init__(title, mixins, summary=summary, id=id) self.architecture = architecture self.cores = cores self.hostname = hostname self.share = share self.memory = memory self.attributes["occi.compute.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.compute.state"], state)) self.attributes["occi.compute.state.message"] = ( attr.InmutableAttribute( self.attributes["occi.compute.state.message"], message)) @property def architecture(self): return self.attributes["occi.compute.architecture"].value @architecture.setter def architecture(self, value): self.attributes["occi.compute.architecture"].value = value @property def cores(self): return self.attributes["occi.compute.cores"].value @cores.setter def cores(self, value): self.attributes["occi.compute.cores"].value = value @property def hostname(self): return self.attributes["occi.compute.hostname"].value @hostname.setter def hostname(self, value): self.attributes["occi.compute.hostname"].value = value @property def share(self): return self.attributes["occi.compute.share"].value @share.setter def share(self, value): self.attributes["occi.compute.share"].value = value @property def memory(self): return self.attributes["occi.compute.memory"].value @memory.setter def memory(self, value): self.attributes["occi.compute.memory"].value = value @property def state(self): return self.attributes["occi.compute.state"].value @property def message(self): return self.attributes["occi.compute.state.message"].value
class NetworkResource(resource.Resource): attributes = attr.AttributeCollection({ "occi.network.vlan": attr.MutableAttribute("occi.network.vlan", description="802.1q VLAN identifier", attr_type=attr.AttributeType.string_type), "occi.network.label": attr.MutableAttribute("occi.network.label", description="Tag based VLANs", attr_type=attr.AttributeType.string_type), "occi.network.state": attr.InmutableAttribute("occi.network.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type), "occi.network.state.message": attr.InmutableAttribute( "occi.network.state.message", description=("Human-readable explanation of the current instance " "state"), attr_type=attr.AttributeType.string_type), }) actions = (up, down) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'network', 'network resource', attributes, 'network/', actions=actions, parent=resource.Resource.kind) def __init__(self, title, summary=None, id=None, vlan=None, label=None, state=None, message=None, mixins=[]): super(NetworkResource, self).__init__(title, mixins, summary=summary, id=id) self.vlan = vlan self.label = label self.attributes["occi.network.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.network.state"], state)) self.attributes["occi.network.state.message"] = ( attr.InmutableAttribute( self.attributes["occi.network.state.message"], message)) @property def vlan(self): return self.attributes["occi.network.vlan"].value @vlan.setter def vlan(self, value): self.attributes["occi.network.vlan"].value = value @property def label(self): return self.attributes["occi.network.label"].value @label.setter def label(self, value): self.attributes["occi.network.label"].value = value @property def state(self): return self.attributes["occi.network.state"].value @property def message(self): return self.attributes["occi.network.state.message"].value
class StorageResource(resource.Resource): attributes = attr.AttributeCollection({ "occi.storage.size": attr.MutableAttribute( "occi.storage.size", required=True, description="Storage size of the instance in gigabytes", attr_type=attr.AttributeType.number_type), "occi.storage.state": attr.InmutableAttribute("occi.storage.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type), "occi.storage.state.message": attr.InmutableAttribute( "occi.storage.state.message", description=("Human-readable explanation of the current instance " "state"), attr_type=attr.AttributeType.string_type), }) actions = (online, offline, backup, snapshot, resize) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'storage', 'storage resource', attributes, 'storage/', actions=actions, parent=resource.Resource.kind) def __init__(self, title, summary=None, id=None, size=None, state=None, message=None): mixins = [] super(StorageResource, self).__init__(title, mixins, summary=summary, id=id) self.size = size self.attributes["occi.storage.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.storage.state"], state)) self.attributes["occi.storage.state.message"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.storage.state.message"], message)) @property def size(self): return self.attributes["occi.storage.size"].value @size.setter def size(self, value): self.attributes["occi.storage.size"].value = value @property def state(self): return self.attributes["occi.storage.state"].value @property def message(self): return self.attributes["occi.storage.state.message"].value
class StorageLink(link.Link): attributes = attr.AttributeCollection({ "occi.storagelink.deviceid": attr.MutableAttribute( "occi.storagelink.deviceid", description=("Device identifier as defined by the OCCI service " "provider"), attr_type=attr.AttributeType.string_type), "occi.storagelink.mountpoint": attr.MutableAttribute( "occi.storagelink.mountpoint", description=("Point to where the storage is mounted " "in the guest OS"), attr_type=attr.AttributeType.string_type), "occi.storagelink.state": attr.InmutableAttribute("occi.storagelink.state", description="Current state of the instance", attr_type=attr.AttributeType.string_type), "occi.storagelink.state.message": attr.InmutableAttribute( "occi.storagelink.state.message", description=("Human-readable explanation of the current instance " "state"), attr_type=attr.AttributeType.string_type), }) kind = kind.Kind(helpers.build_scheme('infrastructure'), 'storagelink', 'storage link resource', attributes, 'storagelink/', parent=link.Link.kind) def __init__(self, source, target, deviceid=None, mountpoint=None, state=None, message=None): # TODO(enolfc): is this a valid link id? link_id = '_'.join([source.id, target.id]) super(StorageLink, self).__init__(None, [], source, target, link_id) self.deviceid = deviceid self.mountpoint = mountpoint self.attributes["occi.storagelink.state"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.storagelink.state"], state)) self.attributes["occi.storagelink.state.message"] = ( attr.InmutableAttribute.from_attr( self.attributes["occi.storagelink.state.message"], message)) @property def deviceid(self): return self.attributes["occi.storagelink.deviceid"].value @deviceid.setter def deviceid(self, value): self.attributes["occi.storagelink.deviceid"].value = value @property def mountpoint(self): return self.attributes["occi.storagelink.mountpoint"].value @mountpoint.setter def mountpoint(self, value): self.attributes["occi.storagelink.mountpoint"].value = value @property def state(self): return self.attributes["occi.storagelink.state"].value @property def message(self): return self.attributes["occi.storagelink.state.message"].value