コード例 #1
0
 def add_remove_services(self, grpname, ip_ports):
     """ Reconfigures service group membership to be the
     same as supplied list of ip and port
     """
     to_add = ip_ports
     to_remove = []
     try:
         bindings = servicegroup_servicegroupmember_binding.get(
             self.ns_session, grpname)
         existing = [(b.ip, b.port) for b in bindings if b.port != 0]
         to_remove = list(set(existing) - set(ip_ports))
         to_add = list(set(ip_ports) - set(existing))
         to_leave = list(set(ip_ports) & set(existing))
     except nitro_exception:
         pass  # no bindings
     for s in to_remove:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Unbinding %s:%s from service group %s " % (s[0], s[1], grpname))
         servicegroup_servicegroupmember_binding.delete(self.ns_session,
                                                        binding)
     for s in to_add:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Binding %s:%s from service group %s " % (s[0], s[1], grpname))
         servicegroup_servicegroupmember_binding.add(self.ns_session,
                                                     binding)
     for s in to_leave:
         logger.info("Service %s:%s is already bound to  service group %s" % (s[0], s[1], grpname))
コード例 #2
0
ファイル: netscaler.py プロジェクト: mikebryant/nitrox
 def _configure_services(self, grpname, srvrs):
     to_add = srvrs
     to_remove = []
     try:
         bindings = servicegroup_servicegroupmember_binding.get(
             self.ns_session, grpname)
         existing = [(b.ip, b.port) for b in bindings if b.port != 0]
         to_remove = list(set(existing) - set(srvrs))
         to_add = list(set(srvrs) - set(existing))
         to_leave = list(set(srvrs) & set(existing))
     except nitro_exception as e:
         pass  # no bindings
     for s in to_remove:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Unbinding %s:%s from service group %s " % (s[0], s[1],
                     grpname))
         servicegroup_servicegroupmember_binding.delete(self.ns_session,
                                                        binding)
     for s in to_add:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Binding %s:%s from service group %s " %
                     (s[0], s[1], grpname))
         servicegroup_servicegroupmember_binding.add(self.ns_session,
                                                     binding)
     for s in to_leave:
         logger.info("%s:%s is already bound to  service group %s"
                     % (s[0], s[1], grpname))
コード例 #3
0
def servicemembers_identical(client, module):
    log('servicemembers_identical')
    try:
        # count() raises nitro exception instead of returning 0
        count = servicegroup_servicegroupmember_binding.count(
            client, module.params['servicegroupname'])
        if count > 0:
            servicegroup_members = servicegroup_servicegroupmember_binding.get(
                client, module.params['servicegroupname'])
        else:
            servicegroup_members = []
    except nitro_exception as e:
        if e.errorcode == 258:
            servicegroup_members = []
        else:
            raise

    log('servicemembers %s' % servicegroup_members)
    module_servicegroups = get_configured_service_members(client, module)
    log('Number of service group members %s' % len(servicegroup_members))
    if len(servicegroup_members) != len(module_servicegroups):
        return False

    # Fallthrough to member evaluation
    identical_count = 0
    for actual_member in servicegroup_members:
        for member in module_servicegroups:
            if member.has_equal_attributes(actual_member):
                identical_count += 1
                break
    if identical_count != len(servicegroup_members):
        return False

    # Fallthrough to success
    return True
コード例 #4
0
ファイル: netscaler.py プロジェクト: renato-farias/nitrox
 def _configure_services(self, grpname, srvrs):
     to_add = srvrs
     to_remove = []
     try:
         bindings = servicegroup_servicegroupmember_binding.get(
             self.ns_session, grpname)
         existing = [(b.ip, b.port) for b in bindings if b.port != 0]
         to_remove = list(set(existing) - set(srvrs))
         to_add = list(set(srvrs) - set(existing))
         to_leave = list(set(srvrs) & set(existing))
     except nitro_exception as e:
         pass  # no bindings
     for s in to_remove:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Unbinding %s:%s from service group %s " %
                     (s[0], s[1], grpname))
         servicegroup_servicegroupmember_binding.delete(
             self.ns_session, binding)
     for s in to_add:
         binding = servicegroup_servicegroupmember_binding()
         binding.servicegroupname = grpname
         binding.ip = s[0]
         binding.port = s[1]
         logger.info("Binding %s:%s from service group %s " %
                     (s[0], s[1], grpname))
         servicegroup_servicegroupmember_binding.add(
             self.ns_session, binding)
     for s in to_leave:
         logger.info("%s:%s is already bound to  service group %s" %
                     (s[0], s[1], grpname))
コード例 #5
0
def get_actual_service_members(client, module):
    try:
        # count() raises nitro exception instead of returning 0
        count = servicegroup_servicegroupmember_binding.count(client, module.params['servicegroupname'])
        if count > 0:
            servicegroup_members = servicegroup_servicegroupmember_binding.get(client, module.params['servicegroupname'])
        else:
            servicegroup_members = []
    except nitro_exception as e:
        if e.errorcode == 258:
            servicegroup_members = []
        else:
            raise
    return servicegroup_members
コード例 #6
0
ファイル: netscaler.py プロジェクト: mikebryant/nitrox
    def _add_service(self, grpname, srvr_ip, srvr_port):
        try:
            bindings = servicegroup_servicegroupmember_binding.get(
                self.ns_session, grpname)
            for binding in bindings:
                if binding.ip == srvr_ip and str(binding.port) == srvr_port:
                    logger.info("Service %s:%s is already bound to service \
                                group %s " % (srvr_ip, srvr_port, grpname))
                    return

        except nitro_exception as e:
            pass
        binding = servicegroup_servicegroupmember_binding()
        binding.servicegroupname = grpname
        binding.ip = srvr_ip
        binding.port = srvr_port
        servicegroup_servicegroupmember_binding.add(self.ns_session, binding)
コード例 #7
0
ファイル: netscaler.py プロジェクト: renato-farias/nitrox
    def _add_service(self, grpname, srvr_ip, srvr_port):
        try:
            bindings = servicegroup_servicegroupmember_binding.get(
                self.ns_session, grpname)
            for binding in bindings:
                if binding.ip == srvr_ip and str(binding.port) == srvr_port:
                    logger.info("Service %s:%s is already bound to service \
                                group %s " % (srvr_ip, srvr_port, grpname))
                    return

        except nitro_exception as e:
            pass
        binding = servicegroup_servicegroupmember_binding()
        binding.servicegroupname = grpname
        binding.ip = srvr_ip
        binding.port = srvr_port
        servicegroup_servicegroupmember_binding.add(self.ns_session, binding)
コード例 #8
0
    def add_service(self, grpname, srvr_ip, srvr_port):
        """Add a service(ip, port) to an existing service group."""
        try:
            bindings = servicegroup_servicegroupmember_binding.get(
                self.ns_session, grpname)
            for binding in bindings:
                if binding.ip == srvr_ip and binding.port == srvr_port:
                    logger.info('Service %s:%s is already bound to service \
                                group %s ' % (srvr_ip, srvr_port, grpname))
                    return

        except nitro_exception:
            pass
        binding = servicegroup_servicegroupmember_binding()
        binding.servicegroupname = grpname
        binding.ip = srvr_ip
        binding.port = srvr_port
        servicegroup_servicegroupmember_binding.add(self.ns_session, binding)
    def service_group_servicemembers_identical():
        log('service_group_servicemembers_identical')
        service_group_members = servicegroup_servicegroupmember_binding.get(
            client, module.params['servicegroupname'])
        module_service_groups = get_servicegroups_from_module_params()
        log('Number of service group members %s' % len(service_group_members))
        if len(service_group_members) != len(module_service_groups):
            return False

        # Fallthrough to member evaluation
        identical_count = 0
        for actual_member in service_group_members:
            for member in module_service_groups:
                if member.has_equal_attributes(actual_member):
                    identical_count += 1
                    break
        if identical_count != len(service_group_members):
            return False

        # Fallthrough to success
        return True
    def delete_all_servicegroup_members():
        log('delete_all_servicegroup_members')
        if servicegroup_servicegroupmember_binding.count(
                client, module.params['servicegroupname']) == 0:
            return
        service_group_members = servicegroup_servicegroupmember_binding.get(
            client, module.params['servicegroupname'])
        log('len %s' % len(service_group_members))
        log('count %s' % servicegroup_servicegroupmember_binding.count(
            client, module.params['servicegroupname']))
        for member in service_group_members:
            log('%s' % dir(member))
            log('ip %s' % member.ip)
            log('servername %s' % member.servername)
            if all([
                    hasattr(member, 'ip'),
                    member.ip is not None,
                    hasattr(member, 'servername'),
                    member.servername is not None,
            ]):
                member.ip = None

            member.servicegroupname = module.params['servicegroupname']
            servicegroup_servicegroupmember_binding.delete(client, member)