From 39a46f48bfcaae1ca4500ba145c1c08c6bf009f1 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 8 Jan 2013 08:13:12 +0000 Subject: Move vpn_image_id to pipelib Apart from checking whether a given image is the cloudpipe image, the vpn_image_id option is only used within pipelib itself. Add a is_vpn_image() helper method and move the option into pipelib. Some rejiggering of how pipelib imports ec2 opts is required to avoid circular imports. blueprint: scope-config-opts Change-Id: Ie984b2bb81681c24d3cee803082960083992a535 --- nova/cloudpipe/pipelib.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'nova/cloudpipe') diff --git a/nova/cloudpipe/pipelib.py b/nova/cloudpipe/pipelib.py index c165b44ffb..19cbf32535 100644 --- a/nova/cloudpipe/pipelib.py +++ b/nova/cloudpipe/pipelib.py @@ -39,6 +39,9 @@ from nova import utils cloudpipe_opts = [ + cfg.StrOpt('vpn_image_id', + default='0', + help='image id used when starting up a cloudpipe vpn server'), cfg.StrOpt('vpn_instance_type', default='m1.tiny', help=_('Instance type for vpn instances')), @@ -55,15 +58,33 @@ cloudpipe_opts = [ CONF = cfg.CONF CONF.register_opts(cloudpipe_opts) -CONF.import_opt('ec2_dmz_host', 'nova.api.ec2.cloud') -CONF.import_opt('ec2_port', 'nova.api.ec2.cloud') -CONF.import_opt('vpn_image_id', 'nova.config') CONF.import_opt('vpn_key_suffix', 'nova.config') -CONF.import_opt('cnt_vpn_clients', 'nova.network.manager') LOG = logging.getLogger(__name__) +def is_vpn_image(image_id): + return image_id == CONF.vpn_image_id + + +def _load_boot_script(): + shellfile = open(CONF.boot_script_template, "r") + try: + s = string.Template(shellfile.read()) + finally: + shellfile.close() + + CONF.import_opt('ec2_dmz_host', 'nova.api.ec2.cloud') + CONF.import_opt('ec2_port', 'nova.api.ec2.cloud') + CONF.import_opt('cnt_vpn_clients', 'nova.network.manager') + + return s.substitute(cc_dmz=CONF.ec2_dmz_host, + cc_port=CONF.ec2_port, + dmz_net=CONF.dmz_net, + dmz_mask=CONF.dmz_mask, + num_vpn=CONF.cnt_vpn_clients) + + class CloudPipe(object): def __init__(self): self.compute_api = compute.API() @@ -74,14 +95,7 @@ class CloudPipe(object): filename = "payload.zip" zippath = os.path.join(tmpdir, filename) z = zipfile.ZipFile(zippath, "w", zipfile.ZIP_DEFLATED) - shellfile = open(CONF.boot_script_template, "r") - s = string.Template(shellfile.read()) - shellfile.close() - boot_script = s.substitute(cc_dmz=CONF.ec2_dmz_host, - cc_port=CONF.ec2_port, - dmz_net=CONF.dmz_net, - dmz_mask=CONF.dmz_mask, - num_vpn=CONF.cnt_vpn_clients) + boot_script = _load_boot_script() # genvpn, sign csr crypto.generate_vpn_files(project_id) z.writestr('autorun.sh', boot_script) -- cgit v1.2.1