Add support for new fields in network create
Also adds missing network-delete shell command. Additionally changes the type of vlan and vlan_start to int to match the api samples. Partially-implements blueprint better-support-for-multiple-networks Change-Id: I233614431db4737284cceaf8e6b947f50dd84602
This commit is contained in:
parent
ecb3320df1
commit
c59a0c8748
@ -1710,11 +1710,15 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'id': '1'}]})
|
||||
|
||||
def delete_os_networks_1(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
def post_os_networks(self, **kw):
|
||||
return (202, {}, {'network': kw})
|
||||
|
||||
def get_os_networks_1(self, **kw):
|
||||
return (200, {}, {'network': {"label": "1", "cidr": "10.0.0.0/24"}})
|
||||
return (200, {}, {'network': {"label": "1", "cidr": "10.0.0.0/24",
|
||||
"id": "1"}})
|
||||
|
||||
def delete_os_networks_networkdelete(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
@ -59,7 +59,13 @@ class NetworksTest(utils.FixturedTestCase):
|
||||
'project_id': '1',
|
||||
'vlan': 5,
|
||||
'vlan_start': 1,
|
||||
'vpn_start': 1
|
||||
'vpn_start': 1,
|
||||
'mtu': 1500,
|
||||
'enable_dhcp': 'T',
|
||||
'dhcp_server': '1920.2.2',
|
||||
'share_address': 'T',
|
||||
'allowed_start': '192.0.2.10',
|
||||
'allowed_end': '192.0.2.20',
|
||||
}
|
||||
|
||||
f = self.cs.networks.create(**params)
|
||||
|
@ -1757,16 +1757,32 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('network-create --fixed-range-v4 192.168.0.0/24'
|
||||
' --vlan=200 new_network')
|
||||
body = {'network': {'cidr': '192.168.0.0/24', 'label': 'new_network',
|
||||
'vlan': '200'}}
|
||||
'vlan': 200}}
|
||||
self.assert_called('POST', '/os-networks', body)
|
||||
|
||||
def test_network_create_vlan_start(self):
|
||||
self.run_command('network-create --fixed-range-v4 192.168.0.0/24'
|
||||
' --vlan-start=100 new_network')
|
||||
body = {'network': {'cidr': '192.168.0.0/24', 'label': 'new_network',
|
||||
'vlan_start': '100'}}
|
||||
'vlan_start': 100}}
|
||||
self.assert_called('POST', '/os-networks', body)
|
||||
|
||||
def test_network_create_extra_args(self):
|
||||
self.run_command('network-create --fixed-range-v4 192.168.0.0/24'
|
||||
' --enable-dhcp F --dhcp-server 192.168.0.2'
|
||||
' --share-address T --allowed-start 192.168.0.10'
|
||||
' --allowed-end 192.168.0.20 --mtu 9000 new_network')
|
||||
body = {'network': {'cidr': '192.168.0.0/24', 'label': 'new_network',
|
||||
'enable_dhcp': False, 'dhcp_server': '192.168.0.2',
|
||||
'share_address': True, 'mtu': 9000,
|
||||
'allowed_start': '192.168.0.10',
|
||||
'allowed_end': '192.168.0.20'}}
|
||||
self.assert_called('POST', '/os-networks', body)
|
||||
|
||||
def test_network_delete(self):
|
||||
self.run_command('network-delete 1')
|
||||
self.assert_called('DELETE', '/os-networks/1')
|
||||
|
||||
def test_add_fixed_ip(self):
|
||||
self.run_command('add-fixed-ip sample-server 1')
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
|
@ -26,7 +26,7 @@ class Network(base.Resource):
|
||||
"""
|
||||
A network.
|
||||
"""
|
||||
HUMAN_ID = False
|
||||
HUMAN_ID = True
|
||||
NAME_ATTR = "label"
|
||||
|
||||
def __repr__(self):
|
||||
@ -89,8 +89,14 @@ class NetworkManager(base.ManagerWithFind):
|
||||
:param vlan: int
|
||||
:param vlan_start: int
|
||||
:param vpn_start: int
|
||||
:param mtu: int
|
||||
:param enable_dhcp: int
|
||||
:param dhcp_server: str
|
||||
:param share_address: int
|
||||
:param allowed_start: str
|
||||
:param allowed_end: str
|
||||
|
||||
:rtype: list of :class:`Network`
|
||||
:rtype: object of :class:`Network`
|
||||
"""
|
||||
body = {"network": kwargs}
|
||||
return self._create('/os-networks', body, 'network')
|
||||
|
@ -794,6 +794,15 @@ def do_network_show(cs, args):
|
||||
utils.print_dict(network._info)
|
||||
|
||||
|
||||
@utils.arg('network',
|
||||
metavar='<network>',
|
||||
help=_("uuid or label of network"))
|
||||
def do_network_delete(cs, args):
|
||||
"""Delete network by label or id."""
|
||||
network = utils.find_resource(cs.networks, args.network)
|
||||
network.delete()
|
||||
|
||||
|
||||
@utils.arg('--host-only',
|
||||
dest='host_only',
|
||||
metavar='<0|1>',
|
||||
@ -844,7 +853,8 @@ def _filter_network_create_options(args):
|
||||
valid_args = ['label', 'cidr', 'vlan_start', 'vpn_start', 'cidr_v6',
|
||||
'gateway', 'gateway_v6', 'bridge', 'bridge_interface',
|
||||
'multi_host', 'dns1', 'dns2', 'uuid', 'fixed_cidr',
|
||||
'project_id', 'priority', 'vlan']
|
||||
'project_id', 'priority', 'vlan', 'mtu', 'dhcp_server',
|
||||
'allowed_start', 'allowed_end']
|
||||
kwargs = {}
|
||||
for k, v in args.__dict__.items():
|
||||
if k in valid_args and v is not None:
|
||||
@ -865,15 +875,18 @@ def _filter_network_create_options(args):
|
||||
help=_('IPv6 subnet (ex: fe80::/64'))
|
||||
@utils.arg('--vlan',
|
||||
dest='vlan',
|
||||
type=int,
|
||||
metavar='<vlan id>',
|
||||
help=_("vlan id to be assigned to project"))
|
||||
@utils.arg('--vlan-start',
|
||||
dest='vlan_start',
|
||||
type=int,
|
||||
metavar='<vlan start>',
|
||||
help=_('First vlan ID to be assigned to project. Subsequent vlan'
|
||||
' IDs will be assigned incrementally'))
|
||||
@utils.arg('--vpn',
|
||||
dest='vpn_start',
|
||||
type=int,
|
||||
metavar='<vpn start>',
|
||||
help=_("vpn start"))
|
||||
@utils.arg('--gateway',
|
||||
@ -917,6 +930,27 @@ def _filter_network_create_options(args):
|
||||
dest="priority",
|
||||
metavar="<number>",
|
||||
help=_('Network interface priority'))
|
||||
@utils.arg('--mtu',
|
||||
dest="mtu",
|
||||
type=int,
|
||||
help=_('MTU for network'))
|
||||
@utils.arg('--enable-dhcp',
|
||||
dest="enable_dhcp",
|
||||
metavar="<'T'|'F'>",
|
||||
help=_('Enable dhcp'))
|
||||
@utils.arg('--dhcp-server',
|
||||
dest="dhcp_server",
|
||||
help=_('Dhcp-server (defaults to gateway address)'))
|
||||
@utils.arg('--share-address',
|
||||
dest="share_address",
|
||||
metavar="<'T'|'F'>",
|
||||
help=_('Share address'))
|
||||
@utils.arg('--allowed-start',
|
||||
dest="allowed_start",
|
||||
help=_('Start of allowed addresses for instances'))
|
||||
@utils.arg('--allowed-end',
|
||||
dest="allowed_end",
|
||||
help=_('End of allowed addresses for instances'))
|
||||
def do_network_create(cs, args):
|
||||
"""Create a network."""
|
||||
|
||||
@ -927,6 +961,12 @@ def do_network_create(cs, args):
|
||||
if args.multi_host is not None:
|
||||
kwargs['multi_host'] = bool(args.multi_host == 'T' or
|
||||
strutils.bool_from_string(args.multi_host))
|
||||
if args.enable_dhcp is not None:
|
||||
kwargs['enable_dhcp'] = bool(args.enable_dhcp == 'T' or
|
||||
strutils.bool_from_string(args.enable_dhcp))
|
||||
if args.share_address is not None:
|
||||
kwargs['share_address'] = bool(args.share_address == 'T' or
|
||||
strutils.bool_from_string(args.share_address))
|
||||
|
||||
cs.networks.create(**kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user