Beispiel #1
0
    def rename(cls, **kwargs):
        cloud_provider = CloudProvider(kwargs["cloud"]).provider
        new_name = kwargs["new_name"]
        for server in kwargs["servers"]:
            cloud_provider.rename_vm(server, new_name)
            print("Machine {:} renamed to {:} on {:} Cloud...".format(server, new_name, cloud_provider.cloud))

            # Explicit refresh called after VM delete, to update db.
            cls.refresh(cloud=kwargs["cloud"])
Beispiel #2
0
    def rename(cls, **kwargs):

        arg = dotdict(kwargs)

        cloud_provider = CloudProvider(kwargs["cloud"]).provider

        # Check for vms with duplicate names in DB.
        vms = cls.get_vms_by_name(name=arg.oldname, cloud=arg.cloud)

        if len(vms) > 1:
            users_choice = "y"

            if not arg.force:
                print("More than 1 vms found with the same name as {}."
                      .format(server))
                users_choice = input(
                    "Would you like to auto-order the new names? (y/n): ")

            if users_choice.strip() == "y":
                count = 1
                for index in vms:
                    count_new_name = "{0}{1}".format(arg.newname, count)
                    # print(vms[index])

                    cloud_provider.rename_vm(vms[index]["uuid"],
                                             count_new_name)

                    print(
                        "Machine {0} with UUID {1} renamed to {2} on {3} cloud"
                        .format(vms[index]["name"],
                                vms[index]["uuid"],
                                count_new_name,
                                cloud_provider.cloud))
                    count += 1
            elif users_choice.strip() == "n":
                cloud_provider.rename_vm(arg.oldname, arg.newname)
                print(
                    "Machine {0} renamed to {1} on {2} Cloud..."
                    .format(arg.oldname, arg.newname, cloud_provider.cloud))
            else:
                Console.error("Invalid Choice.")
                return
        else:
            cloud_provider.rename_vm(arg.oldname, arg.newname)
            print("Machine {0} renamed to {1} on {2} Cloud..."
                  .format(arg.oldname, arg.newname, cloud_provider.cloud))

        # Explicit refresh called after VM rename, to update db.
        cls.refresh(cloud=arg.cloud)
Beispiel #3
0
    def rename(cls, **kwargs):

        arg = dotdict(kwargs)

        cloud_provider = CloudProvider(kwargs["cloud"]).provider

        # Check for vms with duplicate names in DB.
        vms = cls.get_vms_by_name(name=arg.oldname, cloud=arg.cloud)

        if len(vms) > 1:
            users_choice = "y"

            if not arg.force:
                print("More than 1 vms found with the same name as {}.".format(
                    server))
                users_choice = input(
                    "Would you like to auto-order the new names? (y/n): ")

            if users_choice.strip() == "y":
                count = 1
                for index in vms:
                    count_new_name = "{0}{1}".format(arg.newname, count)
                    # print(vms[index])

                    cloud_provider.rename_vm(vms[index]["uuid"],
                                             count_new_name)

                    print(
                        "Machine {0} with UUID {1} renamed to {2} on {3} cloud"
                        .format(vms[index]["name"], vms[index]["uuid"],
                                count_new_name, cloud_provider.cloud))
                    count += 1
            elif users_choice.strip() == "n":
                cloud_provider.rename_vm(arg.oldname, arg.newname)
                print("Machine {0} renamed to {1} on {2} Cloud...".format(
                    arg.oldname, arg.newname, cloud_provider.cloud))
            else:
                Console.error("Invalid Choice.")
                return
        else:
            cloud_provider.rename_vm(arg.oldname, arg.newname)
            print("Machine {0} renamed to {1} on {2} Cloud...".format(
                arg.oldname, arg.newname, cloud_provider.cloud))

        # Explicit refresh called after VM rename, to update db.
        cls.refresh(cloud=arg.cloud)