conf: Move cloudpipe options to a group

This allows us to remove the final TODO.

Change-Id: Ie9c1f7eb17acd20f60b4c89c71a6da9e1c813715
This commit is contained in:
Stephen Finucane 2016-08-17 18:00:58 +01:00
parent 8224be1736
commit 512fb41c4e
6 changed files with 35 additions and 18 deletions

View File

@ -43,14 +43,14 @@ LOG = logging.getLogger(__name__)
def is_vpn_image(image_id): def is_vpn_image(image_id):
return image_id == CONF.vpn_image_id return image_id == CONF.cloudpipe.vpn_image_id
def _load_boot_script(): def _load_boot_script():
with open(CONF.boot_script_template, "r") as shellfile: with open(CONF.cloudpipe.boot_script_template, "r") as shellfile:
s = string.Template(shellfile.read()) s = string.Template(shellfile.read())
return s.substitute(dmz_net=CONF.dmz_net, return s.substitute(dmz_net=CONF.cloudpipe.dmz_net,
dmz_mask=CONF.dmz_mask, dmz_mask=CONF.cloudpipe.dmz_mask,
num_vpn=CONF.cnt_vpn_clients) num_vpn=CONF.cnt_vpn_clients)
@ -93,19 +93,21 @@ class CloudPipe(object):
LOG.debug("Launching VPN for %s", context.project_id) LOG.debug("Launching VPN for %s", context.project_id)
key_name = self.setup_key_pair(context) key_name = self.setup_key_pair(context)
group_name = self.setup_security_group(context) group_name = self.setup_security_group(context)
flavor = flavors.get_flavor_by_name(CONF.vpn_flavor) flavor = flavors.get_flavor_by_name(CONF.cloudpipe.vpn_flavor)
instance_name = '%s%s' % (context.project_id, CONF.vpn_key_suffix) instance_name = '%s%s' % (context.project_id,
CONF.cloudpipe.vpn_key_suffix)
user_data = self.get_encoded_zip(context.project_id) user_data = self.get_encoded_zip(context.project_id)
return self.compute_api.create(context, return self.compute_api.create(context,
flavor, flavor,
CONF.vpn_image_id, CONF.cloudpipe.vpn_image_id,
display_name=instance_name, display_name=instance_name,
user_data=user_data, user_data=user_data,
key_name=key_name, key_name=key_name,
security_group=[group_name]) security_group=[group_name])
def setup_security_group(self, context): def setup_security_group(self, context):
group_name = '%s%s' % (context.project_id, CONF.vpn_key_suffix) group_name = '%s%s' % (context.project_id,
CONF.cloudpipe.vpn_key_suffix)
group = {'user_id': context.user_id, group = {'user_id': context.user_id,
'project_id': context.project_id, 'project_id': context.project_id,
'name': group_name, 'name': group_name,
@ -131,7 +133,8 @@ class CloudPipe(object):
return group_name return group_name
def setup_key_pair(self, context): def setup_key_pair(self, context):
key_name = '%s%s' % (context.project_id, CONF.vpn_key_suffix) key_name = '%s%s' % (context.project_id,
CONF.cloudpipe.vpn_key_suffix)
try: try:
keypair_api = compute.api.KeypairAPI() keypair_api = compute.api.KeypairAPI()
result, private_key = keypair_api.create_key_pair(context, result, private_key = keypair_api.create_key_pair(context,

View File

@ -16,9 +16,14 @@ from oslo_config import cfg
from nova.conf import paths from nova.conf import paths
cloudpipe_group = cfg.OptGroup(
name='cloudpipe',
title='Cloudpipe options')
cloudpipe_opts = [ cloudpipe_opts = [
cfg.StrOpt('vpn_image_id', cfg.StrOpt('vpn_image_id',
default='0', default='0',
deprecated_group='DEFAULT',
help=""" help="""
Image ID used when starting up a cloudpipe VPN client. Image ID used when starting up a cloudpipe VPN client.
@ -33,6 +38,7 @@ Possible values:
"""), """),
cfg.StrOpt('vpn_flavor', cfg.StrOpt('vpn_flavor',
default='m1.tiny', default='m1.tiny',
deprecated_group='DEFAULT',
help=""" help="""
Flavor for VPN instances. Flavor for VPN instances.
@ -42,6 +48,7 @@ Possible values:
"""), """),
cfg.StrOpt('boot_script_template', cfg.StrOpt('boot_script_template',
default=paths.basedir_def('nova/cloudpipe/bootscript.template'), default=paths.basedir_def('nova/cloudpipe/bootscript.template'),
deprecated_group='DEFAULT',
help=""" help="""
Template for cloudpipe instance boot script. Template for cloudpipe instance boot script.
@ -60,6 +67,7 @@ OpenVPN server.
"""), """),
cfg.IPOpt('dmz_net', cfg.IPOpt('dmz_net',
default='10.0.0.0', default='10.0.0.0',
deprecated_group='DEFAULT',
help=""" help="""
Network to push into OpenVPN config. Network to push into OpenVPN config.
@ -77,6 +85,7 @@ Related options:
"""), """),
cfg.IPOpt('dmz_mask', cfg.IPOpt('dmz_mask',
default='255.255.255.0', default='255.255.255.0',
deprecated_group='DEFAULT',
help=""" help="""
Netmask to push into OpenVPN config. Netmask to push into OpenVPN config.
@ -92,6 +101,7 @@ Related options:
"""), """),
cfg.StrOpt('vpn_key_suffix', cfg.StrOpt('vpn_key_suffix',
default='-vpn', default='-vpn',
deprecated_group='DEFAULT',
help=""" help="""
Suffix to add to project name for VPN key and secgroups Suffix to add to project name for VPN key and secgroups
@ -103,9 +113,9 @@ Possible values:
def register_opts(conf): def register_opts(conf):
conf.register_opts(cloudpipe_opts) conf.register_group(cloudpipe_group)
conf.register_opts(cloudpipe_opts, group=cloudpipe_group)
def list_opts(): def list_opts():
# TODO(siva_krishnan) add opt group return {cloudpipe_group: cloudpipe_opts}
return {'DEFAULT': cloudpipe_opts}

View File

@ -49,11 +49,11 @@ class CloudPipeSampleTest(api_sample_base.ApiSampleTestBaseV21):
def test_cloud_pipe_create(self): def test_cloud_pipe_create(self):
# Get api samples of cloud pipe extension creation. # Get api samples of cloud pipe extension creation.
self.flags(vpn_image_id=fake.get_valid_image_id()) self.flags(vpn_image_id=fake.get_valid_image_id(), group='cloudpipe')
subs = {'project_id': str(uuid_lib.uuid4().hex)} subs = {'project_id': str(uuid_lib.uuid4().hex)}
response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req', response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req',
subs) subs)
subs['image_id'] = CONF.vpn_image_id subs['image_id'] = CONF.cloudpipe.vpn_image_id
self._verify_response('cloud-pipe-create-resp', subs, response, 200) self._verify_response('cloud-pipe-create-resp', subs, response, 200)
return subs return subs
@ -61,7 +61,7 @@ class CloudPipeSampleTest(api_sample_base.ApiSampleTestBaseV21):
# Get api samples of cloud pipe extension get request. # Get api samples of cloud pipe extension get request.
subs = self.test_cloud_pipe_create() subs = self.test_cloud_pipe_create()
response = self._do_get('os-cloudpipe') response = self._do_get('os-cloudpipe')
subs['image_id'] = CONF.vpn_image_id subs['image_id'] = CONF.cloudpipe.vpn_image_id
self._verify_response('cloud-pipe-get-resp', subs, response, 200) self._verify_response('cloud-pipe-get-resp', subs, response, 200)
def test_cloud_pipe_update(self): def test_cloud_pipe_update(self):

View File

@ -38,7 +38,7 @@ uuid = str(uuid_lib.uuid4())
def fake_vpn_instance(): def fake_vpn_instance():
return objects.Instance( return objects.Instance(
id=7, image_ref=CONF.vpn_image_id, vm_state='active', id=7, image_ref=CONF.cloudpipe.vpn_image_id, vm_state='active',
created_at=timeutils.parse_strtime('1981-10-20T00:00:00.000000'), created_at=timeutils.parse_strtime('1981-10-20T00:00:00.000000'),
uuid=uuid, project_id=project_id) uuid=uuid, project_id=project_id)

View File

@ -53,7 +53,7 @@ class PipelibTest(test.TestCase):
_do_test() _do_test()
def test_setup_security_group(self): def test_setup_security_group(self):
group_name = "%s%s" % (self.project, CONF.vpn_key_suffix) group_name = "%s%s" % (self.project, CONF.cloudpipe.vpn_key_suffix)
# First attempt, does not exist (thus its created) # First attempt, does not exist (thus its created)
res1_group = self.cloudpipe.setup_security_group(self.context) res1_group = self.cloudpipe.setup_security_group(self.context)
@ -64,7 +64,7 @@ class PipelibTest(test.TestCase):
self.assertEqual(res1_group, res2_group) self.assertEqual(res1_group, res2_group)
def test_setup_key_pair(self): def test_setup_key_pair(self):
key_name = "%s%s" % (self.project, CONF.vpn_key_suffix) key_name = "%s%s" % (self.project, CONF.cloudpipe.vpn_key_suffix)
with utils.tempdir() as tmpdir: with utils.tempdir() as tmpdir:
self.flags(keys_path=tmpdir, group='crypto') self.flags(keys_path=tmpdir, group='crypto')

View File

@ -0,0 +1,4 @@
---
upgrade:
- All cloudpipe configuration options have been added to the 'cloudpipe'
group. They should no longer be included in the 'DEFAULT' group.