Exemple #1
0
def main():
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument("-c", help="config: -c <json>", dest="config")
        parser.add_argument("-p", help="pidfile: -p <file name>", dest="pidfile")

        args = parser.parse_args()
        print args.config
        print args.pidfile

        cfg = AgentConfigParser()

        cfg.read(os.path.abspath(os.path.join(os.path.dirname(__file__), '../config.cfg')))
        cfg = cfg.as_dic()
        LOGGER.info("Attempting to start monitoring for config %s under pidfile %s" % (args.config, args.pidfile))

        try:
            instanceMonitor = InstanceMonitor(pidfile=args.pidfile,
                                              instance_configuration_json=simplejson.loads(args.config), cfg=cfg)
        except Exception, e:
            LOGGER.error("Exception while trying to start monitor for config %s: %s" % (args.config, e))

        instanceMonitor.start()

        exit(0)
Exemple #2
0
 def shutdown_monitoring(instanceid,
                         jsondata,
                         instances=None,
                         notifier=None):
     cfg = AgentConfigParser()
     cfg.read(
         os.path.abspath(
             os.path.join(os.path.dirname(__file__), '../config.cfg')))
     cfg = cfg.as_dic()
     LOGGER.info(cfg)
     time.sleep(3)
     data1 = {"method": "stopmonitor", "arg": instanceid}
     msg = json.dumps(data1)
     try:
         api = API(cfg)
         EVENT_LOGGER.info("[*] EVENT calling RPC stopmonitor arg %s" %
                           instanceid)
         response = api.call(msg)
         ###shutdown monitoring for this
         LOGGER.info(
             "<<<<<<<<<<<<<<<<>>>>>>>>>>>>>> -instance is shutting down %r"
             % response)
         LOGGER.info("SHUTTING DOWN ALL MONITORING FOR THIS INSTANCE")
     except Exception, e:
         exc_type, exc_obj, exc_tb = sys.exc_info()[:]
         LOGGER.error("Exception while trying toshutting down: %s, %s" %
                      (exc_type, exc_tb.tb_lineno))
         EVENT_LOGGER.info(
             "[1e][EVENT] EXCEPTION for Event stopmonitor arg %s" %
             instanceid)
         EVENT_LOGGER.error(
             "[2e][EVENT] Exception while executing shutdown_instance: %s, %s"
             % (exc_type, exc_tb.tb_lineno))
Exemple #3
0
def main():
    try:

        parser = argparse.ArgumentParser()
        parser.add_argument("-l",
                            help="listener : -l start or -l stop",
                            dest="listener")
        parser.add_argument("-s",
                            help="server: -s start or -s stop",
                            dest="server")
        parser.add_argument("-a",
                            help="all server: -a start or -a stop",
                            dest="allserver")

        args = parser.parse_args()
        print args.allserver
        print args.listener
        print args.server

        # cfg = ConfigParser.ConfigParser()
        cfg = AgentConfigParser()

        cfg.read(
            os.path.abspath(
                os.path.join(os.path.dirname(__file__), '../config.cfg')))
        cfg = cfg.as_dic()

        # launch_rpcserver(ConfigSectionMap("RabbitMQ", cfg), "start")
        # exit(0)
        if args.allserver:
            # this is not working , since daemon process kills parent process

            launch_allserver(cfg, args.allserver, LAUNCH_OPTIONS.keys())
        else:
            if args.listener:
                launch_listener(cfg, args.listener)

            if args.server:
                launch_rpcserver(cfg, args.server)

                # thread = eventlet.spawn(launch_rpcserver, ConfigSectionMap("RabbitMQ", cfg))
        # print "wait"

        exit(0)
    except RuntimeError as excp:
        sys.stderr.write("ERROR: %s\n" % excp)
        sys.exit(1)
Exemple #4
0
    def shutdown_instance(instanceid,
                          jsonmessage,
                          instances=None,
                          notifier=None):
        """
        :param jsondata:
        :param notifier:
        :return:

        - Needs to call negotiator script for UFR shutdown (shutdown for UFR means turn off network interfaces)
        - Needs to make CLI call to axcons for FT shutdown, like so: /opt/ft/bin/axcons instance-000000d5 PVM set Preferred
          CoServer 1 From Ax2
        """
        cfg = AgentConfigParser()
        cfg.read(
            os.path.abspath(
                os.path.join(os.path.dirname(__file__), '../config.cfg')))
        cfg = cfg.as_dic()
        LOGGER.info(cfg)

        data = {"method": "shutdown_instance", "arg": instanceid}
        msg = json.dumps(data)
        try:
            api = API(cfg)
            EVENT_LOGGER.info(
                "[1][EVENT] calling RPC shutdown _instance arg %s" %
                instanceid)
            EVENT_LOGGER.info(
                "[2][EVENT] calling RPC shutdown _instance arg %s" %
                jsonmessage)
            response = api.call(msg)
            LOGGER.info(
                "<<<<<<<<<<<<<<<<>>>>>>>>>>>>>> -instance is shutting down %r"
                % response)
            LOGGER.info("Executing scripts")
        except Exception, e:
            exc_type, exc_obj, exc_tb = sys.exc_info()[:]
            LOGGER.error("Exception while executing scripts: %s, %s" %
                         (exc_type, exc_tb.tb_lineno))
            EVENT_LOGGER.info(
                "[1e][EVENT] EXCEPTION for Event shutdown_instance arg %s" %
                instanceid)
            EVENT_LOGGER.error(
                "[2e][EVENT] Exception while executing shutdown_instance: %s, %s"
                % (exc_type, exc_tb.tb_lineno))
Exemple #5
0
    def call(self, args):
        self.response = None
        self.corr_id = str(uuid.uuid4())
        self.channel.basic_publish(exchange=self.exchange,
                                   routing_key=self.routing_key,
                                   properties=pika.BasicProperties(
                                       reply_to=self.callback_queue,
                                       correlation_id=self.corr_id,
                                   ),
                                   body=args)
        while self.response is None:
            self.connection.process_data_events(0)
        return self.response


cfg = AgentConfigParser()
cfg.read(
    os.path.abspath(os.path.join(os.path.dirname(__file__), '../config.cfg')))
cfg = cfg.as_dic()

print sys.argv
if len(sys.argv) == 1:
    print "command line argument missing or not correct \n"
    print "> python client.py configure  \n\t\t Use this to configure"
    print "> python client.py stopmonitor  \n\t\t Use this to stop mointoring"
    print "> python client.py monitor \n\t\t use this option to start monitoring ."
    print "> python client.py execute \n\t\t use this option to execute negoitator script."
    print "> python client.py getconfig all \n\t\t use this option to get all config data."
    print "> python client.py heartbeat {hostname} \n\t\t use this option to get all config data."
    print "> python client.py getagentconfig  \n\t\t use this option to get application configuration."