Merge "Add disable floating ip parameter"
This commit is contained in:
commit
e3202b95e1
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient.exceptions import InvalidAttribute
|
||||
from magnumclient.i18n import _
|
||||
|
||||
from osc_lib.command import command
|
||||
@ -209,10 +210,17 @@ class CreateClusterTemplate(command.ShowOne):
|
||||
parser.add_argument(
|
||||
'--floating-ip-enabled',
|
||||
dest='floating_ip_enabled',
|
||||
action='store_true',
|
||||
default=True,
|
||||
default=[],
|
||||
action='append_const',
|
||||
const=True,
|
||||
help=_('Indicates whether created Clusters should have a '
|
||||
'floating ip or not.'))
|
||||
'floating ip.'))
|
||||
parser.add_argument(
|
||||
'--floating-ip-disabled',
|
||||
dest='floating_ip_enabled',
|
||||
action='append_const',
|
||||
const=False,
|
||||
help=_('Disables floating ip creation on the new Cluster'))
|
||||
|
||||
return parser
|
||||
|
||||
@ -243,8 +251,15 @@ class CreateClusterTemplate(command.ShowOne):
|
||||
'registry_enabled': parsed_args.registry_enabled,
|
||||
'server_type': parsed_args.server_type,
|
||||
'master_lb_enabled': parsed_args.master_lb_enabled,
|
||||
'floating_ip_enabled': parsed_args.floating_ip_enabled,
|
||||
}
|
||||
if len(parsed_args.floating_ip_enabled) > 1:
|
||||
raise InvalidAttribute('--floating-ip-enabled and '
|
||||
'--floating-ip-disabled are '
|
||||
'mutually exclusive and '
|
||||
'should be specified only once.')
|
||||
elif len(parsed_args.floating_ip_enabled) == 1:
|
||||
args['floating_ip_enabled'] = parsed_args.floating_ip_enabled[0]
|
||||
|
||||
ct = mag_client.cluster_templates.create(**args)
|
||||
print("Request to create cluster template %s accepted"
|
||||
% parsed_args.name)
|
||||
|
@ -17,6 +17,7 @@ import copy
|
||||
import mock
|
||||
from mock import call
|
||||
|
||||
from magnumclient.exceptions import InvalidAttribute
|
||||
from magnumclient.osc.v1 import cluster_templates as osc_ct
|
||||
from magnumclient.tests.osc.unit.v1 import fakes as magnum_fakes
|
||||
|
||||
@ -33,7 +34,6 @@ class TestClusterTemplate(magnum_fakes.TestMagnumClientOSCV1):
|
||||
'fixed_network': None,
|
||||
'fixed_subnet': None,
|
||||
'flavor_id': 'm1.medium',
|
||||
'floating_ip_enabled': True,
|
||||
'http_proxy': None,
|
||||
'https_proxy': None,
|
||||
'image_id': 'fedora-atomic-latest',
|
||||
@ -134,6 +134,33 @@ class TestClusterTemplateCreate(TestClusterTemplate):
|
||||
self.assertRaises(magnum_fakes.MagnumParseException,
|
||||
self.check_parser, self.cmd, arglist, verifylist)
|
||||
|
||||
def test_cluster_template_create_floating_ips(self):
|
||||
"""Verifies floating ip parameters."""
|
||||
arglist = [
|
||||
'--coe', self.new_ct.coe,
|
||||
'--external-network', self.new_ct.external_network_id,
|
||||
'--image', self.new_ct.image_id,
|
||||
'--floating-ip-enabled',
|
||||
self.new_ct.name
|
||||
]
|
||||
verifylist = [
|
||||
('coe', self.new_ct.coe),
|
||||
('external_network', self.new_ct.external_network_id),
|
||||
('image', self.new_ct.image_id),
|
||||
('floating_ip_enabled', [True]),
|
||||
('name', self.new_ct.name)
|
||||
]
|
||||
self.default_create_args['floating_ip_enabled'] = True
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.default_create_args.pop('floating_ip_enabled')
|
||||
|
||||
arglist.append('--floating-ip-disabled')
|
||||
verifylist.remove(('floating_ip_enabled', [True]))
|
||||
verifylist.append(('floating_ip_enabled', [True, False]))
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(InvalidAttribute, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestClusterTemplateDelete(TestClusterTemplate):
|
||||
|
||||
|
@ -57,8 +57,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
https_proxy=None, no_proxy=None, labels={},
|
||||
tls_disabled=False, public=False,
|
||||
master_lb_enabled=False, server_type='vm',
|
||||
floating_ip_enabled=True,
|
||||
registry_enabled=False):
|
||||
registry_enabled=False, floating_ip_enabled=None):
|
||||
|
||||
expected_args = {}
|
||||
expected_args['image_id'] = image_id
|
||||
@ -83,7 +82,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
expected_args['public'] = public
|
||||
expected_args['master_lb_enabled'] = master_lb_enabled
|
||||
expected_args['server_type'] = server_type
|
||||
expected_args['floating_ip_enabled'] = floating_ip_enabled
|
||||
expected_args['registry_enabled'] = registry_enabled
|
||||
|
||||
return expected_args
|
||||
@ -125,8 +123,8 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
docker_storage_driver='devicemapper',
|
||||
docker_volume_size=10,
|
||||
master_lb_enabled=True,
|
||||
floating_ip_enabled=True,
|
||||
labels={'key': 'val'})
|
||||
expected_args['floating_ip_enabled'] = True
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('baymodel-create '
|
||||
@ -144,6 +142,23 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
server_type='vm')
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
self._test_arg_success('baymodel-create '
|
||||
'--keypair-id test_keypair '
|
||||
'--external-network-id test_net '
|
||||
'--image-id test_image '
|
||||
'--coe kubernetes '
|
||||
'--name test '
|
||||
'--server-type vm '
|
||||
'--floating-ip-disabled ')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair',
|
||||
coe='kubernetes',
|
||||
external_network_id='test_net',
|
||||
server_type='vm',
|
||||
floating_ip_enabled=False)
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
@mock.patch('magnumclient.v1.baymodels.BayModelManager.create')
|
||||
def test_baymodel_create_success_no_servertype(self, mock_create):
|
||||
self._test_arg_success('baymodel-create '
|
||||
|
@ -57,7 +57,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
https_proxy=None, no_proxy=None, labels={},
|
||||
tls_disabled=False, public=False,
|
||||
master_lb_enabled=False, server_type='vm',
|
||||
floating_ip_enabled=True,
|
||||
registry_enabled=False,
|
||||
insecure_registry=None):
|
||||
|
||||
@ -84,7 +83,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
expected_args['public'] = public
|
||||
expected_args['master_lb_enabled'] = master_lb_enabled
|
||||
expected_args['server_type'] = server_type
|
||||
expected_args['floating_ip_enabled'] = floating_ip_enabled
|
||||
expected_args['registry_enabled'] = registry_enabled
|
||||
expected_args['insecure_registry'] = insecure_registry
|
||||
|
||||
@ -111,8 +109,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
'--docker-storage-driver devicemapper '
|
||||
'--public '
|
||||
'--server-type vm '
|
||||
'--master-lb-enabled '
|
||||
'--floating-ip-enabled ')
|
||||
'--master-lb-enabled ')
|
||||
expected_args = \
|
||||
self._get_expected_args(name='test', image_id='test_image',
|
||||
keypair_id='test_keypair', coe='swarm',
|
||||
@ -128,7 +125,6 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
|
||||
docker_storage_driver='devicemapper',
|
||||
docker_volume_size=10,
|
||||
master_lb_enabled=True,
|
||||
floating_ip_enabled=True,
|
||||
labels={'key': 'val'})
|
||||
mock_create.assert_called_with(**expected_args)
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from magnumclient.common import cliutils as utils
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient.exceptions import InvalidAttribute
|
||||
from magnumclient.i18n import _
|
||||
from magnumclient.v1 import basemodels
|
||||
|
||||
@ -121,9 +122,18 @@ def _show_baymodel(baymodel):
|
||||
help=_('Indicates whether created bays should have a load balancer '
|
||||
'for master nodes or not.'))
|
||||
@utils.arg('--floating-ip-enabled',
|
||||
action='store_true', default=True,
|
||||
action='append_const',
|
||||
dest='floating_ip_enabled',
|
||||
const=True,
|
||||
default=[],
|
||||
help=_('Indicates whether created bays should have a floating ip'
|
||||
'or not.'))
|
||||
@utils.arg('--floating-ip-disabled',
|
||||
action='append_const',
|
||||
dest='floatin_ip_disabled',
|
||||
const=False,
|
||||
default=[],
|
||||
help=_('Disables floating ip creation on the new Cluster'))
|
||||
@utils.deprecated(DEPRECATION_MESSAGE)
|
||||
def do_baymodel_create(cs, args):
|
||||
"""Create a baymodel.
|
||||
@ -154,7 +164,14 @@ def do_baymodel_create(cs, args):
|
||||
opts['registry_enabled'] = args.registry_enabled
|
||||
opts['server_type'] = args.server_type
|
||||
opts['master_lb_enabled'] = args.master_lb_enabled
|
||||
opts['floating_ip_enabled'] = args.floating_ip_enabled
|
||||
|
||||
if len(args.floating_ip_enabled) > 1:
|
||||
raise InvalidAttribute('--floating-ip-enabled and '
|
||||
'--floating-ip-disabled are '
|
||||
'mutually exclusive and '
|
||||
'should be specified only once.')
|
||||
elif len(args.floating_ip_enabled) == 1:
|
||||
opts['floating_ip_enabled'] = args.floating_ip_enabled[0]
|
||||
|
||||
baymodel = cs.baymodels.create(**opts)
|
||||
_show_baymodel(baymodel)
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
from magnumclient.common import cliutils as utils
|
||||
from magnumclient.common import utils as magnum_utils
|
||||
from magnumclient.exceptions import InvalidAttribute
|
||||
from magnumclient.i18n import _
|
||||
from magnumclient.v1 import basemodels
|
||||
|
||||
|
||||
# Maps old parameter names to their new names and whether they are required
|
||||
DEPRECATING_PARAMS = {
|
||||
"--external-network-id": "--external-network",
|
||||
@ -172,9 +172,18 @@ def _show_cluster_template(cluster_template):
|
||||
help=_('Indicates whether created Clusters should have a load '
|
||||
'balancer for master nodes or not.'))
|
||||
@utils.arg('--floating-ip-enabled',
|
||||
action='store_true', default=True,
|
||||
action='append_const',
|
||||
const=True,
|
||||
default=[],
|
||||
dest='floating_ip_enabled',
|
||||
help=_('Indicates whether created Clusters should have a '
|
||||
'floating ip or not.'))
|
||||
'floating ip.'))
|
||||
@utils.arg('--floating-ip-disabled',
|
||||
action='append_const',
|
||||
const=False,
|
||||
default=[],
|
||||
dest='floating_ip_enabled',
|
||||
help=_('Disables floating ip creation on the new Cluster'))
|
||||
@utils.arg('--insecure-registry',
|
||||
metavar='<insecure-registry>',
|
||||
help='url of docker registry')
|
||||
@ -208,9 +217,16 @@ def do_cluster_template_create(cs, args):
|
||||
opts['registry_enabled'] = args.registry_enabled
|
||||
opts['server_type'] = args.server_type
|
||||
opts['master_lb_enabled'] = args.master_lb_enabled
|
||||
opts['floating_ip_enabled'] = args.floating_ip_enabled
|
||||
opts['insecure_registry'] = args.insecure_registry
|
||||
|
||||
if len(args.floating_ip_enabled) > 1:
|
||||
raise InvalidAttribute('--floating-ip-enabled and '
|
||||
'--floating-ip-disabled are '
|
||||
'mutually exclusive and '
|
||||
'should be specified only once.')
|
||||
elif len(args.floating_ip_enabled) == 1:
|
||||
opts['floating_ip_enabled'] = args.floating_ip_enabled[0]
|
||||
|
||||
cluster_template = cs.cluster_templates.create(**opts)
|
||||
_show_cluster_template(cluster_template)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user