summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Ding <jack.ding@windriver.com>2019-01-15 08:52:20 -0500
committerJack Ding <jack.ding@windriver.com>2019-01-25 09:56:09 -0500
commit9ececd76235baf59d400b518e9323a91c4b681eb (patch)
tree25dddd24cd8b67751bc8670c2cfc1ccf4d1093f6
parent9c271569d60fe71c887d023ac9bffbe01ad7d75c (diff)
Remove nova storage aggregates
Remove the automated creation of storage host aggregates and host population in inventory. Story: 2004607 Task: 29068 Change-Id: I4a74a1ee1f8b3bc8dc6293a5c971d9c7ed1442b5 Signed-off-by: Jack Ding <jack.ding@windriver.com>
Notes
Notes (review): Code-Review+2: John Kung <john.kung@windriver.com> Code-Review+2: Tao Liu <tao.liu@windriver.com> Workflow+1: Tao Liu <tao.liu@windriver.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 25 Jan 2019 22:25:37 +0000 Reviewed-on: https://review.openstack.org/633198 Project: openstack/stx-metal Branch: refs/heads/master
-rw-r--r--inventory/inventory/inventory/common/k_host_agg.py15
-rw-r--r--inventory/inventory/inventory/conductor/openstack.py179
2 files changed, 8 insertions, 186 deletions
diff --git a/inventory/inventory/inventory/common/k_host_agg.py b/inventory/inventory/inventory/common/k_host_agg.py
deleted file mode 100644
index cc019eb..0000000
--- a/inventory/inventory/inventory/common/k_host_agg.py
+++ /dev/null
@@ -1,15 +0,0 @@
1#
2# Copyright (c) 2018 Wind River Systems, Inc.
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6
7# Host Aggregate Constants
8
9# Storage: Host Aggregates Groups
10HOST_AGG_NAME_REMOTE = 'remote_storage_hosts'
11HOST_AGG_META_REMOTE = 'remote'
12HOST_AGG_NAME_LOCAL_LVM = 'local_storage_lvm_hosts'
13HOST_AGG_META_LOCAL_LVM = 'local_lvm'
14HOST_AGG_NAME_LOCAL_IMAGE = 'local_storage_image_hosts'
15HOST_AGG_META_LOCAL_IMAGE = 'local_image'
diff --git a/inventory/inventory/inventory/conductor/openstack.py b/inventory/inventory/inventory/conductor/openstack.py
index 399db0d..b517dde 100644
--- a/inventory/inventory/inventory/conductor/openstack.py
+++ b/inventory/inventory/inventory/conductor/openstack.py
@@ -15,8 +15,6 @@ from cinderclient.v2 import client as cinder_client_v2
15from inventory.common import constants 15from inventory.common import constants
16from inventory.common import exception 16from inventory.common import exception
17from inventory.common.i18n import _ 17from inventory.common.i18n import _
18from inventory.common import k_host
19from inventory.common import k_host_agg
20from inventory.common.storage_backend_conf import StorageBackendConfig 18from inventory.common.storage_backend_conf import StorageBackendConfig
21from keystoneclient.auth.identity import v3 19from keystoneclient.auth.identity import v3
22from keystoneclient import exceptions as identity_exc 20from keystoneclient import exceptions as identity_exc
@@ -24,7 +22,6 @@ from keystoneclient import session
24from keystoneclient.v3 import client as keystone_client 22from keystoneclient.v3 import client as keystone_client
25from neutronclient.v2_0 import client as neutron_client_v2_0 23from neutronclient.v2_0 import client as neutron_client_v2_0
26from novaclient.v2 import client as nova_client_v2 24from novaclient.v2 import client as nova_client_v2
27from oslo_concurrency import lockutils
28from oslo_config import cfg 25from oslo_config import cfg
29from oslo_log import log 26from oslo_log import log
30from sqlalchemy.orm import exc 27from sqlalchemy.orm import exc
@@ -259,158 +256,6 @@ class OpenStackOperator(object):
259 256
260 return interfaces 257 return interfaces
261 258
262 @lockutils.synchronized('update_nova_local_aggregates', 'inventory-')
263 def update_nova_local_aggregates(self, ihost_uuid, aggregates=None):
264 """
265 Update nova_local aggregates for a host
266 """
267 availability_zone = None
268
269 if not aggregates:
270 try:
271 aggregates = self._get_novaclient().aggregates.list()
272 except Exception:
273 self.nova_client = None # password may have updated
274 aggregates = self._get_novaclient().aggregates.list()
275
276 nova_aggset_provider = set()
277 for aggregate in aggregates:
278 nova_aggset_provider.add(aggregate.name)
279
280 aggset_storage = set([
281 k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
282 k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
283 k_host_agg.HOST_AGG_NAME_REMOTE])
284 agglist_missing = list(aggset_storage - nova_aggset_provider)
285 LOG.debug("AGG Storage agglist_missing = %s." % agglist_missing)
286
287 # Only add the ones that don't exist
288 for agg_name in agglist_missing:
289 # Create the aggregate
290 try:
291 aggregate = self._get_novaclient().aggregates.create(
292 agg_name, availability_zone)
293 LOG.info("AGG-AS Storage aggregate= %s created. " % (
294 aggregate))
295 except Exception:
296 LOG.error("AGG-AS EXCEPTION Storage aggregate "
297 "agg_name=%s not created" % (agg_name))
298 raise
299
300 # Add the metadata
301 try:
302 if agg_name == k_host_agg.HOST_AGG_NAME_LOCAL_LVM:
303 metadata = {'storage': k_host_agg.HOST_AGG_META_LOCAL_LVM}
304 elif agg_name == k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE:
305 metadata = \
306 {'storage': k_host_agg.HOST_AGG_META_LOCAL_IMAGE}
307 else:
308 metadata = {'storage': k_host_agg.HOST_AGG_META_REMOTE}
309 LOG.debug("AGG-AS storage aggregate metadata = %s." % metadata)
310 aggregate = self._get_novaclient().aggregates.set_metadata(
311 aggregate.id, metadata)
312 except Exception:
313 LOG.error("AGG-AS EXCEPTION Storage aggregate "
314 "=%s metadata not added" % aggregate)
315 raise
316
317 # refresh the aggregate list
318 try:
319 aggregates = dict([(agg.name, agg) for agg in
320 self._get_novaclient().aggregates.list()])
321 except Exception:
322 self.nova_client = None # password may have updated
323 aggregates = dict([(agg.name, agg) for agg in
324 self._get_novaclient().aggregates.list()])
325
326 # Add the host to the local or remote aggregate group
327 # determine if this host is configured for local storage
328 host_has_lvg = False
329 lvg_backing = False
330 try:
331 ilvgs = self.dbapi.ilvg_get_by_ihost(ihost_uuid)
332 for lvg in ilvgs:
333 if lvg.lvm_vg_name == constants.LVG_NOVA_LOCAL and \
334 lvg.vg_state == k_host.PROVISIONED:
335 host_has_lvg = True
336 lvg_backing = lvg.capabilities.get(
337 constants.LVG_NOVA_PARAM_BACKING)
338 break
339 else:
340 LOG.debug("AGG-AS Found LVG %s with state %s "
341 "for host %s." % (
342 lvg.lvm_vg_name,
343 lvg.vg_state,
344 ihost_uuid))
345 except Exception:
346 LOG.error("AGG-AS ilvg_get_by_ihost failed "
347 "for %s." % ihost_uuid)
348 raise
349
350 LOG.debug("AGG-AS ihost (%s) %s in a local storage configuration." %
351 (ihost_uuid,
352 "is not"
353 if (lvg_backing == constants.LVG_NOVA_BACKING_REMOTE) else
354 "is"))
355
356 # Select the appropriate aggregate id based on the presence of an LVG
357 #
358 agg_add_to = ""
359 if host_has_lvg:
360 agg_add_to = {
361 constants.LVG_NOVA_BACKING_IMAGE:
362 k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
363 constants.LVG_NOVA_BACKING_LVM:
364 k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
365 constants.LVG_NOVA_BACKING_REMOTE:
366 k_host_agg.HOST_AGG_NAME_REMOTE
367 }.get(lvg_backing)
368
369 if not agg_add_to:
370 LOG.error("The nova-local LVG for host: %s has an invalid "
371 "instance backing: " % (ihost_uuid, agg_add_to))
372
373 ihost = self.dbapi.ihost_get(ihost_uuid)
374 for aggregate in aggregates.values():
375 if aggregate.name not in aggset_storage \
376 or aggregate.name == agg_add_to:
377 continue
378 if hasattr(aggregate, 'hosts') \
379 and ihost.hostname in aggregate.hosts:
380 try:
381 self._get_novaclient().aggregates.remove_host(
382 aggregate.id,
383 ihost.hostname)
384 LOG.info("AGG-AS remove ihost = %s from aggregate = %s." %
385 (ihost.hostname, aggregate.name))
386 except Exception:
387 LOG.error(("AGG-AS EXCEPTION remove ihost= %s "
388 "from aggregate = %s.") % (
389 ihost.hostname,
390 aggregate.name))
391 raise
392 else:
393 LOG.info("skip removing host=%s not in storage "
394 "aggregate id=%s" % (
395 ihost.hostname,
396 aggregate))
397 if hasattr(aggregates[agg_add_to], 'hosts') \
398 and ihost.hostname in aggregates[agg_add_to].hosts:
399 LOG.info(("skip adding host=%s already in storage "
400 "aggregate id=%s") % (
401 ihost.hostname,
402 agg_add_to))
403 else:
404 try:
405 self._get_novaclient().aggregates.add_host(
406 aggregates[agg_add_to].id, ihost.hostname)
407 LOG.info("AGG-AS add ihost = %s to aggregate = %s." % (
408 ihost.hostname, agg_add_to))
409 except Exception:
410 LOG.error("AGG-AS EXCEPTION add ihost= %s to aggregate = %s." %
411 (ihost.hostname, agg_add_to))
412 raise
413
414 def nova_host_available(self, ihost_uuid): 259 def nova_host_available(self, ihost_uuid):
415 """ 260 """
416 Perform inventory driven nova operations for an available ihost 261 Perform inventory driven nova operations for an available ihost
@@ -623,12 +468,6 @@ class OpenStackOperator(object):
623 else: 468 else:
624 LOG.debug("AGG ihost_providernets empty %s." % ihost_uuid) 469 LOG.debug("AGG ihost_providernets empty %s." % ihost_uuid)
625 470
626 # setup the valid set of storage aggregates for host removal
627 aggset_storage = set([
628 k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
629 k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
630 k_host_agg.HOST_AGG_NAME_REMOTE])
631
632 # Remove aggregates from provider network. Anything with host in list. 471 # Remove aggregates from provider network. Anything with host in list.
633 # 4. nova aggregate-remove-host provider_physnet0 compute-0 472 # 4. nova aggregate-remove-host provider_physnet0 compute-0
634 # cs.aggregates.remove_host(aggregate.id, args.host) 473 # cs.aggregates.remove_host(aggregate.id, args.host)
@@ -636,16 +475,14 @@ class OpenStackOperator(object):
636 ihost = self.dbapi.ihost_get(ihost_uuid) 475 ihost = self.dbapi.ihost_get(ihost_uuid)
637 476
638 for aggregate in aggregates: 477 for aggregate in aggregates:
639 if aggregate.name in ihost_providernets or \ 478 try:
640 aggregate.name in aggset_storage: # or just do it for all aggs 479 LOG.debug("AGG10 remove aggregate id = %s ihost= %s." %
641 try: 480 (aggregate.id, ihost.hostname))
642 LOG.debug("AGG10 remove aggregate id = %s ihost= %s." % 481 self._get_novaclient().aggregates.remove_host(
643 (aggregate.id, ihost.hostname)) 482 aggregate.id, ihost.hostname)
644 self._get_novaclient().aggregates.remove_host( 483 except Exception:
645 aggregate.id, ihost.hostname) 484 LOG.debug("AGG10 EXCEPTION remove aggregate")
646 except Exception: 485 pass
647 LOG.debug("AGG10 EXCEPTION remove aggregate")
648 pass
649 486
650 return True 487 return True
651 488