예제 #1
0
 def take_action(self, parsed_args):
     client = self.get_client()
     extra_values = v2_0.parse_args_to_dict(self.values_specs)
     if extra_values:
         raise exceptions.CommandError(
             _("Invalid argument(s): --%s") % ', --'.join(extra_values))
     tenant_id = parsed_args.tenant_id or parsed_args.pos_tenant_id
     if parsed_args.dry_run:
         data = client.validate_auto_allocated_topology_requirements(
             tenant_id)
     else:
         data = client.get_auto_allocated_topology(tenant_id)
     if self.resource in data:
         for k, v in data[self.resource].items():
             if isinstance(v, list):
                 value = ""
                 for _item in v:
                     if value:
                         value += "\n"
                     if isinstance(_item, dict):
                         value += jsonutils.dumps(_item)
                     else:
                         value += str(_item)
                 data[self.resource][k] = value
             elif v == "dry-run=pass":
                 return ("dry-run", ), ("pass", )
             elif v is None:
                 data[self.resource][k] = ''
         return zip(*sorted(data[self.resource].items()))
     else:
         return None
 def test_int_and_str(self):
     _specs = [
         '--my-int', 'type=int', '10', '--my-str', 'type=str', 'value1'
     ]
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(10, _mydict['my_int'])
     self.assertEqual('value1', _mydict['my_str'])
예제 #3
0
 def take_action(self, parsed_args):
     neutron_client = self.get_client()
     _extra_values = neutronV20.parse_args_to_dict(self.values_specs)
     neutronV20._merge_args(self, parsed_args, _extra_values,
                            self.values_specs)
     body = self.args2body(parsed_args)
     if self.resource in body:
         body[self.resource].update(_extra_values)
     else:
         body[self.resource] = _extra_values
     obj_updator = getattr(neutron_client, "update_%s" % self.resource)
     tenant_id = get_tenant_id(parsed_args, neutron_client)
     data = obj_updator(tenant_id, body)
     if self.resource in data:
         for k, v in six.iteritems(data[self.resource]):
             if isinstance(v, list):
                 value = ""
                 for _item in v:
                     if value:
                         value += "\n"
                     if isinstance(_item, dict):
                         value += jsonutils.dumps(_item)
                     else:
                         value += str(_item)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
         return zip(*sorted(six.iteritems(data[self.resource])))
     else:
         return
예제 #4
0
 def get_data(self, parsed_args):
     self.log.debug('run(%s)', parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     _extra_values = neutronV20.parse_args_to_dict(self.values_specs)
     neutronV20._merge_args(self, parsed_args, _extra_values,
                            self.values_specs)
     body = self.args2body(parsed_args)
     if self.resource in body:
         body[self.resource].update(_extra_values)
     else:
         body[self.resource] = _extra_values
     obj_updator = getattr(neutron_client, "update_%s" % self.resource)
     tenant_id = get_tenant_id(parsed_args.tenant_id, neutron_client)
     data = obj_updator(tenant_id, body)
     if self.resource in data:
         for k, v in data[self.resource].iteritems():
             if isinstance(v, list):
                 value = ""
                 for _item in v:
                     if value:
                         value += "\n"
                     if isinstance(_item, dict):
                         value += utils.dumps(_item)
                     else:
                         value += str(_item)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
         return zip(*sorted(data[self.resource].iteritems()))
     else:
         return None
예제 #5
0
 def get_data(self, parsed_args):
     self.log.debug('run(%s)', parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     _extra_values = neutronV20.parse_args_to_dict(self.values_specs)
     neutronV20._merge_args(self, parsed_args, _extra_values,
                            self.values_specs)
     body = self.args2body(parsed_args)
     if self.resource in body:
         body[self.resource].update(_extra_values)
     else:
         body[self.resource] = _extra_values
     obj_updator = getattr(neutron_client,
                           "update_%s" % self.resource)
     tenant_id = get_tenant_id(parsed_args.tenant_id,
                               neutron_client)
     data = obj_updator(tenant_id, body)
     if self.resource in data:
         for k, v in six.iteritems(data[self.resource]):
             if isinstance(v, list):
                 value = ""
                 for _item in v:
                     if value:
                         value += "\n"
                     if isinstance(_item, dict):
                         value += jsonutils.dumps(_item)
                     else:
                         value += str(_item)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
         return zip(*sorted(six.iteritems(data[self.resource])))
     else:
         return None
 def take_action(self, parsed_args):
     client = self.get_client()
     extra_values = v2_0.parse_args_to_dict(self.values_specs)
     if extra_values:
         raise exceptions.CommandError(
             _("Invalid argument(s): --%s") % ', --'.join(extra_values))
     tenant_id = parsed_args.tenant_id or parsed_args.pos_tenant_id
     if parsed_args.dry_run:
         data = client.validate_auto_allocated_topology_requirements(
             tenant_id)
     else:
         data = client.get_auto_allocated_topology(tenant_id)
     if self.resource in data:
         for k, v in data[self.resource].items():
             if isinstance(v, list):
                 value = ""
                 for _item in v:
                     if value:
                         value += "\n"
                     if isinstance(_item, dict):
                         value += jsonutils.dumps(_item)
                     else:
                         value += str(_item)
                 data[self.resource][k] = value
             elif v == "dry-run=pass":
                 return ("dry-run",), ("pass",)
             elif v is None:
                 data[self.resource][k] = ''
         return zip(*sorted(data[self.resource].items()))
     else:
         return None
 def test_list_of_dict_arg(self):
     _specs = [
         '--tag=t', '--arg1', 'type=dict', 'list=true',
         'key1=value1,key2=value2'
     ]
     arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
     self.assertEqual('value1', arg1[0]['key1'])
     self.assertEqual('value2', arg1[0]['key2'])
 def run(self, parsed_args):
     self.log.debug('run(%s)' % parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     data = {self.resource: parse_args_to_dict(parsed_args)}
     if parsed_args.remove_tenant:
         data[self.resource]['remove_tenant'] = parsed_args.remove_tenant
     neutron_client.update_network_profile(parsed_args.id,
                                           {self.resource: data})
     print((_('Updated %(resource)s: %(id)s') %
            {'id': parsed_args.id, 'resource': self.resource}),
           file=self.app.stdout)
     return
 def run(self, parsed_args):
     self.log.debug('run(%s)' % parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     data = {self.resource: parse_args_to_dict(parsed_args)}
     if parsed_args.remove_tenant:
         data[self.resource]['remove_tenant'] = parsed_args.remove_tenant
     neutron_client.update_network_profile(parsed_args.id,
                                           {self.resource: data})
     print((_('Updated %(resource)s: %(id)s') %
            {'id': parsed_args.id, 'resource': self.resource}),
           file=self.app.stdout)
     return
 def run(self, parsed_args):
     self.log.debug("run(%s)" % parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     data = {self.resource: parse_args_to_dict(parsed_args)}
     if parsed_args.remove_tenant:
         data[self.resource]["remove_tenant"] = parsed_args.remove_tenant
     neutron_client.update_network_profile(parsed_args.id, {self.resource: data})
     print(
         (_("Updated %(resource)s: %(id)s") % {"id": parsed_args.id, "resource": self.resource}),
         file=self.app.stdout,
     )
     return
예제 #11
0
    def take_action(self, parsed_args):
        neutron_client = self.get_client()
        filters = {}
        if parsed_args.for_subnet:
            resource = subnet.ListSubnet.resource
            subnet_id = neutronV20.find_resourceid_by_name_or_id(
                neutron_client, resource, parsed_args.for_subnet)
            filters['for_subnet'] = [subnet_id]
        elif parsed_args.for_port:
            resource = port.ListPort.resource
            port_id = neutronV20.find_resourceid_by_name_or_id(
                neutron_client, resource, parsed_args.for_port)
            filters['for_port'] = [port_id]

        filters.update(neutronV20.parse_args_to_dict(self.values_specs))
        fips = neutron_client.list_nuage_floatingips(
            **filters)[self.resource_plural]
        return self.setup_columns(fips, parsed_args)
 def test_bool_false(self):
     _specs = ["--my_bool", "type=bool", "false", "--arg1", "value1"]
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertFalse(_mydict["my_bool"])
 def test_dict_arg_with_attribute_named_type(self):
     _specs = ['--tag=t', '--arg1', 'type=dict', 'type=value1,key2=value2']
     arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
     self.assertEqual('value1', arg1['type'])
     self.assertEqual('value2', arg1['key2'])
 def test_arg(self):
     _specs = ['--tag=t', '--arg1', 'value1']
     self.assertEqual('value1',
                      neutronV20.parse_args_to_dict(_specs)['arg1'])
 def test_goodarg_with_minus_number(self):
     _specs = ['--arg1', 'value1', '-1', '-1.0']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(['value1', '-1', '-1.0'], _mydict['arg1'])
 def test_nargs(self):
     _specs = ['--tag', 'x', 'y', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertIn('x', _mydict['tag'])
     self.assertIn('y', _mydict['tag'])
 def test_nargs(self):
     _specs = ["--tag", "x", "y", "--arg1", "value1"]
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertTrue("x" in _mydict["tag"])
     self.assertTrue("y" in _mydict["tag"])
 def test_clear_action(self):
     _specs = ["--anyarg", "action=clear"]
     args = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(None, args["anyarg"])
 def test_nargs(self):
     _specs = ['--tag', 'x', 'y', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertIn('x', _mydict['tag'])
     self.assertIn('y', _mydict['tag'])
 def test_arg(self):
     _specs = ['--tag=t', '--arg1', 'value1']
     self.assertEqual('value1',
                      neutronV20.parse_args_to_dict(_specs)['arg1'])
 def test_default_bool(self):
     _specs = ['--my_bool', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertTrue(_mydict['my_bool'])
 def test_int_and_str(self):
     _specs = ['--my-int', 'type=int', '10',
               '--my-str', 'type=str', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(10, _mydict['my_int'])
     self.assertEqual('value1', _mydict['my_str'])
 def test_goodarg_with_minus_number(self):
     _specs = ["--arg1", "value1", "-1", "-1.0"]
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(["value1", "-1", "-1.0"], _mydict["arg1"])
 def test_default_bool(self):
     _specs = ["--my_bool", "--arg1", "value1"]
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertTrue(_mydict["my_bool"])
 def test_dict_arg_with_attribute_named_type(self):
     _specs = ["--tag=t", "--arg1", "type=dict", "type=value1,key2=value2"]
     arg1 = neutronV20.parse_args_to_dict(_specs)["arg1"]
     self.assertEqual("value1", arg1["type"])
     self.assertEqual("value2", arg1["key2"])
 def test_list_of_dict_arg(self):
     _specs = ['--tag=t', '--arg1', 'type=dict',
               'list=true', 'key1=value1,key2=value2']
     arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
     self.assertEqual('value1', arg1[0]['key1'])
     self.assertEqual('value2', arg1[0]['key2'])
 def test_list_of_dict_arg(self):
     _specs = ["--tag=t", "--arg1", "type=dict", "list=true", "key1=value1,key2=value2"]
     arg1 = neutronV20.parse_args_to_dict(_specs)["arg1"]
     self.assertEqual("value1", arg1[0]["key1"])
     self.assertEqual("value2", arg1[0]["key2"])
 def test_empty(self):
     _mydict = neutronV20.parse_args_to_dict([])
     self.assertEqual({}, _mydict)
 def test_arg(self):
     _specs = ["--tag=t", "--arg1", "value1"]
     self.assertEqual("value1", neutronV20.parse_args_to_dict(_specs)["arg1"])
 def test_bool_false(self):
     _specs = ['--my_bool', 'type=bool', 'false', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertFalse(_mydict['my_bool'])
 def test_clear_action(self):
     _specs = ['--anyarg', 'action=clear']
     args = neutronV20.parse_args_to_dict(_specs)
     self.assertIsNone(args['anyarg'])
 def test_goodarg_with_minus_number(self):
     _specs = ['--arg1', 'value1', '-1', '-1.0']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(['value1', '-1', '-1.0'],
                      _mydict['arg1'])
 def test_empty(self):
     _mydict = neutronV20.parse_args_to_dict([])
     self.assertEqual({}, _mydict)
 def test_dict_arg_with_attribute_named_type(self):
     _specs = ['--tag=t', '--arg1', 'type=dict', 'type=value1,key2=value2']
     arg1 = neutronV20.parse_args_to_dict(_specs)['arg1']
     self.assertEqual('value1', arg1['type'])
     self.assertEqual('value2', arg1['key2'])
 def test_default_bool(self):
     _specs = ['--my_bool', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertTrue(_mydict['my_bool'])
 def test_clear_action(self):
     _specs = ['--anyarg', 'action=clear']
     args = neutronV20.parse_args_to_dict(_specs)
     self.assertEqual(None, args['anyarg'])
 def test_bool_false(self):
     _specs = ['--my_bool', 'type=bool', 'false', '--arg1', 'value1']
     _mydict = neutronV20.parse_args_to_dict(_specs)
     self.assertFalse(_mydict['my_bool'])