def update_hostgroups(self, groups):
        """Replace existing HostGroupType with contents of groups dict."""
        # First find any existing HostGroupType
        try:
            hgtype = HostGroupType.find_by_name(self.netprofiler,
                                                self.options.hostgroup)
            hgtype.config = []
            hgtype.groups = {}
            print('Existing HostGroupType "{0}" found.'
                  ''.format(self.options.hostgroup))
        except RvbdException:
            print('No existing HostGroupType found, creating a new one.')

            hgtype = HostGroupType.create(self.netprofiler,
                                          self.options.hostgroup)

        # Add new values
        for group, cidrs in groups.items():
            hg = HostGroup(hgtype, group)
            hg.add(cidrs)

        # Save to NetProfiler
        hgtype.save()
        print('HostGroupType "%s" configuration saved.' %
              self.options.hostgroup)
    def update_hostgroups(self, groups):
        """Replace existing HostGroupType with contents of groups dict."""
        # First find any existing HostGroupType
        try:
            hgtype = HostGroupType.find_by_name(self.netprofiler,
                                                self.options.hostgroup)
            hgtype.config = []
            hgtype.groups = {}
            print('Existing HostGroupType "{0}" found.'
                  ''.format(self.options.hostgroup))
        except RvbdException:
            print('No existing HostGroupType found, creating a new one.')

            hgtype = HostGroupType.create(self.netprofiler,
                                          self.options.hostgroup)

        # Add new values
        for group, cidrs in groups.items():
            hg = HostGroup(hgtype, group)
            hg.add(cidrs)

        # Save to NetProfiler
        hgtype.save()
        print ('HostGroupType "%s" configuration saved.'
               % self.options.hostgroup)
    def test_add_cidrs_as_list(self):
        """ Checks if you can add cidrs to a host group as a list
        """
        host_group_type = HostGroupType.create(self.profiler, "TestType4057")
        prepend_group = HostGroup(host_group_type, "PrependGroup")
        prepend_group.add(["10.91.11.0/24", "10.92.11.0/24"],
                          keep_together=False, prepend=True)

        self.assertEqual(host_group_type.config[0]['cidr'], '10.91.11.0/24')
        self.assertEqual(host_group_type.config[1]['cidr'], '10.92.11.0/24')
Ejemplo n.º 4
0
    def test_add_cidrs_as_list(self):
        """ Checks if you can add cidrs to a host group as a list
        """
        host_group_type = HostGroupType.create(self.profiler, "TestType4057")
        prepend_group = HostGroup(host_group_type, "PrependGroup")
        prepend_group.add(["10.91.11.0/24", "10.92.11.0/24"],
                          keep_together=False,
                          prepend=True)

        self.assertEqual(host_group_type.config[0]['cidr'], '10.91.11.0/24')
        self.assertEqual(host_group_type.config[1]['cidr'], '10.92.11.0/24')
Ejemplo n.º 5
0
    def test_remove_group(self):
        """
        Check that the remove method in HostGroup works properly by adding a few
        cidrs that have the same value, but are in different host groups, then
        removing one of those entries from one host group to make sure the other
        is not effected.
        """
        host_group_type = HostGroupType.create(self.profiler, "TestType4057")
        # Create a bunch of new host groups for testing
        new_host_groups = []
        for i in range(10):
            new_host_groups.append(HostGroup(host_group_type, 'Test' + str(i)))
            new_host_groups[i].add("10.9{0}.11.0/24".format(i),
                                   keep_together=True,
                                   prepend=False)
        # Add our special host group that will be what we focus on
        new_host_groups[9].add("10.10.21.0/24",
                               keep_together=True,
                               prepend=False)
        new_host_groups[8].add("10.10.21.0/24",
                               keep_together=True,
                               prepend=False)
        new_host_groups[9].remove("10.10.21.0/24")

        host_group_type.save()
        # If everything went well, the new host group will be the 2nd element
        self.assertEqual(host_group_type.groups['Test9'].get()[0],
                         "10.99.11.0/24")
        self.assertEqual(host_group_type.groups['Test8'].get()[1],
                         "10.10.21.0/24")
        self.assertEqual(len(host_group_type.groups['Test9'].get()), 1)
        host_group_type.delete()
Ejemplo n.º 6
0
    def test_add_group_to_end_and_start(self):
        """
        Check that add(cidr, keep_together=False, replace=False, prepend=True or
        prepend=False) works as expected
        """
        host_group_type = HostGroupType.create(self.profiler, "TestType4057")
        prepend_group = HostGroup(host_group_type, "PrependGroup")
        prepend_group.add("10.91.11.0/24", keep_together=False, prepend=True)

        append_group = HostGroup(host_group_type, "AppendGroup")
        append_group.add("10.91.11.0/24", keep_together=False, prepend=False)

        self.assertEqual(host_group_type.config[0]['name'], 'PrependGroup')
        self.assertEqual(host_group_type.config[1]['name'], 'AppendGroup')
Ejemplo n.º 7
0
 def test_abusive_input(self):
     """
     Check that after a series of weirdly placed loads, saves, and additions,
     the program handles everything correctly
     """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     self.assertRaises(RvbdException, HostGroup, "Hurtful", host_group_type)
     self.assertRaises(RvbdException, host_group_type.load)
     host_group_type.save()
     host_group_type.delete()
     self.assertRaises(RvbdException, host_group_type.delete)
     host_group_type.create(self.profiler, "AnotherTestType4057", False,
                            "PLE")
     self.assertRaises(RvbdException, host_group_type.load)
     HostGroup(host_group_type, "TestGroup")
     host_group_type.groups['TestGroup'].get()
     host_group_type.config = host_group_type.groups['TestGroup'].get()
    def test_add_group_to_end_and_start(self):
        """
        Check that add(cidr, keep_together=False, replace=False, prepend=True or
        prepend=False) works as expected
        """
        host_group_type = HostGroupType.create(self.profiler, "TestType4057")
        prepend_group = HostGroup(host_group_type, "PrependGroup")
        prepend_group.add("10.91.11.0/24", keep_together=False, prepend=True)

        append_group = HostGroup(host_group_type, "AppendGroup")
        append_group.add("10.91.11.0/24", keep_together=False, prepend=False)

        self.assertEqual(host_group_type.config[0]['name'], 'PrependGroup')
        self.assertEqual(host_group_type.config[1]['name'], 'AppendGroup')
Ejemplo n.º 9
0
 def test_group_keeptogether_and_append(self):
     """
     Check that you can add host groups and that it responds correctly
     When you append an element to the end with keep_together=True
     """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     # Create a bunch of new host groups for testing
     new_host_groups = []
     for i in range(10):
         new_host_groups.append(HostGroup(host_group_type, 'Test' + str(i)))
         new_host_groups[i].add("10.9{0}.11.0/24".format(i),
                                keep_together=True,
                                prepend=False)
     # Add our special host group that will be what we focus on
     new_host_groups[9].add("10.10.21.0/24",
                            keep_together=True,
                            prepend=False)
     host_group_type.save()
     # If everything went well, the new host group will be the 2nd element
     self.assertEqual(host_group_type.groups['Test9'].get()[1],
                      "10.10.21.0/24")
     host_group_type.delete()
Ejemplo n.º 10
0
 def test_replace(self):
     """
     Check that the replace parameter works when adding groups.
     """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     # Create a bunch of new host groups for testing
     new_host_groups = []
     for i in range(10):
         new_host_groups.append(HostGroup(host_group_type, 'Test' + str(i)))
         new_host_groups[i].add("10.9{0}.11.0/24".format(i),
                                keep_together=True,
                                prepend=False)
     # Add our special host group that will be what we focus on
     new_host_groups[9].add("10.10.21.0/24",
                            keep_together=True,
                            prepend=False,
                            replace=True)
     host_group_type.save()
     # If everything went well, the new host group will be the 1st element
     self.assertEqual(host_group_type.groups['Test9'].get()[0],
                      "10.10.21.0/24")
     self.assertEqual(len(host_group_type.groups['Test9'].get()), 1)
     host_group_type.delete()
 def test_empty_get(self):
     """ Check that you get an empty array when you try to get an empty group
     """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     new_host_group = HostGroup(host_group_type, "EmptyGroup")
     self.assertEqual(new_host_group.get(), [])
Ejemplo n.º 12
0
 def test_empty_get(self):
     """ Check that you get an empty array when you try to get an empty group
     """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     new_host_group = HostGroup(host_group_type, "EmptyGroup")
     self.assertEqual(new_host_group.get(), [])