Esempio n. 1
0
    def lbvserver_servicegroup_binding(self, action, lbvservername,
                                       servicegroupname):
        '''Function to add or remove a servicegroup from an lbvserver.

	@param action string: add or delete
	@param lbvservername string: Name of lbvserver
	@param servicegroupname string: Name of servicegroup name
'''

        obj = lbvserver_servicegroup_binding()
        obj.name = lbvservername
        obj.servicegroupname = servicegroupname

        try:
            if action == 'add':
                lbvserver_servicegroup_binding.add(self._sess, obj)
            elif action == 'delete':
                lbvserver_servicegroup_binding.delete(self._sess, obj)
        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
Esempio n. 2
0
def call_nitro_commands(ns_session):
    try:
        ns_session.clear_config(force=True, level='full')
        logging.debug('Clear config executed')
        needed_features = [
            nsfeature.Feature.CS, nsfeature.Feature.LB, nsfeature.Feature.SSL,
            nsfeature.Feature.RESPONDER, nsfeature.Feature.REWRITE
        ]
        ns_session.enable_features(needed_features)

        logging.debug('Adding CS vserver')
        csvserver_instance = csvserver()
        csvserver_instance.name = 'drinks_sample'
        csvserver_instance.ipv46 = '127.0.0.1'
        csvserver_instance.servicetype = 'http'
        csvserver_instance.port = '443'
        csvserver_instance.add(ns_session, csvserver_instance)

        logging.debug('Adding LB vserver')
        lbvserver_instance = lbvserver()
        lbvserver_instance.name = 'lbvs_hotdrink_http_example'
        lbvserver_instance.ipv46 = '0.0.0.0'
        lbvserver_instance.port = 0
        lbvserver_instance.servicetype = 'http'
        lbvserver_instance.add(ns_session, lbvserver_instance)

        logging.debug('Adding servicegroup')
        servicegroup_instance = servicegroup()
        servicegroup_instance.servicegroupname = 'sg_hotdrink_http_example'
        servicegroup_instance.servicetype = 'http'
        servicegroup_instance.add(ns_session, servicegroup_instance)

        logging.debug('Adding servieegroup binding')
        servicegroup_servicegroupmember_binding_instance = servicegroup_servicegroupmember_binding(
        )
        servicegroup_servicegroupmember_binding_instance.servicegroupname = 'sg_hotdrink_http_example'
        servicegroup_servicegroupmember_binding_instance.ip = '172.100.100.3'
        servicegroup_servicegroupmember_binding_instance.port = 80
        servicegroup_servicegroupmember_binding_instance.add(
            ns_session, servicegroup_servicegroupmember_binding_instance)

        logging.debug('Adding servicegroup lb vserver binding')
        lbvserver_servicegroup_binding_instance = lbvserver_servicegroup_binding(
        )
        lbvserver_servicegroup_binding_instance.name = 'lbvs_hotdrink_http_example'
        lbvserver_servicegroup_binding_instance.servicegroupname = 'sg_hotdrink_http_example'
        lbvserver_servicegroup_binding_instance.add(
            ns_session, lbvserver_servicegroup_binding_instance)

        logging.debug('SUCCESS: Configuration completed')
    except Exception as e:
        logging.error('FAILURE: Error during configuration: {}'.format(
            e.message))
Esempio n. 3
0
    def _bind_service_group_lb(self, lbname, grpname):
        try:
            bindings = lbvserver_servicegroup_binding.get(self.ns_session,
                                                          lbname)
            for b in bindings:
                if b.name == lbname and b.servicegroupname == grpname:
                    logger.info("LB %s is already bound to service group %s"
                                % (lbname, grpname))
                    return
        except nitro_exception:
            pass

        binding = lbvserver_servicegroup_binding()
        binding.name = lbname
        binding.servicegroupname = grpname
        lbvserver_servicegroup_binding.add(self.ns_session, binding)
Esempio n. 4
0
    def _bind_service_group_lb(self, lbname, grpname):
        try:
            bindings = lbvserver_servicegroup_binding.get(self.ns_session,
                                                          lbname)
            for b in bindings:
                if b.name == lbname and b.servicegroupname == grpname:
                    logger.info("LB %s is already bound to service group %s"
                                % (lbname, grpname))
                    return
        except nitro_exception as e:
            pass

        binding = lbvserver_servicegroup_binding()
        binding.name = lbname
        binding.servicegroupname = grpname
        lbvserver_servicegroup_binding.add(self.ns_session, binding)