Exemplo n.º 1
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a port ID")

        port = common.get_port(args[0])

        pprint.pprint_port(port, stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_ips(port, stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_in_ganeti(port, stdout=self.stdout)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a port ID")

        port = common.get_resource("port", args[0])
        display_mails = options['displaymails']

        pprint.pprint_port(port, display_mails=display_mails,
                           stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_ips(port, stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_in_ganeti(port, stdout=self.stdout)
Exemplo n.º 3
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a port ID")

        port = common.get_resource("port", args[0])
        display_mails = options['displaymails']

        pprint.pprint_port(port,
                           display_mails=display_mails,
                           stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_ips(port, stdout=self.stdout)
        self.stdout.write('\n\n')

        pprint.pprint_port_in_ganeti(port, stdout=self.stdout)
Exemplo n.º 4
0
    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_resource("server", server_id)
            #if vm.router:
            #    raise CommandError("Server '%s' does not exist." % server_id)
        elif router_id:
            owner = "router"
            vm = common.get_resource("server", router_id)
            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 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_resource("floating-ip", floating_ip_id)
            address = ipaddress.address
            if ipv4_address is not None and address != ipv4_address:
                raise CommandError("Floating IP address '%s' is different from"
                                   " specified address '%s'" %
                                   (address, ipv4_address))
        else:
            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)

        credentials = Credentials(user_id)
        new_port = servers.create_port(credentials,
                                       network_id,
                                       machine=vm.id,
                                       name=name,
                                       address=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)
Exemplo n.º 5
0
    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_resource("server", server_id)
            #if vm.router:
            #    raise CommandError("Server '%s' does not exist." % server_id)
        elif router_id:
            owner = "router"
            vm = common.get_resource("server", router_id)
            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 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_resource("floating-ip", floating_ip_id)
            address = ipaddress.address
            if ipv4_address is not None and address != ipv4_address:
                raise CommandError("Floating IP address '%s' is different from"
                                   " specified address '%s'" %
                                   (address, ipv4_address))
        else:
            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)

        credentials = Credentials(user_id)
        new_port = servers.create_port(credentials, network_id, machine=vm.id,
                                       name=name,
                                       address=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)