Merge "Add accessIPv4 and accessIPv6 when create server"

This commit is contained in:
Jenkins 2015-12-09 04:39:49 +00:00 committed by Gerrit Code Review
commit 691e8d4f8b
4 changed files with 70 additions and 4 deletions

View File

@ -204,6 +204,30 @@ class ServersTest(utils.FixturedTestCase):
self.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_boot_with_address(self):
old_boot = self.cs.servers._boot
access_ip_v6 = '::1'
access_ip_v4 = '10.10.10.10'
def wrapped_boot(url, key, *boot_args, **boot_kwargs):
self.assertEqual(boot_kwargs['access_ip_v6'], access_ip_v6)
self.assertEqual(boot_kwargs['access_ip_v4'], access_ip_v4)
return old_boot(url, key, *boot_args, **boot_kwargs)
with mock.patch.object(self.cs.servers, '_boot', wrapped_boot):
s = self.cs.servers.create(
name="My server",
image=1,
flavor=1,
meta={'foo': 'bar'},
userdata="hello moto",
key_name="fakekey",
access_ip_v6=access_ip_v6,
access_ip_v4=access_ip_v4
)
self.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_file_object(self):
s = self.cs.servers.create(
name="My server",

View File

@ -234,6 +234,23 @@ class ShellTest(utils.TestCase):
}},
)
def test_boot_access_ip(self):
self.run_command(
'boot --flavor 1 --image 1 --access-ip-v4 10.10.10.10 '
'--access-ip-v6 ::1 some-server')
self.assert_called_anytime(
'POST', '/servers',
{'server': {
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'accessIPv4': '10.10.10.10',
'accessIPv6': '::1',
'max_count': 1,
'min_count': 1
}},
)
def test_boot_config_drive_custom(self):
self.run_command(
'boot --flavor 1 --image 1 --config-drive /dev/hda some-server')

View File

@ -428,7 +428,8 @@ class ServerManager(base.BootingManagerWithFind):
max_count=None, security_groups=None, key_name=None,
availability_zone=None, block_device_mapping=None,
block_device_mapping_v2=None, nics=None, scheduler_hints=None,
config_drive=None, admin_pass=None, disk_config=None, **kwargs):
config_drive=None, admin_pass=None, disk_config=None,
access_ip_v4=None, access_ip_v6=None, **kwargs):
"""
Create (boot) a new server.
"""
@ -544,6 +545,12 @@ class ServerManager(base.BootingManagerWithFind):
if disk_config is not None:
body['server']['OS-DCF:diskConfig'] = disk_config
if access_ip_v4 is not None:
body['server']['accessIPv4'] = access_ip_v4
if access_ip_v6 is not None:
body['server']['accessIPv6'] = access_ip_v6
return self._create(resource_url, body, response_key,
return_raw=return_raw, **kwargs)
@ -934,7 +941,8 @@ class ServerManager(base.BootingManagerWithFind):
key_name=None, availability_zone=None,
block_device_mapping=None, block_device_mapping_v2=None,
nics=None, scheduler_hints=None,
config_drive=None, disk_config=None, admin_pass=None, **kwargs):
config_drive=None, disk_config=None, admin_pass=None,
access_ip_v4=None, access_ip_v6=None, **kwargs):
# TODO(anthony): indicate in doc string if param is an extension
# and/or optional
"""
@ -979,6 +987,8 @@ class ServerManager(base.BootingManagerWithFind):
values are 'AUTO' or 'MANUAL'.
:param admin_pass: (optional extension) add a user supplied admin
password.
:param access_ip_v4: (optional extension) add alternative access ip v4
:param access_ip_v6: (optional extension) add alternative access ip v6
"""
if not min_count:
min_count = 1
@ -995,7 +1005,8 @@ class ServerManager(base.BootingManagerWithFind):
max_count=max_count, security_groups=security_groups,
key_name=key_name, availability_zone=availability_zone,
scheduler_hints=scheduler_hints, config_drive=config_drive,
disk_config=disk_config, admin_pass=admin_pass, **kwargs)
disk_config=disk_config, admin_pass=admin_pass,
access_ip_v4=access_ip_v4, access_ip_v6=access_ip_v6, **kwargs)
if block_device_mapping:
resource_url = "/os-volumes_boot"

View File

@ -326,7 +326,9 @@ def _boot(cs, args):
nics=nics,
scheduler_hints=hints,
config_drive=config_drive,
admin_pass=args.admin_pass)
admin_pass=args.admin_pass,
access_ip_v4=args.access_ip_v4,
access_ip_v6=args.access_ip_v6)
return boot_args, boot_kwargs
@ -516,6 +518,18 @@ def _boot(cs, args):
metavar='<value>',
default=None,
help=_('Admin password for the instance.'))
@cliutils.arg(
'--access-ip-v4',
dest='access_ip_v4',
metavar='<value>',
default=None,
help=_('Alternative access ip v4 of the instance.'))
@cliutils.arg(
'--access-ip-v6',
dest='access_ip_v6',
metavar='<value>',
default=None,
help=_('Alternative access ip v6 of the instance.'))
def do_boot(cs, args):
"""Boot a new server."""
boot_args, boot_kwargs = _boot(cs, args)