Beispiel #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))
Beispiel #2
0
 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))
Beispiel #3
0
 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))
Beispiel #4
0
    def servicegroup_servicegroupmember_binding(self, action, fqdns, port,
                                                svcGrp):
        '''Function to bind (add) or unbind (delete) server(s) to a servicegroup.

	@param action string: add or delete
	@param fqdns list: list of FQDNs
	@param port int: Destination port for server
	@param svcGrp string: name of service group to bind servers with services to.
'''

        listOfObjs = []

        try:
            for i in range(len(fqdns)):
                listOfObjs.append(servicegroup_servicegroupmember_binding())
                listOfObjs[i].servicegroupname = svcGrp
                listOfObjs[i].servername = fqdns[i]
                listOfObjs[i].port = port

            if action == 'add':
                servicegroup_servicegroupmember_binding.add(
                    self._sess, listOfObjs)
            elif action == 'delete':
                servicegroup_servicegroupmember_binding.delete(
                    self._sess, listOfObjs)
        except nitro_exception as e:
            print('Exception::errorcode=' + str(e.errorcode) + ',message=' +
                  e.message)
        except Exception as e:
            print('Exception::message=' + str(e.args))
        else:
            return True

        return False
Beispiel #5
0
 def bind_servicegroup_server (self, client) : 
     try :
         grp = servicegroup()
         grp.servicegroupname = "svcgrp1"
         grp.servicetype = servicegroup.Servicetype.HTTP
         servicegroup.add(client, grp)
         obj = servicegroup_servicegroupmember_binding()
         obj.servicegroupname = "svcgrp1"
         obj.ip = "1.1.2.79"
         obj.port = 77
         servicegroup_servicegroupmember_binding.add(client, obj)
         print("bind_servicegroup_server - Done")
     except nitro_exception as e :
         print("Exception::bind_servicegroup_server::errorcode="+str(e.errorcode)+",message="+ e.message)
     except Exception as e:
         print("Exception::bind_servicegroup_server::message="+str(e.args))
Beispiel #6
0
    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)
Beispiel #7
0
    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)
Beispiel #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)