From 770c5eda5f8199b0f1567bcd1d570097073f7833 Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Thu, 5 Dec 2019 01:11:19 +0530 Subject: [PATCH] [RFR] Add _fill_vmrc_console_endpoint_dicts to provider.create_rest() (#9701) * Add _fill_vmrc_console_endpoint_dicts * Add VMRCEndpoint Co-authored-by: Parthvi Vala Co-authored-by: Kedar Kulkarni --- cfme/common/provider.py | 34 +++++++++++++++++-- cfme/infrastructure/provider/virtualcenter.py | 12 +++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cfme/common/provider.py b/cfme/common/provider.py index 921f9d0592..aeefbd1dfb 100644 --- a/cfme/common/provider.py +++ b/cfme/common/provider.py @@ -415,7 +415,7 @@ def _fill_amqp_endpoint_dicts(self, provider_attributes, connection_configs): events_connection["endpoint"]["security_protocol"] = security_protocol connection_configs.append(events_connection) - def _fill_smartstate_endpoint_dicts(self, provider_attributes, connection_configs): + def _fill_smartstate_endpoint_dicts(self, provider_attributes): """Fills dicts with smartstate endpoint data. Helper method for ``self.create_rest`` @@ -433,6 +433,26 @@ def _fill_smartstate_endpoint_dicts(self, provider_attributes, connection_config "auth_type": "smartstate_docker", }) + def _fill_vmrc_console_endpoint_dicts(self, provider_attributes): + """Fills dicts with VMRC console endpoint data + + Helper method for ``self.create_rest`` + """ + if "vmrc" not in self.endpoints: + return + + endpoints_vmrc = self.endpoints["vmrc"] + if isinstance(provider_attributes["credentials"], dict): + provider_attributes["credentials"] = [provider_attributes["credentials"]] + + provider_attributes["credentials"].append( + { + "auth_type": "console", + "userid": endpoints_vmrc.credentials.principal, + "password": endpoints_vmrc.credentials.secret, + } + ) + def _compile_connection_configurations(self, provider_attributes, connection_configs): """Compiles together all dicts with data for ``connection_configurations``. @@ -480,7 +500,8 @@ def create_rest(self, check_existing=False, validate_inventory=False): self._fill_candu_endpoint_dicts(provider_attributes, connection_configs) self._fill_rsa_endpoint_dicts(connection_configs) self._fill_amqp_endpoint_dicts(provider_attributes, connection_configs) - self._fill_smartstate_endpoint_dicts(provider_attributes, connection_configs) + self._fill_smartstate_endpoint_dicts(provider_attributes) + self._fill_vmrc_console_endpoint_dicts(provider_attributes) self._compile_connection_configurations(provider_attributes, connection_configs) try: @@ -1267,6 +1288,15 @@ def view_value_mapping(self): return {} +class VMRCEndpoint(DefaultEndpoint): + credential_class = Credential + name = 'vmrc' + + @property + def view_value_mapping(self): + return {} + + class DefaultEndpointForm(View): hostname = Input('default_hostname') username = Input('default_userid') diff --git a/cfme/infrastructure/provider/virtualcenter.py b/cfme/infrastructure/provider/virtualcenter.py index 65fd18fe56..aca40727a8 100644 --- a/cfme/infrastructure/provider/virtualcenter.py +++ b/cfme/infrastructure/provider/virtualcenter.py @@ -5,6 +5,7 @@ from cfme.common.candu_views import VMUtilizationView from cfme.common.provider import DefaultEndpoint from cfme.common.provider import DefaultEndpointForm +from cfme.common.provider import VMRCEndpoint from cfme.exceptions import ItemNotFound from cfme.infrastructure.provider import InfraProvider from cfme.services.catalogs.catalog_items import VMwareCatalogItem @@ -69,17 +70,24 @@ def deployment_helper(self, deploy_args): @classmethod def from_config(cls, prov_config, prov_key, appliance=None): appliance = appliance or cls.appliance - endpoint = VirtualCenterEndpoint(**prov_config['endpoints']['default']) + endpoints = { + VirtualCenterEndpoint.name: VirtualCenterEndpoint(**prov_config['endpoints']['default']) + } + + vmrc_endpoint_config = prov_config["endpoints"].get(VMRCEndpoint.name, {}) + if vmrc_endpoint_config: + endpoints[VMRCEndpoint.name] = VMRCEndpoint(**vmrc_endpoint_config) if prov_config.get('discovery_range'): start_ip = prov_config['discovery_range']['start'] end_ip = prov_config['discovery_range']['end'] else: start_ip = end_ip = prov_config.get('ipaddress') + return appliance.collections.infra_providers.instantiate( prov_class=cls, name=prov_config['name'], - endpoints={endpoint.name: endpoint}, + endpoints=endpoints, zone=prov_config['server_zone'], key=prov_key, start_ip=start_ip,