Add the config file for nova compute drive

Include a certificate , key and user data.
Change-Id: I98577e180159030ad2546ca7badf0b8b04589516
This commit is contained in:
minwang 2015-03-10 17:25:19 -07:00
parent 4c8e6d8ab2
commit dc68919383
4 changed files with 48 additions and 10 deletions

View File

@ -4,7 +4,7 @@ docutils==0.11
nwdiag nwdiag
oslosphinx oslosphinx
seqdiag seqdiag
sphinx sphinx==1.2.3
sphinxcontrib-actdiag sphinxcontrib-actdiag
sphinxcontrib-blockdiag sphinxcontrib-blockdiag
sphinxcontrib-nwdiag sphinxcontrib-nwdiag

View File

@ -30,7 +30,8 @@ class ComputeBase(object):
@abc.abstractmethod @abc.abstractmethod
def build(self, name="amphora_name", amphora_flavor=None, image_id=None, 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. """Build a new amphora.
:param name: Optional name for Amphora :param name: Optional name for Amphora
@ -39,7 +40,17 @@ class ComputeBase(object):
:param key_name: Optionally specify a keypair :param key_name: Optionally specify a keypair
:param sec_groups: Optionally specify list of security groups :param sec_groups: Optionally specify list of security groups
:param network_ids: A list of network IDs to attach to the amphora :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 pass

View File

@ -46,7 +46,8 @@ class VirtualMachineManager(compute_base.ComputeBase):
pass pass
def build(self, name="amphora_name", amphora_flavor=None, image_id=None, 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. '''Create a new virtual machine.
:param name: optional name for amphora :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 key_name: keypair to add to the virtual machine
:param sec_groups: Security group IDs for virtual machine :param sec_groups: Security group IDs for virtual machine
:param network_ids: Network IDs to include on 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 :raises NovaBuildException: if nova failed to build virtual machine
:returns: UUID of amphora :returns: UUID of amphora
''' '''
try: try:
nics = [] nics = []
for net_id in network_ids: for net_id in network_ids:
@ -66,7 +77,12 @@ class VirtualMachineManager(compute_base.ComputeBase):
amphora = self.manager.create( amphora = self.manager.create(
name=name, image=image_id, flavor=amphora_flavor, name=name, image=image_id, flavor=amphora_flavor,
key_name=key_name, security_groups=sec_groups, 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 return amphora.id
except Exception: except Exception:
LOG.exception(_LE("Error building nova virtual machine.")) LOG.exception(_LE("Error building nova virtual machine."))

View File

@ -54,13 +54,24 @@ class TestNovaClient(base.TestCase):
def test_build(self): def test_build(self):
amphora_id = self.manager.build(amphora_flavor=1, image_id=1, amphora_id = self.manager.build(amphora_flavor=1, image_id=1,
key_name=1, sec_groups=1, key_name=1,
network_ids=[1]) sec_groups=1,
network_ids=[1],
user_data='Blah',
config_drive_files='Files Blah')
self.assertEqual(self.amphora.compute_id, amphora_id) self.assertEqual(self.amphora.compute_id, amphora_id)
self.manager.manager.create.assert_called_with( self.manager.manager.create.assert_called_with(
name="amphora_name", image=1, flavor=1, key_name=1, name="amphora_name",
security_groups=1, nics=[{'net-id': 1}] 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): def test_bad_build(self):
self.manager.manager.create.side_effect = Exception self.manager.manager.create.side_effect = Exception