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_create_save_and_delete(self):
     """ Check that when you create a new group type that it is added """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     host_group_type.save()
     HostGroupType.find_by_name(self.profiler, "TestType4057")
     host_group_type.delete()
     self.assertIsNone(host_group_type.id)
示例#4
0
 def test_create_save_and_delete(self):
     """ Check that when you create a new group type that it is added """
     host_group_type = HostGroupType.create(self.profiler, "TestType4057")
     host_group_type.save()
     HostGroupType.find_by_name(self.profiler, "TestType4057")
     host_group_type.delete()
     self.assertIsNone(host_group_type.id)
    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()
示例#6
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()
 def setUp(self):
     try:
         # TestType4057 is reserved for these tests. 4057 has no significance
         # If we can find that host group for some reason in the netprofiler
         # then we must delete it before starting any of our tests.
         old_host_group_type = HostGroupType.find_by_name(self.profiler,
                                                          'TestType4057')
         old_host_group_type.delete()
     except RvbdException:
         return
 def setUp(self):
     try:
         # TestType4057 is reserved for these tests. 4057 has no significance
         # If we can find that host group for some reason in the netprofiler
         # then we must delete it before starting any of our tests.
         old_host_group_type = HostGroupType.find_by_name(
             self.profiler, 'TestType4057')
         old_host_group_type.delete()
     except RvbdException:
         return
    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')
示例#10
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')
def netprofiler_hostgroups(form, id, field_kwargs, params):
    """ Query netprofiler for groups within a given hostgroup. """
    netprofiler_device = form.get_field_value('netprofiler_device', id)

    if netprofiler_device == '':
        choices = [('', '<No netprofiler device>')]
    else:
        netprofiler = DeviceManager.get_device(netprofiler_device)

        if params is not None and 'hostgroup_type' in params:
            hgt = HostGroupType.find_by_name(netprofiler,
                                             params['hostgroup_type'])
        else:
            hostgroup_type = form.get_field_value('hostgroup_type', id)

            hgt = HostGroupType.find_by_name(netprofiler, hostgroup_type)

        choices = [(group, group) for group in hgt.groups.keys()]

    field_kwargs['label'] = 'HostGroup'
    field_kwargs['choices'] = choices
def netprofiler_hostgroups(form, id, field_kwargs, params):
    """ Query netprofiler for groups within a given hostgroup. """
    netprofiler_device = form.get_field_value('netprofiler_device', id)

    if netprofiler_device == '':
        choices = [('', '<No netprofiler device>')]
    else:
        netprofiler = DeviceManager.get_device(netprofiler_device)

        if params is not None and 'hostgroup_type' in params:
            hgt = HostGroupType.find_by_name(netprofiler,
                                             params['hostgroup_type'])
        else:
            hostgroup_type = form.get_field_value('hostgroup_type', id)

            hgt = HostGroupType.find_by_name(netprofiler,
                                             hostgroup_type)

        choices = [(group, group) for group in hgt.groups.keys()]

    field_kwargs['label'] = 'HostGroup'
    field_kwargs['choices'] = choices
示例#13
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')
    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')
 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()
示例#16
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_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()
 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()
示例#19
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()
示例#20
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_find_by_name(self):
     """ Check that it finds ByLocation as a HostGroupType """
     host_group_type = HostGroupType.find_by_name(self.profiler, "ByLocation")
     self.assertEqual(host_group_type.name, "ByLocation")
 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(), [])
示例#23
0
 def test_find_by_name(self):
     """ Check that it finds ByLocation as a HostGroupType """
     host_group_type = HostGroupType.find_by_name(self.profiler,
                                                  "ByLocation")
     self.assertEqual(host_group_type.name, "ByLocation")
示例#24
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(), [])