Exemplo n.º 1
0
    def POST(self):
        consul_host, error = self.get_post_parameter('host')
        if error:
            return self.status_error(error)

        armada_size = _get_armada_size()
        if armada_size > 1:
            return self.status_error('Currently only single ship armadas can join the others. '
                                     'Your armada has size: {0}.'.format(armada_size))

        try:
            agent_self_dict = consul_query('agent/self', consul_address='{0}:8500'.format(consul_host))
            datacenter = agent_self_dict['Config']['Datacenter']
        except:
            return self.status_error('Could not read remote host datacenter address.')

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(consul_mode=consul_config.ConsulMode.CLIENT,
                                      ship_ips=[consul_host],
                                      datacenter=datacenter)
        else:
            override_runtime_settings(ship_ips=[consul_host] + get_other_ship_ips(),
                                      datacenter=datacenter)

        if _restart_consul():
            supervisor_server = xmlrpclib.Server('http://localhost:9001/RPC2')
            hermes_init_output = supervisor_server.supervisor.startProcessGroup('hermes_init')
            get_logger().info('hermes_init start: {}'.format(hermes_init_output))
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 2
0
    def POST(self):
        consul_host, error = self.get_post_parameter('host')
        if error:
            return self.status_error(error)

        armada_size = _get_armada_size()
        if armada_size > 1:
            return self.status_error(
                'Currently only single ship armadas can join the others. '
                'Your armada has size: {armada_size}.'.format(
                    armada_size=armada_size))

        try:
            agent_self_dict = consul_query(
                'agent/self',
                consul_address='{consul_host}:8500'.format(**locals()))
            datacenter = agent_self_dict['Config']['Datacenter']
        except:
            return self.status_error(
                'Could not read remote host datacenter address.')

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(
                consul_mode=consul_config.ConsulMode.CLIENT,
                ship_ips=[consul_host],
                datacenter=datacenter)
        else:
            override_runtime_settings(ship_ips=[consul_host] +
                                      get_other_ship_ips(),
                                      datacenter=datacenter)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 3
0
    def POST(self):
        consul_host, error = self.get_post_parameter('host')
        if error:
            return self.status_error(error)

        armada_size = _get_armada_size()
        if armada_size > 1:
            return self.status_error('Currently only single ship armadas can join the others. '
                                     'Your armada has size: {armada_size}.'.format(armada_size=armada_size))

        try:
            agent_self_dict = consul_query('agent/self', consul_address='{consul_host}:8500'.format(**locals()))
            datacenter = agent_self_dict['Config']['Datacenter']
        except:
            return self.status_error('Could not read remote host datacenter address.')

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(consul_mode=consul_config.ConsulMode.CLIENT,
                                      ship_ips=[consul_host],
                                      datacenter=datacenter)
        else:
            override_runtime_settings(ship_ips=[consul_host] + get_other_ship_ips(),
                                      datacenter=datacenter)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 4
0
    def POST(self):
        current_consul_mode = _get_current_consul_mode()

        if current_consul_mode == consul_config.ConsulMode.SERVER:
            return self.status_ok({'message': 'Ship is already in server mode.'})

        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            return self.status_error('Ship must join armada to be promoted to server.')

        override_runtime_settings(consul_mode=consul_config.ConsulMode.SERVER)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 5
0
    def POST(self):
        current_consul_mode = _get_current_consul_mode()

        if current_consul_mode == consul_config.ConsulMode.SERVER:
            return self.status_ok(
                {'message': 'Ship is already in server mode.'})

        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            return self.status_error(
                'Ship must join armada to be promoted to server.')

        override_runtime_settings(consul_mode=consul_config.ConsulMode.SERVER)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 6
0
    def POST(self):
        consul_host, error = self.get_post_parameter('host')
        if error:
            return self.status_error(error)

        ship = get_ship_name()
        local_services = kv.kv_list('ships/{}/service/'.format(ship)) or []
        local_services_data = {key: kv.kv_get(key) for key in local_services}

        armada_size = _get_armada_size()
        if armada_size > 1:
            return self.status_error(
                'Currently only single ship armadas can join the others. '
                'Your armada has size: {0}.'.format(armada_size))

        try:
            agent_self_dict = consul_query(
                'agent/self', consul_address='{0}:8500'.format(consul_host))
            datacenter = agent_self_dict['Config']['Datacenter']
        except:
            return self.status_error(
                'Could not read remote host datacenter address.')

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(
                consul_mode=consul_config.ConsulMode.CLIENT,
                ship_ips=[consul_host],
                datacenter=datacenter)
        else:
            override_runtime_settings(ship_ips=[consul_host] +
                                      get_other_ship_ips(),
                                      datacenter=datacenter)

        if _restart_consul():
            supervisor_server = xmlrpclib.Server('http://localhost:9001/RPC2')
            hermes_init_output = supervisor_server.supervisor.startProcessGroup(
                'hermes_init')
            get_logger().info(
                'hermes_init start: {}'.format(hermes_init_output))
            set_ship_name(ship)
            for key, data in local_services_data.items():
                kv.kv_set(key, data)
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 7
0
    def POST(self):
        ship_name, error = self.get_post_parameter('name')
        if error:
            return self.status_error(error)
        if not ship_name or ship_name == 'None':
            try:
                ship_name = get_ship_name()
            except:
                ship_name = str(random.randrange(1000000))

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(ship_name=ship_name,
                                      ship_ips=[],
                                      datacenter='dc-' + str(random.randrange(1000000)))
        else:
            override_runtime_settings(ship_name=ship_name)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')
Exemplo n.º 8
0
    def POST(self):
        ship_name, error = self.get_post_parameter('name')
        if error:
            return self.status_error(error)
        if not ship_name or ship_name == 'None':
            try:
                ship_name = get_ship_name()
            except:
                ship_name = str(random.randrange(1000000))

        current_consul_mode = _get_current_consul_mode()
        if current_consul_mode == consul_config.ConsulMode.BOOTSTRAP:
            override_runtime_settings(ship_name=ship_name,
                                      ship_ips=[],
                                      datacenter='dc-' +
                                      str(random.randrange(1000000)))
        else:
            override_runtime_settings(ship_name=ship_name)

        if _restart_consul():
            return self.status_ok()
        return self.status_error('Waiting for armada restart timed out.')