Synchronize resources with Ironic periodically
Change-Id: Ib5e8199fa1ae72d99b4c88259528c76b1156aabd
This commit is contained in:
parent
12fbb19bb3
commit
0bee14006b
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nimble.common import exception
|
||||
from nimble.common import ironic
|
||||
from nimble.engine.baremetal import ironic_states
|
||||
|
||||
@ -81,3 +82,19 @@ def destroy_node(node_uuid):
|
||||
ironicclient = ironic.IronicClientWrapper()
|
||||
ironicclient.call("node.set_provision_state", node_uuid,
|
||||
ironic_states.DELETED)
|
||||
|
||||
|
||||
def get_node_list(**kwargs):
|
||||
"""Helper function to return the list of nodes.
|
||||
|
||||
If unable to connect ironic server, an empty list is returned.
|
||||
|
||||
:returns: a list of raw node from ironic
|
||||
|
||||
"""
|
||||
ironicclient = ironic.IronicClientWrapper()
|
||||
try:
|
||||
node_list = ironicclient.call("node.list", **kwargs)
|
||||
except exception.NimbleException:
|
||||
node_list = []
|
||||
return node_list
|
||||
|
@ -32,6 +32,8 @@ class BaseEngineManager(periodic_task.PeriodicTasks):
|
||||
host = CONF.host
|
||||
self.host = host
|
||||
self.topic = topic
|
||||
self.node_cache = {}
|
||||
self.node_cache_time = 0
|
||||
self.notifier = rpc.get_notifier()
|
||||
self._started = False
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import time
|
||||
|
||||
from oslo_log import log
|
||||
import oslo_messaging as messaging
|
||||
from oslo_service import loopingcall
|
||||
@ -38,10 +40,21 @@ class EngineManager(base_manager.BaseEngineManager):
|
||||
|
||||
target = messaging.Target(version=RPC_API_VERSION)
|
||||
|
||||
def _refresh_cache(self):
|
||||
node_cache = {}
|
||||
nodes = ironic.get_node_list(detail=True, maintenance=False,
|
||||
provision_state=ironic_states.AVAILABLE,
|
||||
associated=False, limit=0)
|
||||
for node in nodes:
|
||||
node_cache[node.uuid] = node
|
||||
|
||||
self.node_cache = node_cache
|
||||
self.node_cache_time = time.time()
|
||||
|
||||
@periodic_task.periodic_task(
|
||||
spacing=CONF.engine.sync_node_resource_interval)
|
||||
def _sync_node_resources(self, context):
|
||||
LOG.info(_LI("During sync_node_resources."))
|
||||
self._refresh_cache()
|
||||
|
||||
def _build_networks(self, context, instance):
|
||||
macs = ironic.get_macs_from_node(instance.node_uuid)
|
||||
|
Loading…
Reference in New Issue
Block a user