def response(self, path, content):

        content_json = json.loads(content)
        received_subnet = content_json['subnet']
        subnet = dict()

        # generate some new id for the subnet
        subnet_id = 'subnet_id_' + str(len(subnets) + 1)

        # only copy the relevant keys, fail if any of them is missing
        subnet['id'] = subnet_id
        subnet['name'] = received_subnet['name']
        subnet['network_id'] = received_subnet['network_id']
        subnet['cidr'] = received_subnet['cidr']

        update_field_if_present(subnet, received_subnet, 'ip_version')
        update_field_if_present(subnet, received_subnet, 'gateway_ip')
        update_field_if_present(subnet, received_subnet, 'dns_nameservers')

        print "UPDATE SUBNET:" + str(subnet)

        subnets[subnet_id] = subnet

        return json.dumps({'subnet': subnet})
Exemplo n.º 2
0
    def response(self, path, content):

        content_json = json.loads(content)

        received_port = content_json['port']

        port_id = get_id_from_path(path)
        port = ports[port_id]

        # only copy the relevant keys, fail if any of them is missing
        update_field_if_present(port, received_port, 'name')
        update_field_if_present(port, received_port, 'network_id')
        update_field_if_present(port, received_port, 'device_id')
        update_field_if_present(port, received_port, 'mac_address')
        update_field_if_present(port, received_port, 'device_owner')
        update_field_if_present(port, received_port, 'admin_state_up')
        update_field_if_present(port, received_port, 'binding:host_id')

        print "PUT PORT:" + str(port)
        # ports[port_id] = port
        return json.dumps({'port': port})