Merge "Add get_available_resources driver method"

This commit is contained in:
Jenkins 2017-03-14 15:06:00 +00:00 committed by Gerrit Code Review
commit f9d5d2ec76
3 changed files with 31 additions and 68 deletions

View File

@ -35,9 +35,10 @@ class BaseEngineDriver(object):
"""Add init staff here.
"""
def get_available_node_list(self):
"""Return all available nodes.
def get_available_resources(self):
"""Retrieve resource information.
:returns: Dictionary describing resources
"""
raise NotImplementedError()
@ -53,16 +54,6 @@ class BaseEngineDriver(object):
"""
raise NotImplementedError()
def get_port_list(self):
"""Return all ports.
"""
raise NotImplementedError()
def get_portgroup_list(self):
"""Return all portgroups.
"""
raise NotImplementedError()
def get_power_state(self, context, instance_uuid):
"""Return a node's power state by passing instance uuid.

View File

@ -345,14 +345,16 @@ class IronicDriver(base_driver.BaseEngineDriver):
LOG.info(_LI('Successfully unprovisioned Ironic node %s'),
node.uuid, instance=instance)
def get_available_node_list(self):
"""Helper function to return the list of nodes.
def get_available_resources(self):
"""Helper function to return the list of resources.
If unable to connect ironic server, an empty list is returned.
:returns: a list of raw node from ironic
"""
# Retrieve nodes
params = {
'maintenance': False,
'detail': True,
@ -366,7 +368,28 @@ class IronicDriver(base_driver.BaseEngineDriver):
LOG.exception(_LE("Could not get nodes from ironic. Reason: "
"%(detail)s"), {'detail': e.message})
node_list = []
return node_list
# Retrive ports
params = {
'limit': 0,
'fields': ('uuid', 'node_uuid', 'extra', 'address')
}
try:
port_list = self.ironicclient.call("port.list", **params)
except client_e.ClientException as e:
LOG.exception(_LE("Could not get ports from ironic. Reason: "
"%(detail)s"), {'detail': e.message})
port_list = []
# TODO(zhenguo): Add portgroups resources
node_resources = {}
for node in node_list:
# Add ports to the associated node
node.ports = [port for port in port_list
if node.uuid == port.node_uuid]
node_resources[node.uuid] = node
return node_resources
def get_maintenance_node_list(self):
"""Helper function to return the list of maintenance nodes.
@ -411,48 +434,6 @@ class IronicDriver(base_driver.BaseEngineDriver):
node_list = []
return node_list
def get_port_list(self):
"""Helper function to return the list of ports.
If unable to connect ironic server, an empty list is returned.
:returns: a list of raw port from ironic
"""
params = {
'limit': 0,
'fields': ('uuid', 'node_uuid', 'extra', 'address')
}
try:
port_list = self.ironicclient.call("port.list", **params)
except client_e.ClientException as e:
LOG.exception(_LE("Could not get ports from ironic. Reason: "
"%(detail)s"), {'detail': e.message})
port_list = []
return port_list
def get_portgroup_list(self, **kwargs):
"""Helper function to return the list of portgroups.
If unable to connect ironic server, an empty list is returned.
:returns: a list of raw port from ironic
"""
params = {
'limit': 0,
'fields': ('uuid', 'node_uuid', 'extra', 'address')
}
try:
portgroup_list = self.ironicclient.call("portgroup.list", **params)
except client_e.ClientException as e:
LOG.exception(_LE("Could not get portgroups from ironic. Reason: "
"%(detail)s"), {'detail': e.message})
portgroup_list = []
return portgroup_list
def get_power_state(self, context, instance_uuid):
try:
node = self.ironicclient.call('node.get_by_instance_uuid',

View File

@ -48,19 +48,10 @@ class EngineManager(base_manager.BaseEngineManager):
_lock = threading.Lock()
def _refresh_cache(self):
node_cache = {}
nodes = self.driver.get_available_node_list()
ports = self.driver.get_port_list()
portgroups = self.driver.get_portgroup_list()
ports += portgroups
for node in nodes:
# Add ports to the associated node
node.ports = [port for port in ports
if node.uuid == port.node_uuid]
node_cache[node.uuid] = node
nodes = self.driver.get_available_resources()
with self._lock:
self.node_cache = node_cache
self.node_cache = nodes
@periodic_task.periodic_task(
spacing=CONF.engine.sync_node_resource_interval,