Commit 260082aa authored by Ross Davies's avatar Ross Davies
Browse files

Added prism.Vms.get_protection_rules

parent c0b86a54
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ A log of changes by version and date.
    :header: "Version", "Date", "Notes"
    :widths: 10, 10, 60

    "1.1.30", "4/1/2021", "Added prism.Vms.get_protection_rules."
    "1.1.29", "3/31/2021", "Added prism.Config.get_protection_rules."
    "1.1.28", "3/31/2021", "Resolved issue where ProtectionRules were being returned as categories on each VM/Host assigned to the protection rule."
    "1.1.27", "3/31/2021", "Resolved issue with if statements within prism.Config.get_projects and prism.Config.get_project_usage."
+1 −1
Original line number Diff line number Diff line
@@ -3,5 +3,5 @@
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module module

__version_info__ = ('1', '1', '29')
__version_info__ = ('1', '1', '30')
__version__ = '.'.join(__version_info__)
+31 −2
Original line number Diff line number Diff line
@@ -2615,7 +2615,6 @@ class Hosts(object):
            self.get_metadata(refresh=refresh)
            metadata = self.metadata.get(uuid)
            if metadata:
                logger.info('host "{0}" metadata "{1}"'.format(uuid, metadata))
                if 'categories' in metadata:
                    for key, value in metadata.get('categories').items():
                        # Skip keys that do not relate to categories
@@ -2623,6 +2622,7 @@ class Hosts(object):
                            'ProtectionRule',
                        ]
                        if not any(value in key for value in items_to_exclude):
                            logger.info('host "{0}" category "{1}:{2}"'.format(uuid, key, value))
                            categories[key] = value
        return categories

@@ -2800,7 +2800,6 @@ class Vms(object):
            self.get_metadata(refresh=refresh)
            metadata = self.metadata.get(uuid)
            if metadata:
                logger.info('vm "{0}" metadata "{1}"'.format(uuid, metadata))
                if 'categories' in metadata:
                    for key, value in metadata.get('categories').items():

@@ -2809,9 +2808,39 @@ class Vms(object):
                            'ProtectionRule',
                        ]
                        if not any(value in key for value in items_to_exclude):
                            logger.info('vm "{0}" category "{1}:{2}"'.format(uuid, key, value))
                            categories[key] = value
        return categories

    def get_protection_rules(self, uuid, refresh=False):
        """Retrieve the protection rules assigned to the specified VM if connected to a prism central

        :param uuid: The UUID of a VM.
        :type uuid: str
        :param refresh: Whether to refresh the class VM Metadata dataset (default=False).
        :type refresh: bool, optional

        :returns: A dictionary with all .
        :rtype: ResponseDict
        """
        logger = logging.getLogger('ntnx_api.prism.Vms.get_protection_rules')
        protection_rules = {}
        if self.api_client.connection_type == "pc":
            self.get_metadata(refresh=refresh)
            metadata = self.metadata.get(uuid)
            if metadata:
                if 'categories' in metadata:
                    for key, value in metadata.get('categories').items():

                        # Skip keys that do not relate to categories
                        items_to_include = [
                            'ProtectionRule',
                        ]
                        if any(value in key for value in items_to_include):
                            logger.info('vm "{0}" protection rule "{1}:{2}"'.format(uuid, key, value))
                            protection_rules[key] = value
        return protection_rules


class Images(object):
    """A class to represent a Nutanix Clusters Images