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')
Beispiel #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')
    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')
Beispiel #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')