Merge "Admin util for validating VC clusters"

This commit is contained in:
Zuul 2021-05-21 11:04:46 +00:00 committed by Gerrit Code Review
commit 1eb7ff6666
2 changed files with 38 additions and 1 deletions

View File

@ -12,10 +12,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import sys
from neutron_lib.callbacks import registry from neutron_lib.callbacks import registry
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_vmware import vim_util
from vmware_nsx.dvs import dvs
from vmware_nsx.plugins.nsx_v.vshield.common import exceptions from vmware_nsx.plugins.nsx_v.vshield.common import exceptions
from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin.plugins.common import constants
from vmware_nsx.shell.admin.plugins.common import utils as admin_utils from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
@ -39,6 +43,37 @@ def validate_configuration(resource, event, trigger, **kwargs):
LOG.info("Configuration validation succeeded") LOG.info("Configuration validation succeeded")
def check_clusters(resource, event, trigger, **kwargs):
clusters_str = ""
if kwargs.get('property'):
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
clusters_str = properties.get('clusters', None)
if not clusters_str:
LOG.error("No cluster to look for was specified")
return
clusters = clusters_str.split(",")
mgr = dvs.VCManagerBase()
session = mgr.get_vc_session()
data = session.invoke_api(vim_util, 'get_objects', session.vim,
'ClusterComputeResource', 100)
while data:
for item in data.objects:
if item.obj.value in clusters[:]:
clusters.remove(item.obj.value)
data = vim_util.continue_retrieval(session.vim, data)
if not clusters:
LOG.info("Clusters %s found on VC backend", clusters_str)
else:
LOG.error("Clusters %s not found on VC backend", ",".join(clusters))
sys.exit(1)
registry.subscribe(validate_configuration, registry.subscribe(validate_configuration,
constants.CONFIG, constants.CONFIG,
shell.Operations.VALIDATE.value) shell.Operations.VALIDATE.value)
registry.subscribe(check_clusters,
constants.CONFIG,
shell.Operations.CHECK_COMPUTE_CLUSTERS.value)

View File

@ -78,6 +78,7 @@ class Operations(enum.Enum):
UPDATE_TIER0 = 'update-tier0' UPDATE_TIER0 = 'update-tier0'
UPDATE_FIREWALL_MATCH = 'update-nat-firewall-match' UPDATE_FIREWALL_MATCH = 'update-nat-firewall-match'
SET_STATUS_ERROR = 'set-status-error' SET_STATUS_ERROR = 'set-status-error'
CHECK_COMPUTE_CLUSTERS = 'check-compute-clusters'
ops = [op.value for op in Operations] ops = [op.value for op in Operations]
@ -246,7 +247,8 @@ nsxv_resources = {
[Operations.NSX_LIST.value, [Operations.NSX_LIST.value,
Operations.NSX_CLEAN.value]), Operations.NSX_CLEAN.value]),
constants.CONFIG: Resource(constants.CONFIG, constants.CONFIG: Resource(constants.CONFIG,
[Operations.VALIDATE.value]), [Operations.VALIDATE.value,
Operations.CHECK_COMPUTE_CLUSTERS.value]),
constants.BGP_GW_EDGE: Resource(constants.BGP_GW_EDGE, constants.BGP_GW_EDGE: Resource(constants.BGP_GW_EDGE,
[Operations.CREATE.value, [Operations.CREATE.value,
Operations.DELETE.value, Operations.DELETE.value,