def add_key_to_cloud(self, user, keyname, cloud, name_on_cloud):

        sshdb = SSHKeyDBManager()
        key_from_db = sshdb.find(keyname)

        if key_from_db is None:
            Console.error("Key with the name {:} not found in database.".format(keyname))
            return

        # Add map entry
        sshdb.add_key_cloud_map_entry(user, keyname, cloud, name_on_cloud)

        print("Adding key {:} to cloud {:} as {:}".format(keyname, cloud, name_on_cloud))
        cloud_provider = CloudProvider(cloud).provider
        cloud_provider.add_key_to_cloud(name_on_cloud, key_from_db["value"])
    def delete_key(self, keyname):

        sshdb = SSHKeyDBManager()
        key = sshdb.find(keyname=keyname)

        # Checking and deleting cloud mappings as well as cloud keys.
        keymap = sshdb.get_key_cloud_map_entry(key["name"])
        if keymap is not None and len(keymap) != 0:
            delete_on_cloud = ""
            while delete_on_cloud != "y" and delete_on_cloud != "n":
                delete_on_cloud = raw_input("Do you want to delete the corresponding key on cloud if present? (y/n): ")
            if delete_on_cloud != "y" and delete_on_cloud != "n":
                print("Invalid Choice")
            for map in keymap.values():
                if delete_on_cloud == "y":
                    self.delete_key_on_cloud(map["cloud_name"], map["key_name_on_cloud"])
            sshdb.delete_key_cloud_map_entry(key["name"])

        sshdb.delete(keyname)
Beispiel #3
0
    def delete_key(self, keyname):

        sshdb = SSHKeyDBManager()
        key = sshdb.find(keyname=keyname)

        # Checking and deleting cloud mappings as well as cloud keys.
        keymap = sshdb.get_key_cloud_map_entry(key["name"])
        if keymap is not None and len(keymap) != 0:
            if self.delete_on_cloud_question:
                delete_on_cloud = yn_choice(
                    "Do you want to delete the corresponding key on cloud if present?", default='y')
            else:
                delete_on_cloud = self.delete_on_cloud

            for map in list(keymap.values()):
                if delete_on_cloud:
                    self.delete_key_on_cloud(map["cloud_name"], map["key_name_on_cloud"])
            sshdb.delete_key_cloud_map_entry(key["name"])

        sshdb.delete(keyname)
Beispiel #4
0
    def add_key_to_cloud(self, user, keyname, cloud, name_on_cloud):
        """

        :param user:
        :param keyname:
        :param cloud:
        :param name_on_cloud:
        :return: 1 if the key is present in db, 0 if the key is added to db.
        """

        sshdb = SSHKeyDBManager()
        key_from_db = sshdb.find(keyname)

        if key_from_db is None:
            Console.error("Key with the name {:} not found in database.".format(keyname))
            return 1

        # Add map entry
        sshdb.add_key_cloud_map_entry(user, keyname, cloud, name_on_cloud)

        print("Adding key {:} to cloud {:} as {:}".format(keyname, cloud, name_on_cloud))
        cloud_provider = CloudProvider(cloud).provider
        cloud_provider.add_key_to_cloud(name_on_cloud, key_from_db["value"])
        return 0