예제 #1
0
def get_server_type(url: str) -> str:
    try:
        provider = ConfStoreProvider(url)
        # Values supported by below key are - VM, HW, K8
        server_type = provider.get('cortx>common>setup_type')

        # For 'server_type' of 'HW' we will consider env as 'physical' and
        # for 'server_type' of 'VM' and 'K8' we will consider env as virtual
        return 'physical' if server_type == 'HW' else 'virtual'
    except Exception as error:
        logging.error('Cannot get server type (%s)', error)
        return 'unknown'
예제 #2
0
def get_server_type(url: str) -> str:
    try:
        provider = ConfStoreProvider(url)
        machine_id = provider.get_machine_id()
        server_type = provider.get(f'server_node>{machine_id}>type')

        if server_type == 'VM':
            return 'virtual'
        else:
            return 'physical'
    except Exception as error:
        logging.error('Cannot get server type (%s)', error)
        return 'unknown'
예제 #3
0
def setup_logging(url) -> None:
    provider = ConfStoreProvider(url)
    machine_id = provider.get_machine_id()
    log_path = provider.get('cortx>common>storage>log')
    log_dir = log_path + LOG_DIR_EXT + machine_id + '/hare_deployment/'
    log_file = log_dir + LOG_FILE

    create_logger_directory(log_dir)

    console = logging.StreamHandler(stream=sys.stdout)
    fhandler = logging.handlers.RotatingFileHandler(log_file,
                                                    maxBytes=LOG_FILE_SIZE,
                                                    mode='a',
                                                    backupCount=5,
                                                    encoding=None,
                                                    delay=False)
    logging.basicConfig(level=logging.INFO,
                        handlers=[console, fhandler],
                        format='%(asctime)s [%(levelname)s] %(message)s')
예제 #4
0
def _start_consul(utils: Utils,
                  stop_event: Event,
                  hare_local_dir: str,
                  hare_log_dir: str,
                  url: str):
    log_dir = hare_log_dir
    data_dir = f'{hare_local_dir}/consul/data'
    config_dir = f'{hare_local_dir}/consul/config'

    provider = ConfStoreProvider(url)
    node_id = uuid.uuid4()
    consul_endpoints = provider.get('cortx>external>consul>endpoints')
    cns_utils: ConsulUtil = ConsulUtil()
    hostname = utils.get_local_hostname()

    # remove tcp://
    peers = []
    for endpoint in consul_endpoints:
        key = endpoint.split('/')
        # Considering tcp endpoints only. Ignoring all other endpoints.
        if key[0] != 'tcp:':
            continue
        peer = ('/'.join(key[2:]))
        peers.append(peer)

    bind_addr = socket.gethostbyname(hostname)
    consul_nodename = hostname + ':' + str(node_id)[:8]
    consul_starter = ConsulStarter(utils=utils, cns_utils=cns_utils,
                                   stop_event=stop_event,
                                   log_dir=log_dir, data_dir=data_dir,
                                   config_dir=config_dir,
                                   node_id=str(node_id),
                                   node_name=consul_nodename,
                                   peers=peers, bind_addr=bind_addr)
    consul_starter.start()
    save_consul_node_name(cns_utils, consul_nodename, hostname)

    return consul_starter
예제 #5
0
def get_config_dir(url) -> str:
    provider = ConfStoreProvider(url)
    machine_id = provider.get_machine_id()
    config_path = provider.get('cortx>common>storage>local')
    return config_path + CONF_DIR_EXT + '/' + machine_id
예제 #6
0
def get_log_dir(url) -> str:
    provider = ConfStoreProvider(url)
    machine_id = provider.get_machine_id()
    log_path = provider.get('cortx>common>storage>log')
    return log_path + LOG_DIR_EXT + machine_id