def show(self, req, id): v = self.os_helper.get_volume(req, id) state = helpers.vol_state(v["status"]) st = storage.StorageResource(title=v["displayName"], id=v["id"], size=v["size"], state=state) return st
def test_storage(self): id = uuid.uuid4().hex s = storage.StorageResource("foo", summary="This is a summary", id=id) self.assertEqual("foo", s.title) self.assertEqual(id, s.id) self.assertEqual("This is a summary", s.summary) self.assertIsNone(s.size) self.assertIsNone(s.state)
def index(self, req): volumes = self.os_helper.get_volumes(req) occi_storage_resources = [] if volumes: for v in volumes: s = storage.StorageResource(title=v["displayName"], id=v["id"]) occi_storage_resources.append(s) return collection.Collection(resources=occi_storage_resources)
def show(self, req, id): # get info from server s = self.os_helper.get_server(req, id) # get info from flavor flavor = self.os_helper.get_flavor(req, s["flavor"]["id"]) res_tpl = templates.OpenStackResourceTemplate(flavor["id"], flavor["name"], flavor["vcpus"], flavor["ram"], flavor["disk"]) # get info from image img_id = s["image"]["id"] try: image = self.os_helper.get_image(req, img_id) except webob.exc.HTTPNotFound: image = { "id": img_id, "name": "None (Image with ID '%s' not found)" % img_id, } os_tpl = templates.OpenStackOSTemplate(image["id"], image["name"]) # build the compute object comp = compute.ComputeResource(title=s["name"], id=s["id"], cores=flavor["vcpus"], hostname=s["name"], memory=flavor["ram"], state=helpers.vm_state(s["status"]), mixins=[os_tpl, res_tpl]) # storage links vols = self.os_helper.get_server_volumes_link(req, s["id"]) for v in vols: st = storage.StorageResource(title="storage", id=v["volumeId"]) comp.add_link( storage_link.StorageLink(comp, st, deviceid=v["device"])) # network links addresses = s.get("addresses", {}) if addresses: for addr_set in addresses.values(): for addr in addr_set: # TODO(jorgesece): add pool information if addr["OS-EXT-IPS:type"] == "floating": net_id = helpers.PUBLIC_NETWORK else: try: net_id = self.os_helper.get_network_id( req, addr['OS-EXT-IPS-MAC:mac_addr'], id) except webob.exc.HTTPNotFound: net_id = "FIXED" comp.add_link(_create_network_link(addr, comp, net_id)) return [comp]
def test_setters(self): c = compute.ComputeResource("foo", summary="This is a summary", id=uuid.uuid4().hex) s = storage.StorageResource("bar", summary="This is a summary", id=uuid.uuid4().hex) l = storage_link.StorageLink(c, s) l.deviceid = "/dev/vdc" self.assertEqual("/dev/vdc", l.attributes["occi.storagelink.deviceid"].value) l.mountpoint = "/mnt" self.assertEqual("/mnt", l.attributes["occi.storagelink.mountpoint"].value)
def test_getters(self): c = compute.ComputeResource("foo", summary="This is a summary", id=uuid.uuid4().hex) s = storage.StorageResource("bar", summary="This is a summary", id=uuid.uuid4().hex) l = storage_link.StorageLink(c, s, deviceid="/dev/vdc", mountpoint="/mnt", state="foobar") self.assertEqual("/dev/vdc", l.deviceid) self.assertEqual("/mnt", l.mountpoint) self.assertEqual("foobar", l.state)
def test_storagelink(self): server_id = uuid.uuid4().hex c = compute.ComputeResource("foo", summary="This is a summary", id=server_id) vol_id = uuid.uuid4().hex s = storage.StorageResource("bar", summary="This is a summary", id=vol_id) l = storage_link.StorageLink(c, s) link_id = '%s_%s' % (server_id, vol_id) self.assertEqual(link_id, l.id) self.assertIsNone(l.deviceid) self.assertIsNone(l.mountpoint) self.assertIsNone(l.state)
def index(self, req): volumes = self.os_helper.get_volumes(req) occi_link_resources = [] for v in volumes: for attach in v["attachments"]: if attach: c = compute.ComputeResource(title="Compute", id=attach["serverId"]) s = storage.StorageResource(title="Storage", id=v["id"]) l = storage_link.StorageLink(c, s, deviceid=attach["device"]) occi_link_resources.append(l) return collection.Collection(resources=occi_link_resources)
def create(self, req, body): parser = req.get_parser()(req.headers, req.body) scheme = {"category": storage_link.StorageLink.kind} obj = parser.parse() validator = occi_validator.Validator(obj) validator.validate(scheme) attrs = obj.get("attributes", {}) vol_id = attrs.get("occi.core.target") server_id = attrs.get("occi.core.source") device = attrs.get("occi.storagelink.deviceid", None) attachment = self.os_helper.create_server_volumes_link(req, server_id, vol_id, dev=device) c = compute.ComputeResource(title="Compute", id=server_id) s = storage.StorageResource(title="Storage", id=vol_id) l = storage_link.StorageLink(c, s, deviceid=attachment["device"]) return collection.Collection(resources=[l])
def show(self, req, id): # get info from server s = self.os_helper.get_server(req, id) # get info from flavor flavor = self.os_helper.get_flavor(req, s["flavor"]["id"]) res_tpl = templates.OpenStackResourceTemplate(flavor["id"], flavor["name"], flavor["vcpus"], flavor["ram"], flavor["disk"]) # get info from image image = self.os_helper.get_image(req, s["image"]["id"]) os_tpl = templates.OpenStackOSTemplate(image["id"], image["name"]) # build the compute object comp = compute.ComputeResource(title=s["name"], id=s["id"], cores=flavor["vcpus"], hostname=s["name"], memory=flavor["ram"], state=helpers.vm_state(s["status"]), mixins=[os_tpl, res_tpl]) # storage links vols = self.os_helper.get_server_volumes_link(req, s["id"]) for v in vols: st = storage.StorageResource(title="storage", id=v["volumeId"]) comp.add_link( storage_link.StorageLink(comp, st, deviceid=v["device"])) # network links addresses = s.get("addresses", {}) if addresses: for addr_set in addresses.values(): for addr in addr_set: comp.add_link(_create_network_link(addr, comp)) return [comp]
def create(self, req, body): parser = req.get_parser()(req.headers, req.body) scheme = {"category": storage.StorageResource.kind} obj = parser.parse() validator = occi_validator.Validator(obj) validator.validate(scheme) attrs = obj.get("attributes", {}) name = attrs.get("occi.core.title", "OCCI Volume") # TODO(enolfc): this should be handled by the validator try: size = attrs["occi.storage.size"] except KeyError: raise exception.Invalid() volume = self.os_helper.volume_create(req, name, size) st = storage.StorageResource(title=volume["displayName"], id=volume["id"], size=volume["size"], state=helpers.vol_state(volume["status"])) return collection.Collection(resources=[st])
def test_getters(self): s = storage.StorageResource("foo", size=5, state="foobar") self.assertEqual(5, s.size) self.assertEqual("foobar", s.state)
def test_setters(self): s = storage.StorageResource("foo") s.size = 3 self.assertEqual(3, s.attributes["occi.storage.size"].value)
def show(self, req, id): v = self._get_attachment_from_id(req, id) c = compute.ComputeResource(title="Compute", id=v["serverId"]) s = storage.StorageResource(title="Storage", id=v["volumeId"]) return storage_link.StorageLink(c, s, deviceid=v.get("device", None))