Exemplo n.º 1
0
def update_network(request, network_id):
    info = api.utils.get_json_body(request)

    network = api.utils.get_attribute(info, "network", attr_type=dict,
                                      required=True)
    new_name = api.utils.get_attribute(network, "name", attr_type=basestring)
    network = networks.rename(network_id, new_name, request.credentials)

    log.info("User %s renamed network %s",
             request.credentials.userid, network.id)

    return render_network(request, network_to_dict(network), 200)
Exemplo n.º 2
0
def update_network(request, network_id):
    info = api.utils.get_request_dict(request)

    network = api.utils.get_attribute(info, "network", attr_type=dict,
                                      required=True)
    new_name = api.utils.get_attribute(network, "name", attr_type=basestring)

    network = util.get_network(network_id, request.user_uniq, for_update=True)
    if network.public:
        raise api.faults.Forbidden("Cannot rename the public network.")
    network = networks.rename(network, new_name)
    return render_network(request, network_to_dict(network), 200)
Exemplo n.º 3
0
def update_network(request, network_id):
    info = api.utils.get_request_dict(request)

    network = api.utils.get_attribute(info,
                                      "network",
                                      attr_type=dict,
                                      required=True)
    new_name = api.utils.get_attribute(network, "name", attr_type=basestring)

    network = util.get_network(network_id, request.user_uniq, for_update=True)
    if network.public:
        raise api.faults.Forbidden("Cannot rename the public network.")
    network = networks.rename(network, new_name)
    return render_network(request, network_to_dict(network), 200)
Exemplo n.º 4
0
def update_network(request, network_id):
    info = api.utils.get_json_body(request)

    network = api.utils.get_attribute(info,
                                      "network",
                                      attr_type=dict,
                                      required=True)
    new_name = api.utils.get_attribute(network, "name", attr_type=basestring)
    network = networks.rename(network_id, new_name, request.credentials)

    log.info("User %s renamed network %s", request.credentials.userid,
             network.id)

    return render_network(request, network_to_dict(network), 200)
Exemplo n.º 5
0
def update_network(request, network_id):
    info = api.utils.get_json_body(request)

    network = api.utils.get_attribute(info,
                                      "network",
                                      attr_type=dict,
                                      required=True)
    new_name = api.utils.get_attribute(network, "name", attr_type=basestring)

    network = util.get_network(network_id,
                               request.user_uniq,
                               request.user_projects,
                               for_update=True,
                               non_deleted=True)
    if network.public:
        raise api.faults.Forbidden("Cannot rename the public network.")

    network = networks.rename(network, new_name)

    log.info("User %s renamed network %s", request.user_uniq, network.id)

    return render_network(request, network_to_dict(network), 200)
Exemplo n.º 6
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a network ID")

        network = get_network(args[0])

        new_name = options.get("name")
        if new_name is not None:
            old_name = network.name
            network = networks.rename(network, new_name)
            self.stdout.write("Renamed network '%s' from '%s' to '%s'.\n" %
                              (network, old_name, new_name))

        drained = options.get("drained")
        if drained is not None:
            drained = parse_bool(drained)
            network.drained = drained
            network.save()
            self.stdout.write("Set network '%s' as drained=%s.\n" %
                              (network, drained))

        new_owner = options.get("userid")
        if new_owner is not None:
            if "@" in new_owner:
                raise CommandError("Invalid owner UUID.")
            old_owner = network.userid
            network.userid = new_owner
            network.save()
            msg = "Changed the owner of network '%s' from '%s' to '%s'.\n"
            self.stdout.write(msg % (network, old_owner, new_owner))

        floating_ip_pool = options["floating_ip_pool"]
        if floating_ip_pool is not None:
            floating_ip_pool = parse_bool(floating_ip_pool)
            if floating_ip_pool is False and network.floating_ip_pool is True:
                if network.ips.filter(deleted=False, floating_ip=True)\
                              .exists():
                    msg = ("Cannot make network a non floating IP pool."
                           " There are still reserved floating IPs.")
                    raise CommandError(msg)
            network.floating_ip_pool = floating_ip_pool
            network.save()
            self.stdout.write("Set network '%s' as floating-ip-pool=%s.\n" %
                              (network, floating_ip_pool))
            if floating_ip_pool is True:
                for backend in Backend.objects.filter(offline=False):
                    bnet, jobs =\
                        backend_mod.ensure_network_is_active(backend,
                                                             network.id)
                    if jobs:
                        msg = ("Sent job to create network '%s' in backend"
                               " '%s'\n" % (network, backend))
                        self.stdout.write(msg)

        add_reserved_ips = options.get('add_reserved_ips')
        remove_reserved_ips = options.get('remove_reserved_ips')
        if add_reserved_ips or remove_reserved_ips:
            if add_reserved_ips:
                add_reserved_ips = add_reserved_ips.split(",")
                for ip in add_reserved_ips:
                    network.reserve_address(ip, external=True)
            if remove_reserved_ips:
                remove_reserved_ips = remove_reserved_ips.split(",")
                for ip in remove_reserved_ips:
                    network.release_address(ip, external=True)

        add_to_backend = options["add_to_backend"]
        if add_to_backend is not None:
            backend = get_backend(add_to_backend)
            bnet, jobs = backend_mod.ensure_network_is_active(backend,
                                                              network.id)
            if jobs:
                msg = "Sent job to create network '%s' in backend '%s'\n"
                self.stdout.write(msg % (network, backend))

        remove_from_backend = options["remove_from_backend"]
        if remove_from_backend is not None:
            backend = get_backend(remove_from_backend)
            if network.nics.filter(machine__backend=backend,
                                   machine__deleted=False).exists():
                msg = "Cannot remove. There are still connected VMs to this"\
                      " network"
                raise CommandError(msg)
            backend_mod.delete_network(network, backend, disconnect=True)
            msg = "Sent job to delete network '%s' from backend '%s'\n"
            self.stdout.write(msg % (network, backend))