Move postconfig to deploy command

Change-Id: Ibcedd19002939b647c542c82c862d03cda2d6073
This commit is contained in:
Brad P. Crochet 2015-06-16 13:03:17 -04:00
parent a933eec21d
commit 7b22702074
4 changed files with 90 additions and 115 deletions

View File

@ -33,6 +33,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self._get_passwords = generate_overcloud_passwords_mock
@mock.patch('rdomanager_oscplugin.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_postconfig')
@mock.patch('rdomanager_oscplugin.v1.overcloud_deploy.DeployOvercloud.'
'_update_nodesjson')
@mock.patch('rdomanager_oscplugin.utils.generate_overcloud_passwords')
@ -64,7 +66,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_sleep, mock_setup_endpoints,
mock_create_overcloudrc,
mock_generate_overcloud_passwords,
mock_update_nodesjson):
mock_update_nodesjson,
mock_deploy_postconfig):
arglist = ['--use-tripleo-heat-templates', ]
verifylist = [
@ -114,6 +117,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
self.assertEqual(kwargs['environment'], 'env')
self.assertEqual(kwargs['stack_name'], 'overcloud')
@mock.patch('rdomanager_oscplugin.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_postconfig')
@mock.patch('rdomanager_oscplugin.v1.overcloud_deploy.DeployOvercloud.'
'_update_nodesjson')
@mock.patch('rdomanager_oscplugin.utils.get_config_value', autospec=True)
@ -134,7 +139,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_get_templte_contents,
mock_process_multiple_env,
mock_generate_overcloud_passwords,
mock_get_key, mock_update_nodesjson):
mock_get_key, mock_update_nodesjson,
mock_deploy_postconfig):
arglist = ['--plan', 'undercloud', '--output-dir', 'fake']
verifylist = [

View File

@ -28,7 +28,10 @@ from heatclient.common import template_utils
from heatclient.exc import HTTPNotFound
from openstackclient.common import utils as oscutils
from openstackclient.i18n import _
from os_cloud_config import keystone
from os_cloud_config import keystone_pki
from os_cloud_config import neutron
from os_cloud_config.utils import clients
from rdomanager_oscplugin import utils
@ -470,6 +473,75 @@ class DeployOvercloud(command.Command):
with open("instackenv.json", "w") as f:
json.dump(instack_env, f)
def _deploy_postconfig(self, stack, parsed_args):
self.log.debug("_deploy_postconfig(%s)" % parsed_args)
passwords = self.passwords
overcloud_endpoint = self._get_overcloud_endpoint(stack)
overcloud_ip = six.moves.urllib.parse.urlparse(
overcloud_endpoint).hostname
utils.remove_known_hosts(overcloud_ip)
keystone.initialize(
overcloud_ip,
passwords['OVERCLOUD_ADMIN_TOKEN'],
'admin@example.com',
passwords['OVERCLOUD_ADMIN_PASSWORD'],
user='heat-admin')
services = {}
for service, data in six.iteritems(utils.SERVICE_LIST):
service_data = {}
password_field = data.get('password_field')
if password_field:
service_data['password'] = passwords[password_field]
services.update({service: service_data})
keystone_client = clients.get_keystone_client(
'admin',
passwords['OVERCLOUD_ADMIN_PASSWORD'],
'admin',
overcloud_endpoint)
keystone.setup_endpoints(
services,
client=keystone_client,
os_auth_url=overcloud_endpoint)
network_description = {
"float": {
"cidr": parsed_args.network_cidr,
"name": "default-net",
"nameserver": parsed_args.overcloud_nameserver
},
"external": {
"name": "ext-net",
"cidr": parsed_args.floating_id_cidr,
"allocation_start": parsed_args.floating_ip_start,
"allocation_end": parsed_args.floating_ip_end,
"gateway": parsed_args.bm_network_gateway,
}
}
neutron_client = clients.get_neutron_client(
'admin',
passwords['OVERCLOUD_ADMIN_PASSWORD'],
'admin',
overcloud_endpoint)
neutron.initialize_neutron(
network_description,
neutron_client=neutron_client,
keystone_client=keystone_client,
)
compute_client = clients.get_nova_bm_client(
'admin',
passwords['OVERCLOUD_ADMIN_PASSWORD'],
'admin',
overcloud_endpoint)
compute_client.flavors.create('m1.demo', 512, 1, 10, 'auto')
def get_parser(self, prog_name):
parser = super(DeployOvercloud, self).get_parser(prog_name)
parser.add_argument('--control-scale', type=int, default=1)
@ -543,6 +615,12 @@ class DeployOvercloud(command.Command):
help=('Directory containing any extra environment files to pass '
'heat. (Defaults to /etc/tripleo/extra_config.d)')
)
parser.add_argument('--overcloud_nameserver', default='8.8.8.8')
parser.add_argument('--floating-id-cidr', default='192.0.2.0/24')
parser.add_argument('--floating-ip-start', default='192.0.2.45')
parser.add_argument('--floating-ip-end', default='192.0.2.64')
parser.add_argument('--bm-network-gateway', default='192.0.2.1')
parser.add_argument('--network-cidr', default='10.0.0.0/8')
return parser
@ -553,6 +631,7 @@ class DeployOvercloud(command.Command):
orchestration_client = clients.rdomanager_oscplugin.orchestration()
stack = self._get_stack(orchestration_client)
stack_create = stack is None
self._pre_heat_deploy()
@ -569,6 +648,9 @@ class DeployOvercloud(command.Command):
self._update_nodesjson(stack)
if stack_create:
self._deploy_postconfig(stack, parsed_args)
overcloud_endpoint = self._get_overcloud_endpoint(stack)
print("Overcloud Endpoint: {0}".format(overcloud_endpoint))
print("Overcloud Deployed")

View File

@ -1,112 +0,0 @@
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from __future__ import print_function
import logging
import six
from cliff import command
from openstackclient.i18n import _
from os_cloud_config import keystone
from os_cloud_config import neutron
from os_cloud_config.utils import clients
from rdomanager_oscplugin import utils
class PostconfigOvercloud(command.Command):
"""Complete the configuration of the overcloud"""
log = logging.getLogger(__name__ + ".PostconfigOvercloud")
def get_parser(self, prog_name):
parser = super(PostconfigOvercloud, self).get_parser(prog_name)
parser.add_argument('--overcloud_nameserver', default='8.8.8.8')
parser.add_argument('--floating-id-cidr', default='192.0.2.0/24')
parser.add_argument('--floating-ip-start', default='192.0.2.45')
parser.add_argument('--floating-ip-end', default='192.0.2.64')
parser.add_argument('--ibm-network-gateway', default='192.0.2.1')
parser.add_argument('--network-cidr', default='10.0.0.0/8')
parser.add_argument(
'overcloud_ip',
help=_('The IP address of the Overcloud endpoint')
)
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
passwords = utils.generate_overcloud_passwords()
utils.remove_known_hosts(parsed_args.overcloud_ip)
keystone.initialize(
parsed_args.overcloud_ip,
passwords['OVERCLOUD_ADMIN_TOKEN'],
'admin@example.com',
passwords['OVERCLOUD_ADMIN_PASSWORD'],
user='heat-admin')
services = {}
for service, data in six.iteritems(utils.SERVICE_LIST):
service_data = {}
password_field = data.get('password_field')
if password_field:
service_data['password'] = passwords[password_field]
services.update({service: service_data})
identity_client = self.app.client_manager.identity
keystone.setup_endpoints(
services,
client=identity_client,
os_auth_url=self.app.client_manager.auth_ref.auth_url[0])
network_description = {
"float": {
"cidr": parsed_args.network_cidr,
"name": "default-net",
"nameserver": parsed_args.overcloud_nameserver
},
"external": {
"name": "ext-net",
"cidr": parsed_args.floating_id_cidr,
"allocation_start": parsed_args.floating_ip_start,
"allocation_end": parsed_args.floating_ip_end,
"gateway": parsed_args.ibm_network_gateway,
}
}
# retrieve needed Overcloud clients
auth_ref = self.app.client_manager.auth_ref
keystone_client = clients.get_keystone_client(
auth_ref.username,
passwords['OVERCLOUD_ADMIN_PASSWORD'],
auth_ref.project_name,
auth_ref.auth_url[0])
neutron_client = clients.get_neutron_client(
auth_ref.username,
passwords['OVERCLOUD_ADMIN_PASSWORD'],
auth_ref.project_name,
auth_ref.auth_url[0])
neutron.initialize_neutron(
network_description,
neutron_client=neutron_client,
keystone_client=keystone_client,
)
self.app.client_manager.compute.flavors.create(
'm1.demo', 512, 1, 10, 'auto')

View File

@ -65,7 +65,6 @@ openstack.rdomanager_oscplugin.v1 =
overcloud_image_build = rdomanager_oscplugin.v1.overcloud_image:BuildOvercloudImage
overcloud_image_upload = rdomanager_oscplugin.v1.overcloud_image:UploadOvercloudImage
overcloud_node_delete = rdomanager_oscplugin.v1.overcloud_node:DeleteNode
overcloud_postconfig = rdomanager_oscplugin.v1.overcloud_postconfig:PostconfigOvercloud
overcloud_update_stack = rdomanager_oscplugin.v1.overcloud_update:UpdateOvercloud
overcloud_validate = rdomanager_oscplugin.v1.overcloud_validate:ValidateOvercloud
undercloud_install = rdomanager_oscplugin.v1.undercloud:InstallPlugin