Add CLI/API to populate data_install

The dcmanager subcloud update CLI is extended to allow
populating/updating the install values required for
remote install (upgrade to stx 4.0).
dcmanager subcloud update subcloud1 --install-values\
install-values.yaml --bmc-password <password>

Depends-On: https://review.opendev.org/#/c/737630/
Story: 2007403
Task: 40148

Change-Id: Ifd7812a164cd110b4082974ac66ef9bd86c9c9dc
Signed-off-by: Tao Liu <tao.liu@windriver.com>
This commit is contained in:
Tao Liu 2020-06-23 17:06:27 -04:00
parent 2e351d9bcf
commit dd05eccb08
2 changed files with 61 additions and 35 deletions

View File

@ -20,8 +20,6 @@
# of an applicable Wind River license agreement.
#
import json
from requests_toolbelt import MultipartEncoder
from dcmanagerclient.api import base
@ -99,33 +97,19 @@ class subcloud_manager(base.ResourceManager):
resource.append(self.json_to_resource(json_object))
return resource
def subcloud_update(self, url, data):
data = json.dumps(data)
resp = self.http_client.patch(url, data)
def subcloud_update(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.resource_class(
self,
subcloud_id=json_object['id'],
name=json_object['name'],
description=json_object['description'],
location=json_object['location'],
software_version=json_object['software-version'],
management_state=json_object['management-state'],
availability_status=json_object['availability-status'],
deploy_status=json_object['deploy-status'],
management_subnet=json_object['management-subnet'],
management_start_ip=json_object['management-start-ip'],
management_end_ip=json_object['management-end-ip'],
management_gateway_ip=json_object['management-gateway-ip'],
systemcontroller_gateway_ip=json_object[
'systemcontroller-gateway-ip'],
created_at=json_object['created-at'],
updated_at=json_object['updated-at'],
group_id=json_object['group_id']))
resource.append(self.json_to_resource(json_object))
return resource
def subcloud_reconfigure(self, url, body, data):
@ -229,9 +213,10 @@ class subcloud_manager(base.ResourceManager):
return self._delete(url)
def update_subcloud(self, subcloud_ref, **kwargs):
data = kwargs
files = kwargs.get('files')
data = kwargs.get('data')
url = '/subclouds/%s' % subcloud_ref
return self.subcloud_update(url, data)
return self.subcloud_update(url, files, data)
def reconfigure_subcloud(self, subcloud_ref, **kwargs):
files = kwargs.get('files')

View File

@ -159,7 +159,8 @@ class AddSubcloud(base.DCManagerShowOne):
'--bmc-password',
required=False,
help='bmc password of the subcloud to be configured, '
'if not provided you will be prompted.'
'if not provided you will be prompted. This parameter is only'
' valid if the --install-values are specified.'
)
parser.add_argument(
@ -408,26 +409,66 @@ class UpdateSubcloud(base.DCManagerShowOne):
help='Name or ID of subcloud group.'
)
parser.add_argument(
'--install-values',
required=False,
help='YAML file containing subcloud variables required for remote '
'install playbook.'
)
parser.add_argument(
'--bmc-password',
required=False,
help='bmc password of the subcloud to be configured, if not '
'provided you will be prompted. This parameter is only'
' valid if the --install-values are specified.'
)
return parser
def _get_resources(self, parsed_args):
subcloud_ref = parsed_args.subcloud
dcmanager_client = self.app.client_manager.subcloud_manager
kwargs = dict()
files = dict()
data = dict()
if parsed_args.description:
kwargs['description'] = parsed_args.description
data['description'] = parsed_args.description
if parsed_args.location:
kwargs['location'] = parsed_args.location
data['location'] = parsed_args.location
if parsed_args.group:
kwargs['group_id'] = parsed_args.group
if len(kwargs) == 0:
error_msg = "Nothing to update"
data['group_id'] = parsed_args.group
if parsed_args.install_values:
if not os.path.isfile(parsed_args.install_values):
error_msg = "install-values does not exist: %s" % \
parsed_args.install_values
raise exceptions.DCManagerClientException(error_msg)
files['install_values'] = parsed_args.install_values
if parsed_args.bmc_password is not None:
data['bmc_password'] = base64.b64encode(
parsed_args.bmc_password.encode("utf-8"))
else:
while True:
password = getpass.getpass(
"Enter the bmc password for the subcloud: ")
if len(password) < 1:
print("Password cannot be empty")
continue
confirm = getpass.getpass(
"Re-enter bmc password to confirm: ")
if password != confirm:
print("Passwords did not match")
continue
data["bmc_password"] = base64.b64encode(
password.encode("utf-8"))
break
if len(data) == 0:
error_msg = "Nothing to update"
raise exceptions.DCManagerClientException(error_msg)
try:
return dcmanager_client.subcloud_manager.update_subcloud(
subcloud_ref, **kwargs)
subcloud_ref, files=files, data=data)
except Exception as e:
print(e)
error_msg = "Unable to update subcloud %s" % (subcloud_ref)