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):
return image_id == CONF.vpn_image_id
return image_id == CONF.cloudpipe.vpn_image_id
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())
return s.substitute(dmz_net=CONF.dmz_net,
dmz_mask=CONF.dmz_mask,
return s.substitute(dmz_net=CONF.cloudpipe.dmz_net,
dmz_mask=CONF.cloudpipe.dmz_mask,
num_vpn=CONF.cnt_vpn_clients)
@ -93,19 +93,21 @@ class CloudPipe(object):
LOG.debug("Launching VPN for %s", context.project_id)
key_name = self.setup_key_pair(context)
group_name = self.setup_security_group(context)
flavor = flavors.get_flavor_by_name(CONF.vpn_flavor)
instance_name = '%s%s' % (context.project_id, CONF.vpn_key_suffix)
flavor = flavors.get_flavor_by_name(CONF.cloudpipe.vpn_flavor)
instance_name = '%s%s' % (context.project_id,
CONF.cloudpipe.vpn_key_suffix)
user_data = self.get_encoded_zip(context.project_id)
return self.compute_api.create(context,
flavor,
CONF.vpn_image_id,
CONF.cloudpipe.vpn_image_id,
display_name=instance_name,
user_data=user_data,
key_name=key_name,
security_group=[group_name])
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,
'project_id': context.project_id,
'name': group_name,
@ -131,7 +133,8 @@ class CloudPipe(object):
return group_name
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:
keypair_api = compute.api.KeypairAPI()
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
cloudpipe_group = cfg.OptGroup(
name='cloudpipe',
title='Cloudpipe options')
cloudpipe_opts = [
cfg.StrOpt('vpn_image_id',
default='0',
deprecated_group='DEFAULT',
help="""
Image ID used when starting up a cloudpipe VPN client.
@ -33,6 +38,7 @@ Possible values:
"""),
cfg.StrOpt('vpn_flavor',
default='m1.tiny',
deprecated_group='DEFAULT',
help="""
Flavor for VPN instances.
@ -42,6 +48,7 @@ Possible values:
"""),
cfg.StrOpt('boot_script_template',
default=paths.basedir_def('nova/cloudpipe/bootscript.template'),
deprecated_group='DEFAULT',
help="""
Template for cloudpipe instance boot script.
@ -60,6 +67,7 @@ OpenVPN server.
"""),
cfg.IPOpt('dmz_net',
default='10.0.0.0',
deprecated_group='DEFAULT',
help="""
Network to push into OpenVPN config.
@ -77,6 +85,7 @@ Related options:
"""),
cfg.IPOpt('dmz_mask',
default='255.255.255.0',
deprecated_group='DEFAULT',
help="""
Netmask to push into OpenVPN config.
@ -92,6 +101,7 @@ Related options:
"""),
cfg.StrOpt('vpn_key_suffix',
default='-vpn',
deprecated_group='DEFAULT',
help="""
Suffix to add to project name for VPN key and secgroups
@ -103,9 +113,9 @@ Possible values:
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():
# TODO(siva_krishnan) add opt group
return {'DEFAULT': cloudpipe_opts}
return {cloudpipe_group: cloudpipe_opts}

View File

@ -49,11 +49,11 @@ class CloudPipeSampleTest(api_sample_base.ApiSampleTestBaseV21):
def test_cloud_pipe_create(self):
# 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)}
response = self._do_post('os-cloudpipe', 'cloud-pipe-create-req',
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)
return subs
@ -61,7 +61,7 @@ class CloudPipeSampleTest(api_sample_base.ApiSampleTestBaseV21):
# Get api samples of cloud pipe extension get request.
subs = self.test_cloud_pipe_create()
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)
def test_cloud_pipe_update(self):

View File

@ -38,7 +38,7 @@ uuid = str(uuid_lib.uuid4())
def fake_vpn_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'),
uuid=uuid, project_id=project_id)

View File

@ -53,7 +53,7 @@ class PipelibTest(test.TestCase):
_do_test()
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)
res1_group = self.cloudpipe.setup_security_group(self.context)
@ -64,7 +64,7 @@ class PipelibTest(test.TestCase):
self.assertEqual(res1_group, res2_group)
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:
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.