Merge "Support IPv6 when booting instances"
This commit is contained in:
commit
b3c57729c5
@ -104,6 +104,28 @@ class ServersTest(utils.TestCase):
|
|||||||
|
|
||||||
test_create_server_from_volume()
|
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):
|
def test_create_server_userdata_file_object(self):
|
||||||
s = cs.servers.create(
|
s = cs.servers.create(
|
||||||
name="My server",
|
name="My server",
|
||||||
|
@ -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):
|
def test_boot_nics_no_value(self):
|
||||||
cmd = ('boot --image 1 --flavor 1 '
|
cmd = ('boot --image 1 --flavor 1 '
|
||||||
'--nic net-id some-server')
|
'--nic net-id some-server')
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from novaclient import exceptions
|
from novaclient import exceptions
|
||||||
@ -74,6 +75,50 @@ class ServersTest(utils.TestCase):
|
|||||||
cs.assert_called('POST', '/servers')
|
cs.assert_called('POST', '/servers')
|
||||||
self.assertIsInstance(s, servers.Server)
|
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):
|
def test_create_server_userdata_file_object(self):
|
||||||
s = cs.servers.create(
|
s = cs.servers.create(
|
||||||
name="My server",
|
name="My server",
|
||||||
|
@ -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):
|
def test_boot_nics_no_value(self):
|
||||||
cmd = ('boot --image 1 --flavor 1 '
|
cmd = ('boot --image 1 --flavor 1 '
|
||||||
'--nic net-id some-server')
|
'--nic net-id some-server')
|
||||||
|
@ -26,6 +26,7 @@ from six.moves.urllib import parse
|
|||||||
|
|
||||||
from novaclient import base
|
from novaclient import base
|
||||||
from novaclient import crypto
|
from novaclient import crypto
|
||||||
|
from novaclient.openstack.common.gettextutils import _
|
||||||
from novaclient.openstack.common import strutils
|
from novaclient.openstack.common import strutils
|
||||||
from novaclient.v1_1.security_groups import SecurityGroup
|
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 value is empty string, do not send value in body
|
||||||
if nic_info.get('net-id'):
|
if nic_info.get('net-id'):
|
||||||
net_data['uuid'] = nic_info['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']
|
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'):
|
if nic_info.get('port-id'):
|
||||||
net_data['port'] = nic_info['port-id']
|
net_data['port'] = nic_info['port-id']
|
||||||
all_net_data.append(net_data)
|
all_net_data.append(net_data)
|
||||||
|
@ -226,9 +226,10 @@ def _boot(cs, args):
|
|||||||
for nic_str in args.nics:
|
for nic_str in args.nics:
|
||||||
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
|
err_msg = (_("Invalid nic argument '%s'. Nic arguments must be of "
|
||||||
"the form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
|
"the form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
|
||||||
"port-id=port-uuid>, with at minimum net-id or port-id "
|
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
|
||||||
"specified.") % nic_str)
|
"net-id or port-id specified.") % nic_str)
|
||||||
nic_info = {"net-id": "", "v4-fixed-ip": "", "port-id": ""}
|
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
|
||||||
|
"port-id": ""}
|
||||||
|
|
||||||
for kv_str in nic_str.split(","):
|
for kv_str in nic_str.split(","):
|
||||||
try:
|
try:
|
||||||
@ -392,7 +393,8 @@ def _boot(cs, args):
|
|||||||
help=_("Send arbitrary key/value pairs to the scheduler for custom "
|
help=_("Send arbitrary key/value pairs to the scheduler for custom "
|
||||||
"use."))
|
"use."))
|
||||||
@utils.arg('--nic',
|
@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',
|
action='append',
|
||||||
dest='nics',
|
dest='nics',
|
||||||
default=[],
|
default=[],
|
||||||
@ -401,6 +403,7 @@ def _boot(cs, args):
|
|||||||
"net-id: attach NIC to network with this UUID "
|
"net-id: attach NIC to network with this UUID "
|
||||||
"(required if no port-id), "
|
"(required if no port-id), "
|
||||||
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
|
"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 "
|
"port-id: attach NIC to port with this UUID "
|
||||||
"(required if no net-id)"))
|
"(required if no net-id)"))
|
||||||
@utils.arg('--config-drive',
|
@utils.arg('--config-drive',
|
||||||
|
@ -26,6 +26,7 @@ from six.moves.urllib import parse
|
|||||||
|
|
||||||
from novaclient import base
|
from novaclient import base
|
||||||
from novaclient import crypto
|
from novaclient import crypto
|
||||||
|
from novaclient.openstack.common.gettextutils import _
|
||||||
from novaclient.openstack.common import strutils
|
from novaclient.openstack.common import strutils
|
||||||
|
|
||||||
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
|
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 value is empty string, do not send value in body
|
||||||
if nic_info.get('net-id'):
|
if nic_info.get('net-id'):
|
||||||
net_data['uuid'] = nic_info['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']
|
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'):
|
if nic_info.get('port-id'):
|
||||||
net_data['port'] = nic_info['port-id']
|
net_data['port'] = nic_info['port-id']
|
||||||
all_net_data.append(net_data)
|
all_net_data.append(net_data)
|
||||||
|
@ -137,9 +137,10 @@ def _boot(cs, args):
|
|||||||
for nic_str in args.nics:
|
for nic_str in args.nics:
|
||||||
err_msg = ("Invalid nic argument '%s'. Nic arguments must be of the "
|
err_msg = ("Invalid nic argument '%s'. Nic arguments must be of the "
|
||||||
"form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
|
"form --nic <net-id=net-uuid,v4-fixed-ip=ip-addr,"
|
||||||
"port-id=port-uuid>, with at minimum net-id or port-id "
|
"v6-fixed-ip=ip-addr,port-id=port-uuid>, with at minimum "
|
||||||
"specified." % nic_str)
|
"net-id or port-id specified." % nic_str)
|
||||||
nic_info = {"net-id": "", "v4-fixed-ip": "", "port-id": ""}
|
nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "",
|
||||||
|
"port-id": ""}
|
||||||
|
|
||||||
for kv_str in nic_str.split(","):
|
for kv_str in nic_str.split(","):
|
||||||
try:
|
try:
|
||||||
@ -268,7 +269,8 @@ def _boot(cs, args):
|
|||||||
metavar='<key=value>',
|
metavar='<key=value>',
|
||||||
help="Send arbitrary key/value pairs to the scheduler for custom use.")
|
help="Send arbitrary key/value pairs to the scheduler for custom use.")
|
||||||
@utils.arg('--nic',
|
@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',
|
action='append',
|
||||||
dest='nics',
|
dest='nics',
|
||||||
default=[],
|
default=[],
|
||||||
@ -277,6 +279,7 @@ def _boot(cs, args):
|
|||||||
"net-id: attach NIC to network with this UUID "
|
"net-id: attach NIC to network with this UUID "
|
||||||
"(required if no port-id), "
|
"(required if no port-id), "
|
||||||
"v4-fixed-ip: IPv4 fixed address for NIC (optional), "
|
"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 "
|
"port-id: attach NIC to port with this UUID "
|
||||||
"(required if no net-id)")
|
"(required if no net-id)")
|
||||||
@utils.arg('--config-drive',
|
@utils.arg('--config-drive',
|
||||||
|
Loading…
Reference in New Issue
Block a user