예제 #1
0
파일: halt.py 프로젝트: golovast/scalarizr
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.halt")
    logger.info("Starting halt script...")

    try:
        try:
            action = sys.argv[1]
        except IndexError:
            logger.error("Invalid execution parameters. argv[1] must be presented")
            sys.exit()

        if action == "start" or action == "stop":

            msg_service = bus.messaging_service
            producer = msg_service.get_producer()

            msg = msg_service.new_message(Messages.INT_SERVER_HALT)
            producer.send(Queues.CONTROL, msg)

            # 30 seconds for termination
            start = time.time()
            while not msg.is_handled():
                if time.time() - start < 30:
                    time.sleep(1)
                else:
                    break

    except (BaseException, Exception), e:
        logger.exception(e)
예제 #2
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.reboot")
    logger.info("Starting reboot script...")

    try:
        try:
            action = sys.argv[1]
        except IndexError:
            logger.error(
                "Invalid execution parameters. argv[1] must be presented")
            sys.exit()

        if action == "start" or action == "stop":
            msg_service = bus.messaging_service
            producer = msg_service.get_producer()

            msg = msg_service.new_message(Messages.INT_SERVER_REBOOT)
            producer.send(Queues.CONTROL, msg)

            # 30 seconds for termination
            start = time.time()
            while not msg.is_handled():
                if time.time() - start < 30:
                    time.sleep(1)
                else:
                    break

    except (BaseException, Exception), e:
        logger.exception(e)
예제 #3
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.update")
    logger.info("Starting update script...")

    if disttool.is_debian_based():
        logger.info("Updating scalarizr with Apt")
        system2("apt-get -y install scalarizr", shell=True)
    elif disttool.is_redhat_based():
        logger.info("Updating scalarizr with Yum")
        system2("yum -y update scalarizr", shell=True)
    else:
        logger.error("Don't know how to update scalarizr on %s", " ".join(disttool.linux_dist()))
예제 #4
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.update")
    logger.info("Starting update script...")

    if disttool.is_debian_based():
        logger.info("Updating scalarizr with Apt")
        system2("apt-get -y install scalarizr", shell=True)
    elif disttool.is_redhat_based():
        logger.info("Updating scalarizr with Yum")
        system2("yum -y update scalarizr", shell=True)
    else:
        logger.error("Don't know how to update scalarizr on %s",
                     " ".join(disttool.linux_dist()))
예제 #5
0
파일: udev.py 프로젝트: golovast/scalarizr
def main():
	init_script()	
	logger = logging.getLogger("scalarizr.scripts.udev")
	logger.info("Starting udev script...")
	
	try:
		initd = initdv2.lookup('scalarizr')
		if initd.running:
			msg_service = bus.messaging_service
			producer = msg_service.get_producer()
		
			msg = msg_service.new_message(Messages.INT_BLOCK_DEVICE_UPDATED)
			for k, v in os.environ.items():
				msg.body[k.lower()] = v
			producer.send(Queues.CONTROL, msg)
	
	except (BaseException, Exception), e:
		logger.exception(e)
예제 #6
0
def main():
    global ini
    init_script()

    #23.09.11-------------------------------------------------------------------------------------------------
    com_dict = {
        'list-roles': ListRolesCommand,
        'get-latest-version': GetlatestVersionCommand,
        'list-ebs-mountpoints': ListEbsMountpointsCommand,
        'get-https-certificate': GetHttpsCertificateCommand,
        'list-role-params': ListRoleParamsCommand,
        'list-virtualhosts': ListVirtualhostsCommand,
        'list-scripts': ListScriptsCommand,
        'list-messages': ListMessagesCommand,
        'message-details': MessageDetailsCommand,
        'mark-as-unhandled': MarkAsUnhandledCommand,
        'help': Help,
        '--help': Help,
        '-h': Help
    }
    str = None
    com = None
    com_find = None

    if len(sys.argv) > 1:
        com_find = 1
    if com_find and com_dict.has_key(sys.argv[1]):
        if sys.argv[2:]:
            str = sys.argv[2:]
        #select command class in list and create object of this class with param
        try:
            com = com_dict.get(sys.argv[1])(str)
            if com:
                if isinstance(com, Help):
                    com.run(com_dict)
                else:
                    com.run()
        except Exception, e:
            com = Help(com_dict)
            com.run()
            raise LookupError("Cant execute command or option. Error: %s" %
                              (e))
예제 #7
0
def main():
	global ini
	init_script()

#23.09.11-------------------------------------------------------------------------------------------------
	com_dict={'list-roles':ListRolesCommand,
			'get-latest-version':GetlatestVersionCommand,
			'list-ebs-mountpoints':ListEbsMountpointsCommand,
			'get-https-certificate':GetHttpsCertificateCommand,
			'list-role-params':ListRoleParamsCommand,
			'list-virtualhosts':ListVirtualhostsCommand,
			'list-scripts':ListScriptsCommand,
			'list-messages':ListMessagesCommand,
			'message-details':MessageDetailsCommand,
			'mark-as-unhandled':MarkAsUnhandledCommand,

			'help':Help,
			'--help':Help,
			'-h':Help
		}
	str=None
	com=None
	com_find=None

	if len(sys.argv)>1:
		com_find=1
	if com_find and com_dict.has_key(sys.argv[1]):
		if sys.argv[2:]:
			str=sys.argv[2:]
		#select command class in list and create object of this class with param
		try:
			com=com_dict.get(sys.argv[1])(str)
			if com:
				if isinstance(com, Help):
					com.run(com_dict)
				else:
					com.run()
		except Exception, e:
			com=Help(com_dict)
			com.run()
			raise LookupError("Cant execute command or option. Error: %s" % (e))
예제 #8
0
def main():

    parser = OptionParser(usage="Usage: %prog [options] key=value key2=value2 ...")
    parser.add_option("-e", "--endpoint", dest="endpoint", default=None, help="Messaging server URL")
    parser.add_option("-q", "--queue", dest="queue", help="Queue to send message into")
    parser.add_option("-n", "--name", dest="name", help="Message name")
    parser.add_option("-f", "--file", dest="msgfile", help="File with message")

    (options, args) = parser.parse_args()

    if not options.queue or (not options.msgfile and not options.name):
        print parser.format_help()
        sys.exit()


    init_script()

    msg_service = bus.messaging_service
    producer = msg_service.get_producer()
    if options.endpoint:
        producer.endpoint = options.endpoint

    msg = msg_service.new_message()

    if options.msgfile:
        str = None
        with open(options.msgfile, 'r') as fp:
            str = fp.read()
        if str:
            msg.fromxml(str)

    if msg.name:
        msg.name = options.name

    for pair in args:
        k, v = pair.split("=")
        msg.body[k] = v

    producer.send(options.queue, msg)

    print "Done"
예제 #9
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.udev")
    logger.info("Starting udev script...")

    try:
        initd = initdv2.lookup('scalarizr')
        if initd.running:
            channel = '/tmp/udev-block-device'
            with open(channel, 'w+') as fp:
                fp.write(os.environ['DEVNAME'])

            msg_service = bus.messaging_service
            producer = msg_service.get_producer()

            msg = msg_service.new_message(Messages.INT_BLOCK_DEVICE_UPDATED)
            for k, v in os.environ.items():
                msg.body[k.lower()] = v
            producer.send(Queues.CONTROL, msg)

    except (BaseException, Exception), e:
        logger.exception(e)
예제 #10
0
				if str:
					msg.fromxml(str)
			else:
				msg.body = kv

			if options.name:
				msg.name = options.name

			producer.send(options.queue, msg)

			print "Done"		

		if options.reinit:
			print 'Call scalarizr to reinitialize role (see /var/log/scalarizr.log for results)'
			
			init_script()

			conn = bus.db
			cur = conn.cursor()
			try:
				with open('/etc/scalr/private.d/.state', 'w') as fp:
					fp.write('bootstrapping')
				
				msg_service = bus.messaging_service
				msg = msg_service.new_message()				
								
				cur.execute('SELECT message '
						'FROM p2p_message '
						'WHERE message_name = ? '
						'ORDER BY id DESC '
						'LIMIT 1', ('HostInitResponse', )
예제 #11
0
                            print 'Unknown message format'
                            sys.exit(1)
            else:
                msg.body = kv

            if options.name:
                msg.name = options.name

            producer.send(options.queue, msg)

            print "Done"

        if options.reinit:
            print 'Call scalarizr to reinitialize role (see /var/log/scalarizr.log for results)'

            init_script()

            conn = bus.db
            cur = conn.cursor()
            try:
                with open('/etc/scalr/private.d/.state', 'w') as fp:
                    fp.write('bootstrapping')

                msg_service = bus.messaging_service
                msg = msg_service.new_message()

                cur.execute(
                    'SELECT message, format '
                    'FROM p2p_message '
                    'WHERE message_name = ? '
                    'ORDER BY id DESC '