From dc68919383c9bd915dc9f1b4566805c318e36748 Mon Sep 17 00:00:00 2001 From: minwang Date: Tue, 10 Mar 2015 17:25:19 -0700 Subject: [PATCH] Add the config file for nova compute drive Include a certificate , key and user data. Change-Id: I98577e180159030ad2546ca7badf0b8b04589516 --- doc-requirements.txt | 2 +- octavia/compute/compute_base.py | 15 +++++++++++-- octavia/compute/drivers/nova_driver.py | 20 ++++++++++++++++-- .../unit/compute/drivers/test_nova_driver.py | 21 ++++++++++++++----- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/doc-requirements.txt b/doc-requirements.txt index be3b93fe60..822e660cab 100644 --- a/doc-requirements.txt +++ b/doc-requirements.txt @@ -4,7 +4,7 @@ docutils==0.11 nwdiag oslosphinx seqdiag -sphinx +sphinx==1.2.3 sphinxcontrib-actdiag sphinxcontrib-blockdiag sphinxcontrib-nwdiag diff --git a/octavia/compute/compute_base.py b/octavia/compute/compute_base.py index 4fe9df957f..2ea54bebf7 100644 --- a/octavia/compute/compute_base.py +++ b/octavia/compute/compute_base.py @@ -30,7 +30,8 @@ class ComputeBase(object): @abc.abstractmethod def build(self, name="amphora_name", amphora_flavor=None, image_id=None, - key_name=None, sec_groups=None, network_ids=None): + key_name=None, sec_groups=None, network_ids=None, + config_drive_files=None, user_data=None): """Build a new amphora. :param name: Optional name for Amphora @@ -39,7 +40,17 @@ class ComputeBase(object): :param key_name: Optionally specify a keypair :param sec_groups: Optionally specify list of security groups :param network_ids: A list of network IDs to attach to the amphora - :returns: The id of the new instance. + :param config_drive_files: An optional dict of files to overwrite on + the server upon boot. Keys are file names (i.e. /etc/passwd) + and values are the file contents (either as a string or as + a file-like object). A maximum of five entries is allowed, + and each file must be 10k or less. + :param user_data: Optional user data to pass to be exposed by the + metadata server this can be a file type object as well or + a string + + :raises NovaBuildException: if nova failed to build virtual machine + :returns: UUID of amphora """ pass diff --git a/octavia/compute/drivers/nova_driver.py b/octavia/compute/drivers/nova_driver.py index 11e15e42a7..b47274500a 100644 --- a/octavia/compute/drivers/nova_driver.py +++ b/octavia/compute/drivers/nova_driver.py @@ -46,7 +46,8 @@ class VirtualMachineManager(compute_base.ComputeBase): pass def build(self, name="amphora_name", amphora_flavor=None, image_id=None, - key_name=None, sec_groups=None, network_ids=None): + key_name=None, sec_groups=None, network_ids=None, + config_drive_files=None, user_data=None): '''Create a new virtual machine. :param name: optional name for amphora @@ -55,9 +56,19 @@ class VirtualMachineManager(compute_base.ComputeBase): :param key_name: keypair to add to the virtual machine :param sec_groups: Security group IDs for virtual machine :param network_ids: Network IDs to include on virtual machine + :param config_drive_files: An optional dict of files to overwrite on + the server upon boot. Keys are file names (i.e. /etc/passwd) + and values are the file contents (either as a string or as + a file-like object). A maximum of five entries is allowed, + and each file must be 10k or less. + :param user_data: Optional user data to pass to be exposed by the + metadata server this can be a file type object as well or + a string + :raises NovaBuildException: if nova failed to build virtual machine :returns: UUID of amphora ''' + try: nics = [] for net_id in network_ids: @@ -66,7 +77,12 @@ class VirtualMachineManager(compute_base.ComputeBase): amphora = self.manager.create( name=name, image=image_id, flavor=amphora_flavor, key_name=key_name, security_groups=sec_groups, - nics=nics) + nics=nics, + config_drive_files=config_drive_files, + user_data=user_data, + config_drive=True + ) + return amphora.id except Exception: LOG.exception(_LE("Error building nova virtual machine.")) diff --git a/octavia/tests/unit/compute/drivers/test_nova_driver.py b/octavia/tests/unit/compute/drivers/test_nova_driver.py index 45f2c02948..8ea94c4581 100644 --- a/octavia/tests/unit/compute/drivers/test_nova_driver.py +++ b/octavia/tests/unit/compute/drivers/test_nova_driver.py @@ -54,13 +54,24 @@ class TestNovaClient(base.TestCase): def test_build(self): amphora_id = self.manager.build(amphora_flavor=1, image_id=1, - key_name=1, sec_groups=1, - network_ids=[1]) + key_name=1, + sec_groups=1, + network_ids=[1], + user_data='Blah', + config_drive_files='Files Blah') + self.assertEqual(self.amphora.compute_id, amphora_id) + self.manager.manager.create.assert_called_with( - name="amphora_name", image=1, flavor=1, key_name=1, - security_groups=1, nics=[{'net-id': 1}] - ) + name="amphora_name", + nics=[{'net-id': 1}], + image=1, + flavor=1, + key_name=1, + security_groups=1, + config_drive_files='Files Blah', + user_data='Blah', + config_drive=True) def test_bad_build(self): self.manager.manager.create.side_effect = Exception