Ejemplo n.º 1
0
 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(jsonutils.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 = jsonutils.dumps(v, indent=self.json_indent)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
Ejemplo n.º 2
0
 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(jsonutils.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 = jsonutils.dumps(v, indent=self.json_indent)
                 data[self.resource][k] = value
             elif v is None:
                 data[self.resource][k] = ''
Ejemplo n.º 3
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 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
Ejemplo n.º 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 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
Ejemplo n.º 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
Ejemplo n.º 6
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 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
Ejemplo n.º 7
0
 def default(self, data):
     def sanitizer(obj):
         return six.text_type(obj, 'utf8')
     return jsonutils.dumps(data, default=sanitizer)
Ejemplo n.º 8
0
def _format_host_routes(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(route) for route in subnet['host_routes']])
    except Exception:
        return ''
Ejemplo n.º 9
0
def _create_version_list(versions):
    return jsonutils.dumps({"versions": {"values": versions}})
Ejemplo n.º 10
0
def _format_host_routes(subnet):
    try:
        return '\n'.join([jsonutils.dumps(route) for route in
                          subnet['host_routes']])
    except Exception:
        return ''
Ejemplo n.º 11
0
def _format_allocation_pools(subnet):
    try:
        return '\n'.join([jsonutils.dumps(pool) for pool in
                          subnet['allocation_pools']])
    except Exception:
        return ''
Ejemplo n.º 12
0
def _format_dns_nameservers(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(server) for server in subnet['dns_nameservers']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 13
0
def _format_peer_cidrs(ipsec_site_connection):
    try:
        return '\n'.join([jsonutils.dumps(cidrs) for cidrs in
                          ipsec_site_connection['peer_cidrs']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 14
0
def _create_version_entry(version):
    return jsonutils.dumps({'version': version})
Ejemplo n.º 15
0
def _create_version_list(versions):
    return jsonutils.dumps({'versions': {'values': versions}})
Ejemplo n.º 16
0
def _format_fixed_ips(port):
    try:
        return '\n'.join([jsonutils.dumps(ip) for ip in port['fixed_ips']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 17
0
def _format_fixed_ips(port):
    try:
        return '\n'.join([jsonutils.dumps(ip) for ip in port['fixed_ips']])
    except Exception:
        return ''
Ejemplo n.º 18
0
def _format_host_routes(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(route) for route in subnet['host_routes']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 19
0
def _format_external_gateway_info(router):
    try:
        return jsonutils.dumps(router['external_gateway_info'])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 20
0
 def default(self, data):
     def sanitizer(obj):
         return unicode(obj)
     return jsonutils.dumps(data, default=sanitizer)
Ejemplo n.º 21
0
def _format_fixed_ips(port):
    try:
        return '\n'.join([jsonutils.dumps(ip) for ip in port['fixed_ips']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 22
0
def _format_dns_nameservers(subnet):
    try:
        return '\n'.join([jsonutils.dumps(server) for server in
                          subnet['dns_nameservers']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 23
0
def _create_version_list(versions):
    return jsonutils.dumps({'versions': {'values': versions}})
Ejemplo n.º 24
0
def _format_allocation_pools(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(pool) for pool in subnet['allocation_pools']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 25
0
def _format_allocation_pools(subnet):
    try:
        return '\n'.join([jsonutils.dumps(pool) for pool in
                          subnet['allocation_pools']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 26
0
def _format_external_gateway_info(router):
    try:
        return jsonutils.dumps(router['external_gateway_info'])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 27
0
def _format_host_routes(subnet):
    try:
        return '\n'.join([jsonutils.dumps(route) for route in
                          subnet['host_routes']])
    except (TypeError, KeyError):
        return ''
Ejemplo n.º 28
0
    def default(self, data):
        def sanitizer(obj):
            return unicode(obj)

        return jsonutils.dumps(data, default=sanitizer)
Ejemplo n.º 29
0
def _format_dns_nameservers(subnet):
    try:
        return '\n'.join([jsonutils.dumps(server) for server in
                          subnet['dns_nameservers']])
    except Exception:
        return ''
Ejemplo n.º 30
0
    def default(self, data):
        def sanitizer(obj):
            return six.text_type(obj, 'utf8')

        return jsonutils.dumps(data, default=sanitizer)
Ejemplo n.º 31
0
def _create_version_entry(version):
    return jsonutils.dumps({"version": version})
Ejemplo n.º 32
0
def _format_allocation_pools(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(pool) for pool in subnet['allocation_pools']])
    except Exception:
        return ''
def _format_external_gateway_info(router):
    try:
        return jsonutils.dumps(router['external_gateway_info'])
    except Exception:
        return ''
Ejemplo n.º 34
0
def _format_dns_nameservers(subnet):
    try:
        return '\n'.join(
            [jsonutils.dumps(server) for server in subnet['dns_nameservers']])
    except Exception:
        return ''