Beispiel #1
0
 def format_output_data(self, data):
     # Modify data to make it more readable
     if self.resource in data:
         for k, v in data[self.resource].iteritems():
             if isinstance(v, list):
                 value = '\n'.join(utils.dumps(
                     i, indent=self.json_indent) if isinstance(i, dict)
                     else str(i) for i in v)
                 data[self.resource][k] = value
             elif isinstance(v, dict):
                 value = utils.dumps(v, indent=self.json_indent)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
 def format_output_data(self, data):
     # Modify data to make it more readable
     if self.resource in data:
         for k, v in six.iteritems(data[self.resource]):
             if isinstance(v, list):
                 value = '\n'.join(utils.dumps(
                     i, indent=self.json_indent) if isinstance(i, dict)
                     else str(i) for i in v)
                 data[self.resource][k] = value
             elif isinstance(v, dict):
                 value = utils.dumps(v, indent=self.json_indent)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
Beispiel #3
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
Beispiel #4
0
 def get_data(self, parsed_args):
     self.log.debug('get_data(%s)', parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     tenant_id = get_tenant_id(parsed_args.tenant_id, neutron_client)
     params = {}
     obj_shower = getattr(neutron_client, "show_%s" % self.resource)
     data = obj_shower(tenant_id, **params)
     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
 def get_data(self, parsed_args):
     self.log.debug('get_data(%s)', parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     vcenter_id = parsed_args.id
     params = {}
     obj_shower = getattr(neutron_client,
                          "show_%s" % self.resource)
     data = obj_shower(vcenter_id, **params)
     try:
         if data[self.resource] == {}:
             raise Exception()
         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 += utils.dumps(_item)
                         else:
                             value += str(_item)
                     data[self.resource][k] = value
                 elif v is None:
                     data[self.resource][k] = ''
     except Exception:
         not_found_message = (_("Unable to find %(resource)s with vCenter "
                                "name '%(vcenter_id)s'.") %
                              {'resource': self.resource,
                               'vcenter_id': vcenter_id})
         raise exceptions.NeutronClientException(
             message=not_found_message, status_code=404)
     return zip(*sorted(six.iteritems(data[self.resource])))
 def execute(self, parsed_args):
     self.log.debug('execute(%s)', parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     vcenter_id = parsed_args.id
     params = {}
     obj_shower = getattr(neutron_client, "show_%s" % self.resource)
     data = obj_shower(vcenter_id, **params)
     try:
         if data[self.resource] == {}:
             raise Exception()
         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 += utils.dumps(_item)
                         else:
                             value += str(_item)
                     data[self.resource][k] = value
                 elif v is None:
                     data[self.resource][k] = ''
     except Exception:
         not_found_message = (_("Unable to find %(resource)s with vCenter "
                                "name '%(vcenter_id)s'.") % {
                                    'resource': self.resource,
                                    'vcenter_id': vcenter_id
                                })
         raise exceptions.NeutronClientException(message=not_found_message,
                                                 status_code=404)
     return zip(*sorted(six.iteritems(data[self.resource])))
def _format_peer_cidrs(ipsec_site_connection):
    try:
        return '\n'.join([
            utils.dumps(cidrs) for cidrs in ipsec_site_connection['peer_cidrs']
        ])
    except Exception:
        return ''
 def get_data(self, parsed_args):
     self.log.debug('get_data(%s)' % parsed_args)
     neutron_client = self.get_client()
     neutron_client.format = parsed_args.request_format
     tenant_id = get_tenant_id(parsed_args.tenant_id,
                               neutron_client)
     params = {}
     obj_shower = getattr(neutron_client,
                          "show_%s" % self.resource)
     data = obj_shower(tenant_id, **params)
     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
 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
 def test_dumps_dict_with_spaces(self):
     x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7)
     res = utils.dumps({1: 'a ', 2: x})
     expected = '{"1": "a ", "2": "1920-02-03 04:05:06.000007"}'
     self.assertEqual(expected, res)
 def test_dumps(self):
     self.assertEqual(utils.dumps({'a': 'b'}), '{"a": "b"}')
def _format_peer_cidrs(ipsec_site_connection):
    try:
        return "\n".join([utils.dumps(cidrs) for cidrs in ipsec_site_connection["peer_cidrs"]])
    except Exception:
        return ""
Beispiel #13
0
def _format_fixed_ips(port):
    try:
        return '\n'.join([utils.dumps(ip) for ip in port['fixed_ips']])
    except Exception:
        return ''
Beispiel #14
0
def _format_external_gateway_info(router):
    try:
        return utils.dumps(router['external_gateway_info'])
    except Exception:
        return ''
Beispiel #15
0
def _format_fixed_ips_csv(port):
    try:
        return [utils.dumps(ip) for ip in port['fixed_ips']]
    except Exception:
        return ''
Beispiel #16
0
def _format_dns_nameservers(subnet):
    try:
        return '\n'.join([utils.dumps(server) for server in
                          subnet['dns_nameservers']])
    except Exception:
        return ''
Beispiel #17
0
def _format_fixed_ips(port):
    try:
        return '\n'.join([utils.dumps(ip) for ip in port['fixed_ips']])
    except Exception:
        return ''
 def test_dumps(self):
     self.assertEqual(utils.dumps({'a': 'b'}), '{"a": "b"}')
 def test_dumps_dict_with_spaces(self):
     x = datetime.datetime(1920, 2, 3, 4, 5, 6, 7)
     res = utils.dumps({1: 'a ', 2: x})
     expected = '{"1": "a ", "2": "1920-02-03 04:05:06.000007"}'
     self.assertEqual(expected, res)
Beispiel #20
0
def _format_allocation_pools(subnet):
    try:
        return '\n'.join([utils.dumps(pool) for pool in
                          subnet['allocation_pools']])
    except Exception:
        return ''
def _format_peer_cidrs(ipsec_site_connection):
    try:
        return '\n'.join([utils.dumps(cidrs) for cidrs in
                          ipsec_site_connection['peer_cidrs']])
    except Exception:
        return ''
Beispiel #22
0
def _format_host_routes(subnet):
    try:
        return '\n'.join([utils.dumps(route) for route in
                          subnet['host_routes']])
    except Exception:
        return ''
Beispiel #23
0
def _format_fixed_ips_csv(port):
    try:
        return [utils.dumps(ip) for ip in port['fixed_ips']]
    except Exception:
        return ''