diff --git a/distributedcloud-client/dcmanagerclient/api/v1/subcloud_manager.py b/distributedcloud-client/dcmanagerclient/api/v1/subcloud_manager.py index 3848c6a..fd73938 100644 --- a/distributedcloud-client/dcmanagerclient/api/v1/subcloud_manager.py +++ b/distributedcloud-client/dcmanagerclient/api/v1/subcloud_manager.py @@ -60,36 +60,6 @@ class subcloud_manager(base.ResourceManager): resource.append(self.json_to_resource(json_object)) return resource - def subcloud_reconfigure(self, url, body, data): - fields = dict() - for k, v in body.items(): - fields.update({k: (v, open(v, 'rb'),)}) - fields.update(data) - enc = MultipartEncoder(fields=fields) - headers = {'content-type': enc.content_type} - resp = self.http_client.patch(url, enc, headers=headers) - if resp.status_code != 200: - self._raise_api_exception(resp) - json_object = get_json(resp) - resource = list() - resource.append(self.json_to_resource(json_object)) - return resource - - def subcloud_reinstall(self, url, body, data): - fields = dict() - for k, v in body.items(): - fields.update({k: (v, open(v, 'rb'),)}) - fields.update(data) - enc = MultipartEncoder(fields=fields) - headers = {'content-type': enc.content_type} - resp = self.http_client.patch(url, enc, headers=headers) - if resp.status_code != 200: - self._raise_api_exception(resp) - json_object = get_json(resp) - resource = list() - resource.append(self.json_to_resource(json_object)) - return resource - def subcloud_redeploy(self, url, body, data): fields = dict() for k, v in body.items(): @@ -183,18 +153,6 @@ class subcloud_manager(base.ResourceManager): url = '/subclouds/%s' % subcloud_ref return self.subcloud_update(url, files, data) - def reconfigure_subcloud(self, subcloud_ref, **kwargs): - files = kwargs.get('files') - data = kwargs.get('data') - url = '/subclouds/%s/reconfigure' % subcloud_ref - return self.subcloud_reconfigure(url, files, data) - - def reinstall_subcloud(self, subcloud_ref, **kwargs): - files = kwargs.get('files') - data = kwargs.get('data') - url = '/subclouds/%s/reinstall' % subcloud_ref - return self.subcloud_reinstall(url, files, data) - def redeploy_subcloud(self, subcloud_ref, **kwargs): files = kwargs.get('files') data = kwargs.get('data') diff --git a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py index 6b9a10f..9fb8edb 100644 --- a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py +++ b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_manager.py @@ -644,60 +644,10 @@ class ReconfigSubcloud(base.DCManagerShowOne): def _get_format_function(self): return detail_format - def get_parser(self, prog_name): - parser = super(ReconfigSubcloud, self).get_parser(prog_name) - - parser.add_argument( - 'subcloud', - help='Name or ID of the subcloud to update.' - ) - - parser.add_argument( - '--deploy-config', - required=True, - help='YAML file containing parameters required for the initial ' - 'configuration and unlock of the subcloud.' - ) - - parser.add_argument( - '--sysadmin-password', - required=False, - help='sysadmin password of the subcloud to be configured, ' - 'if not provided you will be prompted.' - ) - - return parser - def _get_resources(self, parsed_args): - subcloud_ref = parsed_args.subcloud - dcmanager_client = self.app.client_manager.subcloud_manager - files = dict() - data = dict() - - # Get the deploy config yaml file - if parsed_args.deploy_config is not None: - if not os.path.isfile(parsed_args.deploy_config): - error_msg = "deploy-config file does not exist: %s" % \ - parsed_args.deploy_config - raise exceptions.DCManagerClientException(error_msg) - files['deploy_config'] = parsed_args.deploy_config - - # Prompt the user for the subcloud's password if it isn't provided - if parsed_args.sysadmin_password is not None: - data['sysadmin_password'] = base64.b64encode( - parsed_args.sysadmin_password.encode("utf-8")) - else: - password = utils.prompt_for_password() - data["sysadmin_password"] = base64.b64encode( - password.encode("utf-8")) - - try: - return dcmanager_client.subcloud_manager.reconfigure_subcloud( - subcloud_ref=subcloud_ref, files=files, data=data) - except Exception as e: - print(e) - error_msg = "Unable to reconfigure subcloud %s" % (subcloud_ref) - raise exceptions.DCManagerClientException(error_msg) + deprecation_msg = ("This command has been deprecated. Please use " + "'subcloud deploy config' instead.") + raise exceptions.DCManagerClientException(deprecation_msg) class ReinstallSubcloud(base.DCManagerShowOne): @@ -706,93 +656,10 @@ class ReinstallSubcloud(base.DCManagerShowOne): def _get_format_function(self): return detail_format - def get_parser(self, prog_name): - parser = super(ReinstallSubcloud, self).get_parser(prog_name) - - parser.add_argument( - 'subcloud', - help='Name or ID of the subcloud to reinstall.' - ) - - parser.add_argument( - '--bootstrap-values', - required=True, - help='YAML file containing parameters required for the bootstrap ' - 'of the subcloud.' - ) - - parser.add_argument( - '--deploy-config', - required=False, - help='YAML file containing parameters required for the initial ' - 'configuration and unlock of the subcloud.' - ) - - parser.add_argument( - '--sysadmin-password', - required=False, - help='sysadmin password of the subcloud to be configured, ' - 'if not provided you will be prompted.' - ) - - parser.add_argument( - '--release', - required=False, - help='software release used to install, bootstrap and/or deploy ' - 'the subcloud with. If not specified, the current software ' - 'release of the system controller will be used.' - ) - return parser - def _get_resources(self, parsed_args): - subcloud_ref = parsed_args.subcloud - dcmanager_client = self.app.client_manager.subcloud_manager - files = dict() - data = dict() - - # Get the bootstrap values yaml file - if not os.path.isfile(parsed_args.bootstrap_values): - error_msg = "bootstrap-values does not exist: %s" % \ - parsed_args.bootstrap_values - raise exceptions.DCManagerClientException(error_msg) - files['bootstrap_values'] = parsed_args.bootstrap_values - - # Get the deploy config yaml file - if parsed_args.deploy_config is not None: - if not os.path.isfile(parsed_args.deploy_config): - error_msg = "deploy-config does not exist: %s" % \ - parsed_args.deploy_config - raise exceptions.DCManagerClientException(error_msg) - files['deploy_config'] = parsed_args.deploy_config - - # Prompt the user for the subcloud's password if it isn't provided - if parsed_args.sysadmin_password is not None: - data['sysadmin_password'] = base64.b64encode( - parsed_args.sysadmin_password.encode("utf-8")) - else: - password = utils.prompt_for_password() - data["sysadmin_password"] = base64.b64encode( - password.encode("utf-8")) - - if parsed_args.release is not None: - data['release'] = parsed_args.release - - # Require user to type reinstall to confirm - print("WARNING: This will reinstall the subcloud. " - "All applications and data on the subcloud will be lost.") - confirm = six.moves.input( - "Please type \"reinstall\" to confirm:").strip().lower() - if confirm == 'reinstall': - try: - return dcmanager_client.subcloud_manager.reinstall_subcloud( - subcloud_ref=subcloud_ref, files=files, data=data) - except Exception as e: - print(e) - error_msg = "Unable to reinstall subcloud %s" % (subcloud_ref) - raise exceptions.DCManagerClientException(error_msg) - else: - msg = "Subcloud %s will not be reinstalled" % (subcloud_ref) - raise exceptions.DCManagerClientException(msg) + deprecation_msg = ("This command has been deprecated. Please use " + "'subcloud redeploy' instead.") + raise exceptions.DCManagerClientException(deprecation_msg) class RedeploySubcloud(base.DCManagerShowOne): diff --git a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py index 95cb2e4..acd2df9 100644 --- a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py +++ b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_manager.py @@ -194,104 +194,6 @@ class TestCLISubcloudManagerV1(base.BaseCommandTest): base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID_REHOME_DATA, actual_call[1]) - @mock.patch('getpass.getpass', return_value='testpassword') - def test_success_reconfigure_subcloud(self, getpass): - SUBCLOUD_BEING_DEPLOYED = copy.copy(base.SUBCLOUD_RESOURCE) - SUBCLOUD_BEING_DEPLOYED.deploy_status = base.DEPLOY_STATE_PRE_DEPLOY - self.client.subcloud_manager.reconfigure_subcloud.\ - return_value = [SUBCLOUD_BEING_DEPLOYED] - - with tempfile.NamedTemporaryFile() as f: - file_path = os.path.abspath(f.name) - actual_call = self.call( - subcloud_cmd.ReconfigSubcloud, - app_args=[base.ID, - '--deploy-config', file_path]) - - expected_result = list( - base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID_REHOME_DATA) - expected_result[7] = base.DEPLOY_STATE_PRE_DEPLOY - - self.assertEqual(tuple(expected_result), actual_call[1]) - - @mock.patch('getpass.getpass', return_value='testpassword') - def test_reconfigure_file_does_not_exist(self, getpass): - SUBCLOUD_BEING_DEPLOYED = copy.copy(base.SUBCLOUD_RESOURCE) - SUBCLOUD_BEING_DEPLOYED.deploy_status = base.DEPLOY_STATE_PRE_DEPLOY - self.client.subcloud_manager.reconfigure_subcloud.\ - return_value = [SUBCLOUD_BEING_DEPLOYED] - - with tempfile.NamedTemporaryFile() as f: - file_path = os.path.abspath(f.name) - - e = self.assertRaises(DCManagerClientException, - self.call, - subcloud_cmd.ReconfigSubcloud, - app_args=[base.ID, '--deploy-config', file_path]) - self.assertTrue('deploy-config file does not exist' - in str(e)) - - @mock.patch('getpass.getpass', return_value='testpassword') - @mock.patch('six.moves.input', return_value='reinstall') - def test_success_reinstall_subcloud(self, mock_input, getpass): - self.client.subcloud_manager.reinstall_subcloud.\ - return_value = [base.SUBCLOUD_RESOURCE] - with tempfile.NamedTemporaryFile() as f: - file_path = os.path.abspath(f.name) - actual_call = self.call( - subcloud_cmd.ReinstallSubcloud, - app_args=[base.ID, '--bootstrap-values', file_path]) - self.assertEqual( - base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID_REHOME_DATA, - actual_call[1]) - - @mock.patch('getpass.getpass', return_value='testpassword') - @mock.patch('six.moves.input', return_value='reinstall') - def test_reinstall_subcloud(self, mock_input, getpass): - self.client.subcloud_manager.reinstall_subcloud. \ - return_value = [base.SUBCLOUD_RESOURCE] - - with tempfile.NamedTemporaryFile(mode='w') as f: - yaml.dump(base.FAKE_BOOTSTRAP_VALUES, f) - file_path = os.path.abspath(f.name) - # Without "--release" parameter - actual_call1 = self.call( - subcloud_cmd.ReinstallSubcloud, app_args=[ - base.ID, - '--bootstrap-values', file_path, - ]) - # With "--release" parameter - actual_call2 = self.call( - subcloud_cmd.ReinstallSubcloud, app_args=[ - base.ID, - '--bootstrap-values', file_path, - '--release', base.SOFTWARE_VERSION, - ]) - self.assertEqual( - base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID_REHOME_DATA, - actual_call1[1]) - self.assertEqual( - base.SUBCLOUD_FIELD_RESULT_LIST_WITH_PEERID_REHOME_DATA, - actual_call2[1]) - - @mock.patch('getpass.getpass', return_value='testpassword') - @mock.patch('six.moves.input', return_value='reinstall') - def test_reinstall_bootstrap_file_does_not_exist( - self, mock_input, getpass): - self.client.subcloud_manager.reinstall_subcloud.\ - return_value = [base.SUBCLOUD_RESOURCE] - with tempfile.NamedTemporaryFile() as f: - file_path = os.path.abspath(f.name) - - e = self.assertRaises(DCManagerClientException, - self.call, - subcloud_cmd.ReinstallSubcloud, - app_args=[base.ID, - '--bootstrap-values', - file_path]) - self.assertTrue('bootstrap-values does not exist' - in str(e)) - @mock.patch('getpass.getpass', return_value='testpassword') @mock.patch('six.moves.input', return_value='redeploy') def test_redeploy_subcloud(self, mock_input, getpass):