def test_parse_cluster_props(self):
        """Test the parse_cluster_props_method."""
        datacenter = vim.Datacenter('datacenter-1')
        folder = vim.Folder('group-h1')

        parents_dict = {}
        parents_dict[str(datacenter)] = {
            'type': 'vim.Datacenter',
            'name': 'dc1'
        }
        parents_dict[str(folder)] = {
            'type': 'vim.Folder',
            'parent': str(datacenter)
        }

        props = [
            vim.DynamicProperty(name='name', val='cluster1'),
            vim.DynamicProperty(name='parent', val=folder)
        ]

        expected_facts = {
            'cluster.name': 'cluster1',
            'cluster.datacenter': 'dc1'
        }
        results = self.runner.parse_cluster_props(props, parents_dict)
        self.assertEqual(results, expected_facts)
    def test_parse_parent_props(self):
        """Test the parse_parent_props_method."""
        obj = vim.ClusterComputeResource('domain-c7')

        folder = vim.Folder('group-h1')
        props = [
            vim.DynamicProperty(name='name', val='cluster1'),
            vim.DynamicProperty(name='parent', val=folder),
        ]

        expected_facts = {
            'type': 'vim.ClusterComputeResource',
            'name': 'cluster1',
            'parent': str(folder)
        }
        results = self.runner.parse_parent_props(obj, props)
        self.assertEqual(results, expected_facts)
Example #3
0
    def test_get_vm_names(self):
        """Test the get vm names method."""
        objects = [
            vim.ObjectContent(
                obj=vim.VirtualMachine('vm-1'),
                propSet=[vim.DynamicProperty(name='name', val='vm1')]),
            vim.ObjectContent(
                obj=vim.VirtualMachine('vm-2'),
                propSet=[vim.DynamicProperty(name='name', val='vm2')]),
        ]

        content = Mock()
        content.rootFolder = vim.Folder('group-d1')
        content.propertyCollector.RetrievePropertiesEx(ANY).token = None
        content.propertyCollector.RetrievePropertiesEx(ANY).objects = objects

        vm_names = get_vm_names(content)
        self.assertTrue(isinstance(vm_names, list))
        self.assertEqual(vm_names, ['vm1', 'vm2'])