示例#1
0
    def get_compute_node_by_hostname(self, node_hostname):
        """Get compute node by ID (*not* UUID)"""
        # We need to pass an object with an 'id' attribute to make it work
        try:
            compute_nodes = self.nova.hypervisors.search(node_hostname)
            if len(compute_nodes) != 1:
                raise exception.ComputeNodeNotFound(name=node_hostname)

            return self.get_compute_node_by_id(compute_nodes[0].id)
        except Exception as exc:
            LOG.exception(exc)
            raise exception.ComputeNodeNotFound(name=node_hostname)
示例#2
0
 def get_node_by_instance_uuid(self, instance_uuid):
     instance = self._get_by_uuid(instance_uuid)
     for node_uuid in self.neighbors(instance.uuid):
         node = self._get_by_uuid(node_uuid)
         if isinstance(node, element.ComputeNode):
             return node
     raise exception.ComputeNodeNotFound(name=instance_uuid)
示例#3
0
 def remove_node(self, node):
     self.assert_node(node)
     try:
         super(ModelRoot, self).remove_node(node.uuid)
     except nx.NetworkXError as exc:
         LOG.exception(exc)
         raise exception.ComputeNodeNotFound(name=node.uuid)
    def test_instance_update_node_notfound_set_unmapped(
            self, m_nova_helper_cls):
        m_get_compute_node_by_hostname = mock.Mock(
            side_effect=exception.ComputeNodeNotFound(name="TEST"))
        m_nova_helper_cls.return_value = mock.Mock(
            get_compute_node_by_hostname=m_get_compute_node_by_hostname,
            name='m_nova_helper')

        compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes()
        self.fake_cdmc.cluster_data_model = compute_model
        handler = novanotification.InstanceUpdated(self.fake_cdmc)

        instance0_uuid = '9966d6bd-a45c-4e1c-9d57-3054899a3ec7'

        message = self.load_message('scenario3_notfound_instance-update.json')

        handler.info(
            ctxt=self.context,
            publisher_id=message['publisher_id'],
            event_type=message['event_type'],
            payload=message['payload'],
            metadata=self.FAKE_METADATA,
        )

        instance0 = compute_model.get_instance_by_uuid(instance0_uuid)

        self.assertEqual(element.InstanceState.PAUSED.value, instance0.state)
        self.assertEqual(1, instance0.vcpus)
        self.assertEqual(1, instance0.disk)
        self.assertEqual(1, instance0.disk_capacity)
        self.assertEqual(512, instance0.memory)

        m_get_compute_node_by_hostname.assert_any_call('Node_2')
        self.assertRaises(exception.ComputeNodeNotFound,
                          compute_model.get_node_by_uuid, 'Node_2')
示例#5
0
文件: nova.py 项目: akinsWin/watcher
    def create_compute_node(self, node_hostname):
        """Update the compute node by querying the Nova API."""
        try:
            _node = self.nova.get_compute_node_by_hostname(node_hostname)
            node = element.ComputeNode(_node.id)
            node.uuid = node_hostname
            node.hostname = _node.hypervisor_hostname
            node.state = _node.state
            node.status = _node.status

            self.update_capacity(element.ResourceType.memory, node,
                                 _node.memory_mb)
            self.update_capacity(element.ResourceType.cpu_cores, node,
                                 _node.vcpus)
            self.update_capacity(element.ResourceType.disk, node,
                                 _node.free_disk_gb)
            self.update_capacity(element.ResourceType.disk_capacity, node,
                                 _node.local_gb)
            return node
        except Exception as exc:
            LOG.exception(exc)
            LOG.debug("Could not refresh the node %s.", node_hostname)
            raise exception.ComputeNodeNotFound(name=node_hostname)

        return False
示例#6
0
    def get_compute_node_by_hostname(self, node_hostname):
        """Get compute node by hostname"""
        try:
            hypervisors = [hv for hv in self.get_compute_node_list()
                           if hv.service['host'] == node_hostname]
            if len(hypervisors) != 1:
                # TODO(hidekazu)
                # this may occur if VMware vCenter driver is used
                raise exception.ComputeNodeNotFound(name=node_hostname)
            else:
                compute_nodes = self.nova.hypervisors.search(
                    hypervisors[0].hypervisor_hostname)
                if len(compute_nodes) != 1:
                    raise exception.ComputeNodeNotFound(name=node_hostname)

                return self.get_compute_node_by_id(compute_nodes[0].id)
        except Exception as exc:
            LOG.exception(exc)
            raise exception.ComputeNodeNotFound(name=node_hostname)
示例#7
0
    def get_compute_node_by_hostname(self, node_hostname):
        """Get compute node by hostname

        :param node_hostname: Compute service hostname
        :returns: novaclient.v2.hypervisors.Hypervisor object if found
        :raises: ComputeNodeNotFound if no hypervisor is found for the compute
            service hostname or there was an error communicating with nova
        """
        try:
            # This is a fuzzy match on hypervisor_hostname so we could get back
            # more than one compute node. If so, match on the compute service
            # hostname.
            compute_nodes = self.get_compute_node_by_name(node_hostname,
                                                          detailed=True)
            for cn in compute_nodes:
                if cn.service['host'] == node_hostname:
                    return cn
            raise exception.ComputeNodeNotFound(name=node_hostname)
        except Exception as exc:
            LOG.exception(exc)
            raise exception.ComputeNodeNotFound(name=node_hostname)
示例#8
0
 def get_node_by_name(self, name):
     try:
         node_list = [
             cn['attr'] for uuid, cn in self.nodes(data=True)
             if (isinstance(cn['attr'], element.ComputeNode)
                 and cn['attr']['hostname'] == name)
         ]
         if node_list:
             return node_list[0]
         else:
             raise exception.ComputeResourceNotFound
     except exception.ComputeResourceNotFound:
         raise exception.ComputeNodeNotFound(name=name)
示例#9
0
    def create_compute_node(self, node_hostname):
        """Update the compute node by querying the Nova API."""
        try:
            _node = self.nova.get_compute_node_by_hostname(node_hostname)
            node = element.ComputeNode(
                id=_node.id,
                uuid=node_hostname,
                hostname=_node.hypervisor_hostname,
                state=_node.state,
                status=_node.status,
                memory=_node.memory_mb,
                vcpus=_node.vcpus,
                disk=_node.free_disk_gb,
                disk_capacity=_node.local_gb,
            )
            return node
        except Exception as exc:
            LOG.exception(exc)
            LOG.debug("Could not refresh the node %s.", node_hostname)
            raise exception.ComputeNodeNotFound(name=node_hostname)

        return False
示例#10
0
 def get_node_by_uuid(self, uuid):
     try:
         return self._get_by_uuid(uuid)
     except exception.ComputeResourceNotFound:
         raise exception.ComputeNodeNotFound(name=uuid)
示例#11
0
 def remove_node(self, node):
     self.assert_node(node)
     if str(node.uuid) not in self._nodes:
         raise exception.ComputeNodeNotFound(name=node.uuid)
     else:
         del self._nodes[node.uuid]
示例#12
0
 def get_node_by_uuid(self, node_uuid):
     if str(node_uuid) not in self._nodes:
         raise exception.ComputeNodeNotFound(name=node_uuid)
     return self._nodes[str(node_uuid)]