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>
This commit is contained in:
parent
9c271569d6
commit
9ececd7623
@ -1,15 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2018 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# Host Aggregate Constants
|
||||
|
||||
# Storage: Host Aggregates Groups
|
||||
HOST_AGG_NAME_REMOTE = 'remote_storage_hosts'
|
||||
HOST_AGG_META_REMOTE = 'remote'
|
||||
HOST_AGG_NAME_LOCAL_LVM = 'local_storage_lvm_hosts'
|
||||
HOST_AGG_META_LOCAL_LVM = 'local_lvm'
|
||||
HOST_AGG_NAME_LOCAL_IMAGE = 'local_storage_image_hosts'
|
||||
HOST_AGG_META_LOCAL_IMAGE = 'local_image'
|
@ -15,8 +15,6 @@ from cinderclient.v2 import client as cinder_client_v2
|
||||
from inventory.common import constants
|
||||
from inventory.common import exception
|
||||
from inventory.common.i18n import _
|
||||
from inventory.common import k_host
|
||||
from inventory.common import k_host_agg
|
||||
from inventory.common.storage_backend_conf import StorageBackendConfig
|
||||
from keystoneclient.auth.identity import v3
|
||||
from keystoneclient import exceptions as identity_exc
|
||||
@ -24,7 +22,6 @@ from keystoneclient import session
|
||||
from keystoneclient.v3 import client as keystone_client
|
||||
from neutronclient.v2_0 import client as neutron_client_v2_0
|
||||
from novaclient.v2 import client as nova_client_v2
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from sqlalchemy.orm import exc
|
||||
@ -259,158 +256,6 @@ class OpenStackOperator(object):
|
||||
|
||||
return interfaces
|
||||
|
||||
@lockutils.synchronized('update_nova_local_aggregates', 'inventory-')
|
||||
def update_nova_local_aggregates(self, ihost_uuid, aggregates=None):
|
||||
"""
|
||||
Update nova_local aggregates for a host
|
||||
"""
|
||||
availability_zone = None
|
||||
|
||||
if not aggregates:
|
||||
try:
|
||||
aggregates = self._get_novaclient().aggregates.list()
|
||||
except Exception:
|
||||
self.nova_client = None # password may have updated
|
||||
aggregates = self._get_novaclient().aggregates.list()
|
||||
|
||||
nova_aggset_provider = set()
|
||||
for aggregate in aggregates:
|
||||
nova_aggset_provider.add(aggregate.name)
|
||||
|
||||
aggset_storage = set([
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
|
||||
k_host_agg.HOST_AGG_NAME_REMOTE])
|
||||
agglist_missing = list(aggset_storage - nova_aggset_provider)
|
||||
LOG.debug("AGG Storage agglist_missing = %s." % agglist_missing)
|
||||
|
||||
# Only add the ones that don't exist
|
||||
for agg_name in agglist_missing:
|
||||
# Create the aggregate
|
||||
try:
|
||||
aggregate = self._get_novaclient().aggregates.create(
|
||||
agg_name, availability_zone)
|
||||
LOG.info("AGG-AS Storage aggregate= %s created. " % (
|
||||
aggregate))
|
||||
except Exception:
|
||||
LOG.error("AGG-AS EXCEPTION Storage aggregate "
|
||||
"agg_name=%s not created" % (agg_name))
|
||||
raise
|
||||
|
||||
# Add the metadata
|
||||
try:
|
||||
if agg_name == k_host_agg.HOST_AGG_NAME_LOCAL_LVM:
|
||||
metadata = {'storage': k_host_agg.HOST_AGG_META_LOCAL_LVM}
|
||||
elif agg_name == k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE:
|
||||
metadata = \
|
||||
{'storage': k_host_agg.HOST_AGG_META_LOCAL_IMAGE}
|
||||
else:
|
||||
metadata = {'storage': k_host_agg.HOST_AGG_META_REMOTE}
|
||||
LOG.debug("AGG-AS storage aggregate metadata = %s." % metadata)
|
||||
aggregate = self._get_novaclient().aggregates.set_metadata(
|
||||
aggregate.id, metadata)
|
||||
except Exception:
|
||||
LOG.error("AGG-AS EXCEPTION Storage aggregate "
|
||||
"=%s metadata not added" % aggregate)
|
||||
raise
|
||||
|
||||
# refresh the aggregate list
|
||||
try:
|
||||
aggregates = dict([(agg.name, agg) for agg in
|
||||
self._get_novaclient().aggregates.list()])
|
||||
except Exception:
|
||||
self.nova_client = None # password may have updated
|
||||
aggregates = dict([(agg.name, agg) for agg in
|
||||
self._get_novaclient().aggregates.list()])
|
||||
|
||||
# Add the host to the local or remote aggregate group
|
||||
# determine if this host is configured for local storage
|
||||
host_has_lvg = False
|
||||
lvg_backing = False
|
||||
try:
|
||||
ilvgs = self.dbapi.ilvg_get_by_ihost(ihost_uuid)
|
||||
for lvg in ilvgs:
|
||||
if lvg.lvm_vg_name == constants.LVG_NOVA_LOCAL and \
|
||||
lvg.vg_state == k_host.PROVISIONED:
|
||||
host_has_lvg = True
|
||||
lvg_backing = lvg.capabilities.get(
|
||||
constants.LVG_NOVA_PARAM_BACKING)
|
||||
break
|
||||
else:
|
||||
LOG.debug("AGG-AS Found LVG %s with state %s "
|
||||
"for host %s." % (
|
||||
lvg.lvm_vg_name,
|
||||
lvg.vg_state,
|
||||
ihost_uuid))
|
||||
except Exception:
|
||||
LOG.error("AGG-AS ilvg_get_by_ihost failed "
|
||||
"for %s." % ihost_uuid)
|
||||
raise
|
||||
|
||||
LOG.debug("AGG-AS ihost (%s) %s in a local storage configuration." %
|
||||
(ihost_uuid,
|
||||
"is not"
|
||||
if (lvg_backing == constants.LVG_NOVA_BACKING_REMOTE) else
|
||||
"is"))
|
||||
|
||||
# Select the appropriate aggregate id based on the presence of an LVG
|
||||
#
|
||||
agg_add_to = ""
|
||||
if host_has_lvg:
|
||||
agg_add_to = {
|
||||
constants.LVG_NOVA_BACKING_IMAGE:
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
|
||||
constants.LVG_NOVA_BACKING_LVM:
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
|
||||
constants.LVG_NOVA_BACKING_REMOTE:
|
||||
k_host_agg.HOST_AGG_NAME_REMOTE
|
||||
}.get(lvg_backing)
|
||||
|
||||
if not agg_add_to:
|
||||
LOG.error("The nova-local LVG for host: %s has an invalid "
|
||||
"instance backing: " % (ihost_uuid, agg_add_to))
|
||||
|
||||
ihost = self.dbapi.ihost_get(ihost_uuid)
|
||||
for aggregate in aggregates.values():
|
||||
if aggregate.name not in aggset_storage \
|
||||
or aggregate.name == agg_add_to:
|
||||
continue
|
||||
if hasattr(aggregate, 'hosts') \
|
||||
and ihost.hostname in aggregate.hosts:
|
||||
try:
|
||||
self._get_novaclient().aggregates.remove_host(
|
||||
aggregate.id,
|
||||
ihost.hostname)
|
||||
LOG.info("AGG-AS remove ihost = %s from aggregate = %s." %
|
||||
(ihost.hostname, aggregate.name))
|
||||
except Exception:
|
||||
LOG.error(("AGG-AS EXCEPTION remove ihost= %s "
|
||||
"from aggregate = %s.") % (
|
||||
ihost.hostname,
|
||||
aggregate.name))
|
||||
raise
|
||||
else:
|
||||
LOG.info("skip removing host=%s not in storage "
|
||||
"aggregate id=%s" % (
|
||||
ihost.hostname,
|
||||
aggregate))
|
||||
if hasattr(aggregates[agg_add_to], 'hosts') \
|
||||
and ihost.hostname in aggregates[agg_add_to].hosts:
|
||||
LOG.info(("skip adding host=%s already in storage "
|
||||
"aggregate id=%s") % (
|
||||
ihost.hostname,
|
||||
agg_add_to))
|
||||
else:
|
||||
try:
|
||||
self._get_novaclient().aggregates.add_host(
|
||||
aggregates[agg_add_to].id, ihost.hostname)
|
||||
LOG.info("AGG-AS add ihost = %s to aggregate = %s." % (
|
||||
ihost.hostname, agg_add_to))
|
||||
except Exception:
|
||||
LOG.error("AGG-AS EXCEPTION add ihost= %s to aggregate = %s." %
|
||||
(ihost.hostname, agg_add_to))
|
||||
raise
|
||||
|
||||
def nova_host_available(self, ihost_uuid):
|
||||
"""
|
||||
Perform inventory driven nova operations for an available ihost
|
||||
@ -623,12 +468,6 @@ class OpenStackOperator(object):
|
||||
else:
|
||||
LOG.debug("AGG ihost_providernets empty %s." % ihost_uuid)
|
||||
|
||||
# setup the valid set of storage aggregates for host removal
|
||||
aggset_storage = set([
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_LVM,
|
||||
k_host_agg.HOST_AGG_NAME_LOCAL_IMAGE,
|
||||
k_host_agg.HOST_AGG_NAME_REMOTE])
|
||||
|
||||
# Remove aggregates from provider network. Anything with host in list.
|
||||
# 4. nova aggregate-remove-host provider_physnet0 compute-0
|
||||
# cs.aggregates.remove_host(aggregate.id, args.host)
|
||||
@ -636,16 +475,14 @@ class OpenStackOperator(object):
|
||||
ihost = self.dbapi.ihost_get(ihost_uuid)
|
||||
|
||||
for aggregate in aggregates:
|
||||
if aggregate.name in ihost_providernets or \
|
||||
aggregate.name in aggset_storage: # or just do it for all aggs
|
||||
try:
|
||||
LOG.debug("AGG10 remove aggregate id = %s ihost= %s." %
|
||||
(aggregate.id, ihost.hostname))
|
||||
self._get_novaclient().aggregates.remove_host(
|
||||
aggregate.id, ihost.hostname)
|
||||
except Exception:
|
||||
LOG.debug("AGG10 EXCEPTION remove aggregate")
|
||||
pass
|
||||
try:
|
||||
LOG.debug("AGG10 remove aggregate id = %s ihost= %s." %
|
||||
(aggregate.id, ihost.hostname))
|
||||
self._get_novaclient().aggregates.remove_host(
|
||||
aggregate.id, ihost.hostname)
|
||||
except Exception:
|
||||
LOG.debug("AGG10 EXCEPTION remove aggregate")
|
||||
pass
|
||||
|
||||
return True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user