def parse_connections(con_list): connections = [] if con_list: for opt in con_list: try: con_kind = opt.split(":")[0] if con_kind == "network": info = opt.split(",") network_id = info[0].split(":")[1] try: address = info[1].split(":")[1] except: address = None if address: val = {"uuid": network_id, "fixed_ip": address} else: val = {"uuid": network_id} elif con_kind == "id": port_id = opt.split(":")[1] val = {"port": port_id} elif con_kind == "floatingip": fip_id = opt.split(":")[1] fip = common.get_floating_ip_by_id(fip_id, for_update=True) val = {"uuid": fip.network_id, "fixed_ip": fip.address} else: raise CommandError("Unknown argument for option --port") connections.append(val) except: raise CommandError("Malformed information for option --port") return connections
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 handle(self, *args, **options): if not args or len(args) > 1: raise CommandError("Command accepts exactly one argument") floating_ip_id = args[0] # this is the floating-ip address device = options['machine'] if not device: raise CommandError('Please give either a server or a router id') #get the vm vm = common.get_vm(device, for_update=True) floating_ip = common.get_floating_ip_by_id(floating_ip_id, for_update=True) servers.create_port(vm.userid, floating_ip.network, use_ipaddress=floating_ip, machine=vm) self.stdout.write("Attached %s to %s.\n" % (floating_ip, vm))
def handle(self, *args, **options): if not args: raise CommandError("Please provide a floating-ip ID") force = options['force'] message = "floating IPs" if len(args) > 1 else "floating IP" self.confirm_deletion(force, message, args) for floating_ip_id in args: self.stdout.write("\n") try: floating_ip = common.get_floating_ip_by_id(floating_ip_id, for_update=True) ips.delete_floating_ip(floating_ip) self.stdout.write("Deleted floating IP '%s'.\n" % floating_ip_id) except CommandError as e: self.stdout.write("Error -- %s\n" % e.message)
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 handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") name = options["name"] user_id = options["user_id"] network_id = options["network_id"] server_id = options["server_id"] #router_id = options["router_id"] router_id = None # assume giving security groups comma separated security_group_ids = options["security-groups"] wait = parse_bool(options["wait"]) if not name: name = "" if not network_id: raise CommandError("Please specify a 'network'") vm = None owner = None if server_id: owner = "vm" vm = common.get_vm(server_id, for_update=True) #if vm.router: # raise CommandError("Server '%s' does not exist." % server_id) elif router_id: owner = "router" vm = common.get_vm(router_id, for_update=True) if not vm.router: raise CommandError("Router '%s' does not exist." % router_id) if user_id is None: if vm is not None: user_id = vm.userid else: raise CommandError("Please specify the owner of the port.") # get the network network = common.get_network(network_id) # Get either floating IP or fixed ip address ipaddress = None floating_ip_id = options["floating_ip_id"] ipv4_address = options["ipv4_address"] if floating_ip_id: ipaddress = common.get_floating_ip_by_id(floating_ip_id, for_update=True) if ipv4_address is not None and ipaddress.address != ipv4_address: raise CommandError("Floating IP address '%s' is different from" " specified address '%s'" % (ipaddress.address, ipv4_address)) # validate security groups sg_list = [] if security_group_ids: security_group_ids = security_group_ids.split(",") for gid in security_group_ids: sg = util.get_security_group(int(gid)) sg_list.append(sg) new_port = servers.create_port(user_id, network, machine=vm, name=name, use_ipaddress=ipaddress, address=ipv4_address, security_groups=sg_list, device_owner=owner) self.stdout.write("Created port '%s' in DB:\n" % new_port) pprint.pprint_port(new_port, stdout=self.stdout) pprint.pprint_port_ips(new_port, stdout=self.stdout) self.stdout.write("\n") if vm is not None: common.wait_server_task(new_port.machine, wait, stdout=self.stdout)
def handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") name = options["name"] user_id = options["user_id"] network_id = options["network_id"] server_id = options["server_id"] # router_id = options["router_id"] router_id = None # assume giving security groups comma separated security_group_ids = options["security-groups"] wait = parse_bool(options["wait"]) if not name: name = "" if not network_id: raise CommandError("Please specify a 'network'") vm = None owner = None if server_id: owner = "vm" vm = common.get_vm(server_id, for_update=True) # if vm.router: # raise CommandError("Server '%s' does not exist." % server_id) elif router_id: owner = "router" vm = common.get_vm(router_id, for_update=True) if not vm.router: raise CommandError("Router '%s' does not exist." % router_id) if user_id is None: if vm is not None: user_id = vm.userid else: raise CommandError("Please specify the owner of the port.") # get the network network = common.get_network(network_id) # Get either floating IP or fixed ip address ipaddress = None floating_ip_id = options["floating_ip_id"] ipv4_address = options["ipv4_address"] if floating_ip_id: ipaddress = common.get_floating_ip_by_id(floating_ip_id, for_update=True) if ipv4_address is not None and ipaddress.address != ipv4_address: raise CommandError( "Floating IP address '%s' is different from" " specified address '%s'" % (ipaddress.address, ipv4_address) ) # validate security groups sg_list = [] if security_group_ids: security_group_ids = security_group_ids.split(",") for gid in security_group_ids: sg = util.get_security_group(int(gid)) sg_list.append(sg) new_port = servers.create_port( user_id, network, machine=vm, name=name, use_ipaddress=ipaddress, address=ipv4_address, security_groups=sg_list, device_owner=owner, ) self.stdout.write("Created port '%s' in DB:\n" % new_port) pprint.pprint_port(new_port, stdout=self.stdout) pprint.pprint_port_ips(new_port, stdout=self.stdout) self.stdout.write("\n") if vm is not None: common.wait_server_task(new_port.machine, wait, stdout=self.stdout)