Merge "Support IPv6 when booting instances"

This commit is contained in:
Jenkins 2014-04-09 08:46:55 +00:00 committed by Gerrit Code Review
commit b3c57729c5
8 changed files with 151 additions and 10 deletions

View File

@ -104,6 +104,28 @@ class ServersTest(utils.TestCase):
test_create_server_from_volume()
def test_create_server_boot_with_nics_ipv6(self):
old_boot = cs.servers._boot
nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
'v6-fixed-ip': '2001:db9:0:1::10'}]
def wrapped_boot(url, key, *boot_args, **boot_kwargs):
self.assertEqual(boot_kwargs['nics'], nics)
return old_boot(url, key, *boot_args, **boot_kwargs)
with mock.patch.object(cs.servers, '_boot', wrapped_boot):
s = cs.servers.create(
name="My server",
image=1,
flavor=1,
meta={'foo': 'bar'},
userdata="hello moto",
key_name="fakekey",
nics=nics
)
cs.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_file_object(self):
s = cs.servers.create(
name="My server",

View File

@ -497,6 +497,32 @@ class ShellTest(utils.TestCase):
},
)
def test_boot_nics_ipv6(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id=a=c,v6-fixed-ip=2001:db9:0:1::10 some-server')
self.run_command(cmd)
self.assert_called_anytime(
'POST', '/servers',
{
'server': {
'flavorRef': '1',
'name': 'some-server',
'imageRef': '1',
'min_count': 1,
'max_count': 1,
'networks': [
{'uuid': 'a=c', 'fixed_ip': '2001:db9:0:1::10'},
],
},
},
)
def test_boot_nics_both_ipv4_and_ipv6(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id=a=c,v4-fixed-ip=10.0.0.1,'
'v6-fixed-ip=2001:db9:0:1::10 some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_no_value(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id some-server')

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import six
from novaclient import exceptions
@ -74,6 +75,50 @@ class ServersTest(utils.TestCase):
cs.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_boot_with_nics_ipv4(self):
old_boot = cs.servers._boot
nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
'v4-fixed-ip': '10.10.0.7'}]
def wrapped_boot(url, key, *boot_args, **boot_kwargs):
self.assertEqual(boot_kwargs['nics'], nics)
return old_boot(url, key, *boot_args, **boot_kwargs)
with mock.patch.object(cs.servers, '_boot', wrapped_boot):
s = cs.servers.create(
name="My server",
image=1,
flavor=1,
meta={'foo': 'bar'},
userdata="hello moto",
key_name="fakekey",
nics=nics
)
cs.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_boot_with_nics_ipv6(self):
old_boot = cs.servers._boot
nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
'v6-fixed-ip': '2001:db9:0:1::10'}]
def wrapped_boot(url, key, *boot_args, **boot_kwargs):
self.assertEqual(boot_kwargs['nics'], nics)
return old_boot(url, key, *boot_args, **boot_kwargs)
with mock.patch.object(cs.servers, '_boot', wrapped_boot):
s = cs.servers.create(
name="My server",
image=1,
flavor=1,
meta={'foo': 'bar'},
userdata="hello moto",
key_name="fakekey",
nics=nics
)
cs.assert_called('POST', '/servers')
self.assertIsInstance(s, servers.Server)
def test_create_server_userdata_file_object(self):
s = cs.servers.create(
name="My server",

View File

@ -428,6 +428,32 @@ class ShellTest(utils.TestCase):
},
)
def test_boot_nics_ipv6(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id=a=c,v6-fixed-ip=2001:db9:0:1::10 some-server')
self.run_command(cmd)
self.assert_called_anytime(
'POST', '/servers',
{
'server': {
'flavor_ref': '1',
'name': 'some-server',
'image_ref': '1',
'os-multiple-create:min_count': 1,
'os-multiple-create:max_count': 1,
'networks': [
{'uuid': 'a=c', 'fixed_ip': '2001:db9:0:1::10'},
],
},
},
)
def test_boot_nics_both_ipv4_and_ipv6(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id=a=c,v4-fixed-ip=10.0.0.1,'
'v6-fixed-ip=2001:db9:0:1::10 some-server')
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
def test_boot_nics_no_value(self):
cmd = ('boot --image 1 --flavor 1 '
'--nic net-id some-server')

View File

@ -26,6 +26,7 @@ from six.moves.urllib import parse
from novaclient import base
from novaclient import crypto
from novaclient.openstack.common.gettextutils import _
from novaclient.openstack.common import strutils
from novaclient.v1_1.security_groups import SecurityGroup
@ -520,8 +521,15 @@ class ServerManager(base.BootingManagerWithFind):
# if value is empty string, do not send value in body
if nic_info.get('net-id'):
net_data['uuid'] = nic_info['net-id']
if nic_info.get('v4-fixed-ip'):
if (nic_info.get('v4-fixed-ip') and
nic_info.get('v6-fixed-ip')):
raise base.exceptions.CommandError(_(
"Only one of 'v4-fixed-ip' and 'v6-fixed-ip' may be"
" provided."))
elif nic_info.get('v4-fixed-ip'):
net_data['fixed_ip'] = nic_info['v4-fixed-ip']
elif nic_info.get('v6-fixed-ip'):
net_data['fixed_ip'] = nic_info['v6-fixed-ip']
if nic_info.get('port-id'):
net_data['port'] = nic_info['port-id']
all_net_data.append(net_data)

View File

@ -226,9 +226,10 @@ def _boot(cs, args):
for nic_str in args.nics:
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
"the form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
"port-id=port-uuid>, with at minimum net-id or port-id "
"specified.") % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "port-id": ""}
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
"net-id or port-id specified.") % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
"port-id": ""}
for kv_str in nic_str.split(","):
try:
@ -392,7 +393,8 @@ def _boot(cs, args):
help=_("Send arbitrary key/value pairs to the scheduler for custom "
"use."))
@utils.arg('--nic',
metavar="<net-id=net-uuid,v4-fixed-ip=ip-addr,port-id=port-uuid>",
metavar="<net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,"
"port-id=port-uuid>",
action='append',
dest='nics',
default=[],
@ -401,6 +403,7 @@ def _boot(cs, args):
"net-id: attach NIC to network with this UUID "
"(required if no port-id), "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
"v6-fixed-ip: IPv6 fixed address for NIC (optional), "
"port-id: attach NIC to port with this UUID "
"(required if no net-id)"))
@utils.arg('--config-drive',

View File

@ -26,6 +26,7 @@ from six.moves.urllib import parse
from novaclient import base
from novaclient import crypto
from novaclient.openstack.common.gettextutils import _
from novaclient.openstack.common import strutils
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
@ -457,8 +458,15 @@ class ServerManager(base.BootingManagerWithFind):
# if value is empty string, do not send value in body
if nic_info.get('net-id'):
net_data['uuid'] = nic_info['net-id']
if nic_info.get('v4-fixed-ip'):
if (nic_info.get('v4-fixed-ip') and
nic_info.get('v6-fixed-ip')):
raise base.exceptions.CommandError(_(
"Only one of 'v4-fixed-ip' and 'v6-fixed-ip' may be"
" provided."))
elif nic_info.get('v4-fixed-ip'):
net_data['fixed_ip'] = nic_info['v4-fixed-ip']
elif nic_info.get('v6-fixed-ip'):
net_data['fixed_ip'] = nic_info['v6-fixed-ip']
if nic_info.get('port-id'):
net_data['port'] = nic_info['port-id']
all_net_data.append(net_data)

View File

@ -137,9 +137,10 @@ def _boot(cs, args):
for nic_str in args.nics:
err_msg = ("Invalid nic argument '%s'. Nic arguments must be of the "
"form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
"port-id=port-uuid>, with at minimum net-id or port-id "
"specified." % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "port-id": ""}
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
"net-id or port-id specified." % nic_str)
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
"port-id": ""}
for kv_str in nic_str.split(","):
try:
@ -268,7 +269,8 @@ def _boot(cs, args):
metavar='<key=value>',
help="Send arbitrary key/value pairs to the scheduler for custom use.")
@utils.arg('--nic',
metavar="<net-id=net-uuid,v4-fixed-ip=ip-addr,port-id=port-uuid>",
metavar="<net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,"
"port-id=port-uuid>",
action='append',
dest='nics',
default=[],
@ -277,6 +279,7 @@ def _boot(cs, args):
"net-id: attach NIC to network with this UUID "
"(required if no port-id), "
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
"v6-fixed-ip: IPv6 fixed address for NIC (optional), "
"port-id: attach NIC to port with this UUID "
"(required if no net-id)")
@utils.arg('--config-drive',