Esempio n. 1
0
 def on_post(self, req, resp):
     ship_name, error = self.get_post_parameter(req, 'name')
     if error:
         return self.status_error(resp, error)
     other_ship_names = [get_ship_name(ip) for ip in get_other_ship_ips()]
     name_taken = ship_name in other_ship_names
     if not ship_name or ship_name == 'None' or name_taken:
         return self.status_error(
             resp, 'Incorrect ship name: {}'.format(ship_name))
     set_ship_name(ship_name)
     return self.status_ok(resp)
Esempio n. 2
0
def _save_runtime_settings():
    consul_settings = {
        'is_commander': is_ship_commander(),
        'name': get_ship_name(),
        'ships': get_other_ship_ips(),
        'datacenter': get_current_datacenter(),
        'dockyards': alias.get_list(),
    }

    with open(consul_config.RUNTIME_SETTINGS_PATH, 'w') as runtime_settings:
        runtime_settings.write(json.dumps(consul_settings, sort_keys=True, indent=4))
Esempio n. 3
0
    def on_post(self, req, resp):
        consul_host, error = self.get_post_parameter(req, 'host')
        if error:
            return self.status_error(resp, error)
        ship = get_ship_name()
        local_services_data = {
            key: kv.kv_get(key)
            for key in get_local_services_from_kv_store()
        }

        armada_size = _get_armada_size()
        if armada_size > 1:
            return self.status_error(
                resp,
                '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 Exception as e:
            get_logger().exception(e)
            return self.status_error(
                resp, '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 = xmlrpc.client.Server(
                'http://localhost:9001/RPC2')
            hermes_init_output = supervisor_server.supervisor.startProcessGroup(
                'hermes_init')
            get_logger().info('hermes_init start: %s', hermes_init_output)
            set_ship_name(ship)
            for key, data in six.iteritems(local_services_data):
                kv.kv_set(key, data)
            return self.status_ok(resp)
        return self.status_error(resp, 'Waiting for armada restart timed out.')