Esempio n. 1
0
def delete_port(port_id):
    try:
        port = NetworkInterface.objects.select_for_update().get(id=port_id)
        servers.delete_port(port)
        if port.machine:
            wait_server_job(port.machine)
        return True
    except BaseException:
        raise
Esempio n. 2
0
def remove_floating_ip(request, vm, args):
    address = args.get("address")
    if address is None:
        raise faults.BadRequest("Missing 'address' attribute")
    floating_ip = util.get_floating_ip_by_address(vm.userid, address,
                                                  for_update=True)
    if floating_ip.nic is None:
        raise faults.BadRequest("Floating IP %s not attached to instance"
                                % address)
    servers.delete_port(floating_ip.nic)
    return HttpResponse(status=202)
Esempio n. 3
0
def delete_port(request, port_id):
    log.info('delete_port %s', port_id)
    user_id = request.user_uniq
    port = util.get_port(port_id, user_id, for_update=True)

    # Deleting port that is connected to a public network is allowed only if
    # the port has an associated floating IP address.
    if port.network.public and not port.ips.filter(floating_ip=True,
                                                   deleted=False).exists():
        raise faults.Forbidden("Cannot disconnect from public network.")

    servers.delete_port(port)
    return HttpResponse(status=204)
Esempio n. 4
0
def delete_port(request, port_id):
    log.info('delete_port %s', port_id)
    user_id = request.user_uniq
    port = util.get_port(port_id, user_id, for_update=True)

    # Deleting port that is connected to a public network is allowed only if
    # the port has an associated floating IP address.
    if port.network.public and not port.ips.filter(floating_ip=True,
                                                   deleted=False).exists():
        raise faults.Forbidden("Cannot disconnect from public network.")

    servers.delete_port(port)
    return HttpResponse(status=204)
Esempio n. 5
0
def remove_ip(ip_id):
    try:
        ip = IPAddress.objects.select_for_update().get(id=ip_id)
        port_id = ip.nic_id
        if port_id:
            objs = NetworkInterface.objects.select_for_update()
            port = objs.get(id=port_id)
            servers.delete_port(port)
            if port.machine:
                wait_server_job(port.machine)
            ip = wait_for_ip(ip_id)
        logic_ips.delete_floating_ip(ip)
        return True
    except BaseException:
        return False
Esempio n. 6
0
    def handle(self, *args, **options):
        if not args or len(args) > 1:
            raise CommandError("Command accepts exactly one argument")

        floating_ip_id = args[0]

        # get the floating-ip
        floating_ip = common.get_floating_ip_by_id(floating_ip_id, for_update=True)

        if not floating_ip.nic:
            raise CommandError("This floating IP is not attached to a device")

        nic = floating_ip.nic
        vm = nic.machine
        servers.delete_port(nic)
        self.stdout.write("Detached floating IP %s from  %s.\n" % (floating_ip_id, vm))
Esempio n. 7
0
def remove_floating_ip(request, vm, args):
    address = args.get("address")
    if address is None:
        raise faults.BadRequest("Missing 'address' attribute")

    floating_ip = util.get_floating_ip_by_address(vm.userid,
            request.user_projects, address, for_update=True)
    if floating_ip.nic is None:
        raise faults.BadRequest("Floating IP %s not attached to instance"
                                % address)

    servers.delete_port(floating_ip.nic)

    log.info("User %s detached floating IP %s from VM %s",
             request.user_uniq, floating_ip.id, vm.id)

    return HttpResponse(status=202)
Esempio n. 8
0
    def handle(self, *args, **options):
        if not args or len(args) > 1:
            raise CommandError("Command accepts exactly one argument")

        floating_ip_id = args[0]

        #get the floating-ip
        floating_ip = common.get_resource("floating-ip", floating_ip_id)

        if not floating_ip.nic:
            raise CommandError('This floating IP is not attached to a device')

        credentials = Credentials("snf-manage", is_admin=True)
        nic = floating_ip.nic
        vm = nic.machine
        servers.delete_port(nic.id, credentials)
        self.stdout.write("Detached floating IP %s from  %s.\n" %
                          (floating_ip_id, vm))
Esempio n. 9
0
    def handle(self, *args, **options):
        if not args or len(args) > 1:
            raise CommandError("Command accepts exactly one argument")

        floating_ip_id = args[0]

        #get the floating-ip
        floating_ip = common.get_floating_ip_by_id(floating_ip_id,
                                                   for_update=True)

        if not floating_ip.nic:
            raise CommandError('This floating IP is not attached to a device')

        nic = floating_ip.nic
        vm = nic.machine
        servers.delete_port(nic)
        self.stdout.write("Detached floating IP %s from  %s.\n" %
                          (floating_ip_id, vm))
Esempio n. 10
0
    def handle(self, *args, **options):
        if not args or len(args) > 1:
            raise CommandError("Command accepts exactly one argument")

        floating_ip_id = args[0]

        #get the floating-ip
        floating_ip = common.get_resource("floating-ip", floating_ip_id)

        if not floating_ip.nic:
            raise CommandError('This floating IP is not attached to a device')

        credentials = Credentials("snf-manage", is_admin=True)
        nic = floating_ip.nic
        vm = nic.machine
        servers.delete_port(nic.id, credentials)
        self.stdout.write("Detached floating IP %s from  %s.\n"
                          % (floating_ip_id, vm))
Esempio n. 11
0
def delete_port(request, port_id):
    log.info('delete_port %s', port_id)
    user_id = request.user_uniq
    port = util.get_port(port_id, user_id, request.user_projects,
                         for_update=True)

    # Deleting port that is connected to a public network is allowed only if
    # the port has an associated floating IP address.
    if port.network.public and not port.ips.filter(floating_ip=True,
                                                   deleted=False).exists():
        raise faults.Forbidden("Cannot disconnect from public network.")

    vm = port.machine
    if vm is not None and vm.suspended:
        raise faults.Forbidden("Administratively Suspended VM.")

    servers.delete_port(port)

    log.info("User %s deleted port %s", user_id, port_id)

    return HttpResponse(status=204)
Esempio n. 12
0
def delete_port(request, port_id):
    log.info('delete_port %s', port_id)
    user_id = request.user_uniq
    port = util.get_port(port_id,
                         user_id,
                         request.user_projects,
                         for_update=True)

    # Deleting port that is connected to a public network is allowed only if
    # the port has an associated floating IP address.
    if port.network.public and not port.ips.filter(floating_ip=True,
                                                   deleted=False).exists():
        raise faults.Forbidden("Cannot disconnect from public network.")

    vm = port.machine
    if vm is not None and vm.suspended:
        raise faults.Forbidden("Administratively Suspended VM.")

    servers.delete_port(port)

    log.info("User %s deleted port %s", user_id, port_id)

    return HttpResponse(status=204)
Esempio n. 13
0
    def handle(self, *args, **options):
        if not args:
            raise CommandError("Please provide a port ID")

        force = options['force']
        message = "ports" if len(args) > 1 else "port"
        self.confirm_deletion(force, message, args)

        for port_id in args:
            self.stdout.write("\n")
            try:
                port = common.get_resource("port", port_id, for_update=True)

                servers.delete_port(port)

                wait = parse_bool(options["wait"])
                if port.machine is not None:
                    common.wait_server_task(port.machine, wait,
                                            stdout=self.stdout)
                else:
                    self.stdout.write("Successfully removed port %s\n" % port)
            except CommandError as e:
                self.stdout.write("Error -- %s\n" % e.message)
Esempio n. 14
0
    def handle(self, *args, **options):
        if not args:
            raise CommandError("Please provide a port ID")

        force = options['force']
        message = "ports" if len(args) > 1 else "port"
        self.confirm_deletion(force, message, args)

        for port_id in args:
            self.stdout.write("\n")
            try:
                port = common.get_resource("port", port_id, for_update=True)

                servers.delete_port(port)

                wait = parse_bool(options["wait"])
                if port.machine is not None:
                    common.wait_server_task(port.machine,
                                            wait,
                                            stdout=self.stdout)
                else:
                    self.stdout.write("Successfully removed port %s\n" % port)
            except CommandError as e:
                self.stdout.write("Error -- %s\n" % e.message)
Esempio n. 15
0
def delete_port(port_id):
    port = NetworkInterface.objects.get(id=port_id)
    servers.delete_port(port_id, credentials)
    if port.machine:
        wait_server_job(port.machine)
Esempio n. 16
0
def delete_port(port_id):
    port = NetworkInterface.objects.select_for_update().get(id=port_id)
    servers.delete_port(port)
    if port.machine:
        wait_server_job(port.machine)
Esempio n. 17
0
def delete_port(request, port_id):
    log.info('delete_port %s', port_id)
    credentials = request.credentials
    servers.delete_port(port_id, credentials)
    return HttpResponse(status=204)
Esempio n. 18
0
def delete_port(port_id):
    port = NetworkInterface.objects.get(id=port_id)
    servers.delete_port(port_id, credentials)
    if port.machine:
        wait_server_job(port.machine)