Exemple #1
0
    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]
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
    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)
Exemple #6
0
    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])
Exemple #7
0
    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]
Exemple #8
0
 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))