Beispiel #1
0
 def POST(self):
     ship_name, error = self.get_post_parameter('name')
     if error:
         return self.status_error(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('Incorrect ship name: {}'.format(ship_name))
     set_ship_name(ship_name)
     return self.status_ok()
Beispiel #2
0
def _save_runtime_settings():
    consul_settings = {}
    consul_settings['is_commander'] = is_ship_commander()
    consul_settings['name'] = get_ship_name()
    consul_settings['ships'] = get_other_ship_ips()
    consul_settings['datacenter'] = get_current_datacenter()
    consul_settings['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))
Beispiel #3
0
 def POST(self):
     ship_name, error = self.get_post_parameter('name')
     if error:
         return self.status_error(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(
             'Incorrect ship name: {}'.format(ship_name))
     set_ship_name(ship_name)
     return self.status_ok()
Beispiel #4
0
def _save_runtime_settings():
    consul_settings = {}
    consul_settings['is_commander'] = is_ship_commander()
    consul_settings['name'] = get_ship_name()
    consul_settings['ships'] = get_other_ship_ips()
    consul_settings['datacenter'] = get_current_datacenter()
    consul_settings['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))
Beispiel #5
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: %s', 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.')
Beispiel #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: %s', 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.')