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
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)
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)
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
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))
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)
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))
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))
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)
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)
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)
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)
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)