def delete_all_old_snapshots(self, max_age_days, name_ignore_patterns):
        """Deletes all snapshots from all VMs that are older than max_age_days.
        Ignorning any snapshot with a name that matches one of the name_ignore_pattern.
        """
        # Retrieve a list of all VMs in vSphere
        vm_list = inventory.get_virtualmachines(self.si_content)
        deleted_snapshots = []
        ignored_snapshots = []
        for vm in vm_list.view:
            # Check if any snapshots exist on the VM
            try:
                snapshots = vm.snapshot.rootSnapshotList
            except:
                self.logger.exception(f'No snapshots found for VM.')

            result = self.delete_old_snapshots(snapshots, max_age_days,
                                               name_ignore_patterns)
            # Append the results from each VM
            deleted_snapshots += result['deleted_snapshots']
            ignored_snapshots += result['ignored_snapshots']

        return {
            'deleted_snapshots': deleted_snapshots,
            'ignored_snapshots': ignored_snapshots
        }
示例#2
0
    def get_all(self):
        results = []
        templates = inventory.get_virtualmachines(self.si_content)
        for template in templates.view:
            if template.config.template:
                results.append(self.get_template_dict(template))

        return results
示例#3
0
    def run(self, vm_names):
        results = {}

        vmlist = inventory.get_virtualmachines(self.si_content)

        for vm in vmlist.view:
            if vm_names:
                if vm.name in vm_names:
                    results[vm.name] = str(vm).split(':')[-1].replace("'", "")
            else:
                results[vm.name] = str(vm).split(':')[-1].replace("'", "")

        return results
示例#4
0
    def run(self, vm_names):
        results = {}

        vmlist = inventory.get_virtualmachines(self.si_content)

        for vm in vmlist.view:
            if vm_names:
                if vm.name in vm_names:
                    results[vm.name] = str(vm).split(':')[-1].replace("'", "")
            else:
                results[vm.name] = str(vm).split(':')[-1].replace("'", "")

        return results
示例#5
0
    def run(self, vm_names, vsphere=None):
        """
        Return moid values for VMs listed within the vsphere.

        Args:
        - vm_names: list of names as shown in vsphere

        Returns:
        - dict: key value pair of vm_name and vm moid.
        """

        results = {}
        self.establish_connection(vsphere)

        vmlist = inventory.get_virtualmachines(self.si_content)

        for vm in vmlist.view:
            if vm_names:
                if vm.name in vm_names:
                    results[vm.name] = str(vm).split(':')[-1].replace("'", "")
            else:
                results[vm.name] = str(vm).split(':')[-1].replace("'", "")

        return results
示例#6
0
    def run(self, vm_names, vsphere=None):
        """
        Return moid values for VMs listed within the vsphere.

        Args:
        - vm_names: list of names as shown in vsphere

        Returns:
        - dict: key value pair of vm_name and vm moid.
        """

        results = {}
        self.establish_connection(vsphere)

        vmlist = inventory.get_virtualmachines(self.si_content)

        for vm in vmlist.view:
            if vm_names:
                if vm.name in vm_names:
                    results[vm.name] = str(vm).split(':')[-1].replace("'", "")
            else:
                results[vm.name] = str(vm).split(':')[-1].replace("'", "")

        return results