예제 #1
0
 def test_get_by_id(self):
     self.mox.StubOutWithMock(db, 'compute_node_get')
     db.compute_node_get(self.context, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(self.context, 123)
     self.compare_obj(compute, fake_compute_node,
                      comparators={'stats': self.json_comparator})
예제 #2
0
 def test_get_by_id(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'compute_node_get')
     db.compute_node_get(ctxt, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(ctxt, 123)
     self._compare(compute, fake_compute_node)
예제 #3
0
 def test_get_by_id(self):
     ctxt = context.get_admin_context()
     self.mox.StubOutWithMock(db, 'compute_node_get')
     db.compute_node_get(ctxt, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(ctxt, 123)
     self._compare(compute, fake_compute_node)
예제 #4
0
 def test_get_by_id(self):
     self.mox.StubOutWithMock(db, "compute_node_get")
     db.compute_node_get(self.context, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(self.context, 123)
     self.compare_obj(compute, fake_compute_node, subs=self.subs(), comparators=self.comparators())
     self.assertNotIn("uuid", compute.obj_what_changed())
예제 #5
0
 def test_get_by_id(self):
     self.mox.StubOutWithMock(db, 'compute_node_get')
     db.compute_node_get(self.context, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(self.context, 123)
     self.compare_obj(compute, fake_compute_node,
                      comparators={'stats': self.json_comparator})
예제 #6
0
 def test_get_by_id(self):
     self.mox.StubOutWithMock(db, 'compute_node_get')
     db.compute_node_get(self.context, 123).AndReturn(fake_compute_node)
     self.mox.ReplayAll()
     compute = compute_node.ComputeNode.get_by_id(self.context, 123)
     self.compare_obj(compute, fake_compute_node,
                      subs=self.subs(),
                      comparators=self.comparators())
     self.assertNotIn('uuid', compute.obj_what_changed())
예제 #7
0
 def test_save_creates_inventories(self, mock_minver):
     mock_minver.return_value = 7
     self.cn.create()
     inventories = objects.InventoryList.get_all_by_resource_provider_uuid(
         self.context, self.cn.uuid)
     self.assertEqual(0, len(inventories))
     mock_minver.return_value = 10
     self.cn.memory_mb = 2048
     self.cn.local_gb = 2000
     self.cn.save()
     self.assertEqual(2048, self.cn.memory_mb)
     self.assertEqual(2000, self.cn.local_gb)
     self.assertEqual(8, self.cn.vcpus)
     db_cn = db.compute_node_get(self.context, self.cn.id)
     self.assertEqual(0, db_cn['memory_mb'])
     self.assertEqual(0, db_cn['local_gb'])
     self.assertEqual(0, db_cn['vcpus'])
     inventories = objects.InventoryList.get_all_by_resource_provider_uuid(
         self.context, self.cn.uuid)
     self.assertEqual(3, len(inventories))
     inv = {i.resource_class: i.total for i in inventories}
     expected = {
         fields.ResourceClass.DISK_GB: 2000,
         fields.ResourceClass.MEMORY_MB: 2048,
         fields.ResourceClass.VCPU: 8,
     }
     self.assertEqual(expected, inv)
예제 #8
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()
            self.uuid = updates['uuid']

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        if self._should_manage_inventory():
            self._create_inventory(updates)

        db_compute = db.compute_node_create(self._context, updates)
        # NOTE(danms): compute_node_create() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, db_compute['id'])
        self._from_db_object(self._context, self, db_compute)
예제 #9
0
    def create(self, req, body):
        '''
        :request url: /v2/{tenant_id}/pssr-url/{user_id}
        :param req: user_id:the user to caculate
        :param request: input user data
        :return:

        '''
        import time
        request = body["pssr_tag"]
        LOG.info("PssrController pssr_conf,req = %s" % req)
        LOG.info("PssrController pssr_conf,request = %s" % request)
        context = req.environ['nova.context']
        physerver = request["physerver"]
        node_id = self.get_node_id_from_name(context, physerver)
        physerver_name = db.compute_node_get(
            context, node_id)["host"]  #name include domain

        intf_conf = self.pssr_get_intf_conf(context, node_id, request["name"])
        intf_conf = intf_conf["pssr_tag"]["results"]

        #repeat config or have been config other
        if intf_conf["network_type"] != "" and request[
                "network_type"] != "none":
            return {
                "pssr_tag": {
                    "results": "config fail,network have been config"
                }
            }
        if intf_conf["network_type"] == "" and request[
                "network_type"] == "none":
            return {"pssr_tag": {"results": "config fail,repeat config"}}

        request["last_network_type"] = intf_conf["network_type"]
        cctxt = rpc.get_client(
            messaging.Target(topic="compute", server=physerver_name))
        cctxt = cctxt.prepare(version='4.11')
        pid1 = cctxt.call(get_admin_context(),
                          "get_nova_compute_pid",
                          req=request)
        cctxt.cast(get_admin_context(), "nfvi_pssr_conf", req=request)
        for i in range(0, 10):
            time.sleep(1)
            pid2 = cctxt.call(get_admin_context(),
                              "get_nova_compute_pid",
                              req=request)
            #LOG.info("PssrController nfvi_pssr_conf,pid1 = %s,pid2 = %s" % (pid1,pid2))
            if pid1 == pid2:
                continue
            else:
                results = {"status": "success"}
                self.pssr_update_intf_conf(context, node_id, intf_conf,
                                           request)
                LOG.info(
                    "PssrController nfvi_pssr_conf,pid2 = %s,results = %s" %
                    (pid2, results))
                return {"pssr_tag": {"results": results}}

        LOG.error("nfvi_pssr_conf get_nova_compute_pid fail,pid2 = %s", pid2)
        return {"pssr_tag": {"results": "config fail"}}
예제 #10
0
    def create(self):
        if self.obj_attr_is_set('id'):
            raise exception.ObjectActionError(action='create',
                                              reason='already created')
        updates = self.obj_get_changes()
        if 'uuid' not in updates:
            updates['uuid'] = uuidutils.generate_uuid()
            self.uuid = updates['uuid']

        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        if self._should_manage_inventory():
            self._create_inventory(updates)

        db_compute = db.compute_node_create(self._context, updates)
        # NOTE(danms): compute_node_create() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, db_compute['id'])
        self._from_db_object(self._context, self, db_compute)
예제 #11
0
파일: pci.py 프로젝트: wu330/pci_api
 def show(self, req, resp_obj, id):
     context = req.environ['nova.context']
     resp_obj.attach(xml=PciHypervisorTemplate())
     hypervisor = resp_obj.obj['hypervisor']
     # TODO(yjiang5): Change to compute node object after that change merged
     #compute_node = compute_obj.ComputeNode.get_by_id(
     #    context, hypervisor['id'])
     compute_node = db.compute_node_get(context, hypervisor['id'])
     self._extend_hypervisor(hypervisor, compute_node)
예제 #12
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     try:
         hyp = db.compute_node_get(context, int(id))
     except (ValueError, exception.ComputeHostNotFound):
         msg = _("Hypervisor with ID '%s' could not be found.") % id
         raise webob.exc.HTTPNotFound(explanation=msg)
     return dict(hypervisor=self._view_hypervisor(hyp, True))
예제 #13
0
 def show(self, req, id):
     context = req.environ['nova.context']
     authorize(context)
     try:
         hyp = db.compute_node_get(context, int(id))
     except (ValueError, exception.ComputeHostNotFound):
         msg = _("Hypervisor with ID '%s' could not be found.") % id
         raise webob.exc.HTTPNotFound(explanation=msg)
     return dict(hypervisor=self._view_hypervisor(hyp, True))
예제 #14
0
파일: pci.py 프로젝트: yjiang5/pci_api
 def show(self, req, resp_obj, id):
     context = req.environ['nova.context']
     resp_obj.attach(xml=PciHypervisorTemplate())
     hypervisor = resp_obj.obj['hypervisor']
     # TODO(yjiang5): Change to compute node object after that change merged
     #compute_node = compute_obj.ComputeNode.get_by_id(
     #    context, hypervisor['id'])
     compute_node = db.compute_node_get(context, hypervisor['id'])
     self._extend_hypervisor(hypervisor, compute_node)
예제 #15
0
파일: pci.py 프로젝트: wu330/pci_api
 def detail(self, req, resp_obj):
     context = req.environ['nova.context']
     hypervisors = list(resp_obj.obj['hypervisors'])
     for hypervisor in hypervisors:
         # TODO(yjiang5): Change to compute node object after
         # that changes merged
         # compute_node = compute_obj.ComputeNode.get_by_id(
         #    context, hypervisor['id'])
         compute_node = db.compute_node_get(context, hypervisor['id'])
         hypervisor['os-pci:pci_stats'] = compute_node['pci_stats']
예제 #16
0
파일: pci.py 프로젝트: yjiang5/pci_api
 def detail(self, req, resp_obj):
     context = req.environ['nova.context']
     hypervisors = list(resp_obj.obj['hypervisors'])
     for hypervisor in hypervisors:
         # TODO(yjiang5): Change to compute node object after
         # that changes merged
         # compute_node = compute_obj.ComputeNode.get_by_id(
         #    context, hypervisor['id'])
         compute_node = db.compute_node_get(context, hypervisor['id'])
         hypervisor['os-pci:pci_stats'] = compute_node['pci_stats']
예제 #17
0
 def test_create_honors_version(self, mock_minver):
     mock_minver.return_value = 7
     self.cn.create()
     self.assertEqual(512, self.cn.memory_mb)
     self.assertEqual(1000, self.cn.local_gb)
     self.assertEqual(8, self.cn.vcpus)
     db_cn = db.compute_node_get(self.context, self.cn.id)
     self.assertEqual(512, db_cn['memory_mb'])
     self.assertEqual(1000, db_cn['local_gb'])
     self.assertEqual(8, db_cn['vcpus'])
     inventories = objects.InventoryList.get_all_by_resource_provider_uuid(
         self.context, self.cn.uuid)
     self.assertEqual(0, len(inventories))
예제 #18
0
    def uptime(self, req, id):
        context = req.environ['nova.context']
        authorize(context)
        try:
            hyp = db.compute_node_get(context, int(id))
        except (ValueError, exception.ComputeHostNotFound):
            msg = _("Hypervisor with ID '%s' could not be found.") % id
            raise webob.exc.HTTPNotFound(explanation=msg)

        # Get the uptime
        try:
            uptime = self.api.get_host_uptime(context, hyp)
        except NotImplementedError:
            msg = _("Virt driver does not implement uptime function.")
            raise webob.exc.HTTPNotImplemented(explanation=msg)

        return dict(hypervisor=self._view_hypervisor(hyp, False,
                                                     uptime=uptime))
예제 #19
0
    def uptime(self, req, id):
        context = req.environ['nova.context']
        authorize(context)
        try:
            hyp = db.compute_node_get(context, int(id))
        except (ValueError, exception.ComputeHostNotFound):
            msg = _("Hypervisor with ID '%s' could not be found.") % id
            raise webob.exc.HTTPNotFound(explanation=msg)

        # Get the uptime
        try:
            uptime = self.api.get_host_uptime(context, hyp)
        except NotImplementedError:
            msg = _("Virt driver does not implement uptime function.")
            raise webob.exc.HTTPNotImplemented(explanation=msg)

        return dict(
            hypervisor=self._view_hypervisor(hyp, False, uptime=uptime))
예제 #20
0
    def save(self, prune_stats=False):
        # NOTE(belliott) ignore prune_stats param, no longer relevant

        updates = self.obj_get_changes()
        updates.pop('id', None)
        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        db_compute = db.compute_node_update(self._context, self.id, updates)
        # NOTE(danms): compute_node_update() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, self.id)
        self._from_db_object(self._context, self, db_compute)
예제 #21
0
    def save(self, prune_stats=False):
        # NOTE(belliott) ignore prune_stats param, no longer relevant

        updates = self.obj_get_changes()
        updates.pop('id', None)
        self._convert_stats_to_db_format(updates)
        self._convert_host_ip_to_db_format(updates)
        self._convert_supported_instances_to_db_format(updates)
        self._convert_pci_stats_to_db_format(updates)

        db_compute = db.compute_node_update(self._context, self.id, updates)
        # NOTE(danms): compute_node_update() operates on (and returns) the
        # compute node model only. We need to get the full inventory-based
        # result in order to satisfy _from_db_object(). So, we do a double
        # query here. This can be removed in Newton once we're sure that all
        # compute nodes are inventory-based
        db_compute = db.compute_node_get(self._context, self.id)
        self._from_db_object(self._context, self, db_compute)
예제 #22
0
    def show(self, req, id):
        '''
        :request url: /v2/{tenant_id}/pssr-url/{user_id}
        :param req: user_id:the user to caculate
        :param id: input the tenant_id which the user belong to
        :return:
        '''
        physerver = req.GET.get("physerver")  #name don't include domain
        dev = req.GET.get("dev")
        LOG.info("PssrController paras  id = %s, physerver=%s, dev=%s" %
                 (id, physerver, dev))
        context = req.environ['nova.context']
        node_id = self.get_node_id_from_name(context, physerver)
        if node_id == -1:
            return {
                "pssr_tag": {
                    "results": [{
                        "physerver_type": "not_compute"
                    }]
                }
            }
        physerver_name = db.compute_node_get(
            context, node_id)["host"]  #name include domain
        cctxt = rpc.get_client(
            messaging.Target(topic="compute", server=physerver_name))

        cctxt = cctxt.prepare(version='4.11')
        #        results = cctxt.cast(get_admin_context(), "ttt", a=1, b=2, c=3, d=4)
        if id == '1':
            return self.pssr_get_port_info(context, cctxt, node_id)
        elif id == '2':
            return self.pssr_get_intf_info(context, cctxt, node_id)
        elif id == "11":
            return self.pssr_get_port_conf(context, node_id, dev)
        elif id == "21":
            return self.pssr_get_intf_conf(context, node_id, dev)
        else:
            LOG.info("PssrController paras error, id = %s" % id)
            return {"pssr_tag": {"results": "error"}}
예제 #23
0
 def get_by_id(cls, context, compute_id):
     db_compute = db.compute_node_get(context, compute_id)
     return cls._from_db_object(context, cls(), db_compute)
예제 #24
0
 def get_by_id(cls, context, compute_id):
     db_compute = db.compute_node_get(context, compute_id)
     return cls._from_db_object(context, cls(), db_compute)