def _create_cosmo_wd_settings(self, settings=None): directory_settings = utils.CloudifyWorkingDirectorySettings() directory_settings.set_management_server('localhost') utils.delete_cloudify_working_dir_settings() utils.dump_cloudify_working_dir_settings( settings or directory_settings, update=False) utils.dump_configuration_file()
def provider_init(provider, reset_config): logger = get_logger() provider_deprecation_notice() if os.path.exists(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = ('Current directory is already initialized. ' 'Use the "-r" flag to force ' 'reinitialization (might overwrite ' 'provider configuration files if exist).') raise exceptions.CloudifyCliError(msg) else: # resetting provider configuration logger.debug('resetting configuration...') _provider_init(provider, reset_config) logger.info("Configuration reset complete") return logger.info("Initializing Cloudify") provider_module_name = _provider_init(provider, reset_config) settings = utils.CloudifyWorkingDirectorySettings() settings.set_provider(provider_module_name) settings.set_is_provider_config(True) utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() logger.info("Initialization complete")
def use(management_ip, rest_port): logger = get_logger() # first check this server is available. client = utils.get_rest_client( manager_ip=management_ip, rest_port=rest_port) try: status_result = client.manager.get_status() except CloudifyClientError: status_result = None if not status_result: msg = ("Can't use management server {0}: No response." .format(management_ip)) raise CloudifyCliError(msg) # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() try: response = utils.get_rest_client( management_ip).manager.get_context() provider_context = response['context'] except CloudifyClientError: provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_rest_port(rest_port) logger.info('Using management server {0} with port {1}' .format(management_ip, rest_port)) # delete the previous manager deployment if exists. bs.delete_workdir()
def init(provider, reset_config): if provider is not None: return provider_common.provider_init(provider, reset_config) if os.path.exists(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = 'Current directory is already initialized' error = exceptions.CloudifyCliError(msg) error.possible_solutions = [ "Run 'cfy init -r' to force re-initialization " "(might overwrite existing " "configuration files if exist) " ] raise error else: shutil.rmtree(os.path.join( utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME)) settings = utils.CloudifyWorkingDirectorySettings() utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() configure_loggers() get_logger().info('Initialization completed successfully')
def use(management_ip, provider, rest_port): logger = get_logger() # first check this server is available. client = utils.get_rest_client(manager_ip=management_ip, rest_port=rest_port) try: status_result = client.manager.get_status() except CloudifyClientError: status_result = None if not status_result: msg = ("Can't use management server {0}: No response.".format( management_ip)) raise CloudifyCliError(msg) # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() try: response = utils.get_rest_client(management_ip).manager.get_context() provider_name = response['name'] provider_context = response['context'] except CloudifyClientError: provider_name = None provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_provider(provider_name) wd_settings.set_rest_port(rest_port) wd_settings.set_is_provider_config(provider) logger.info('Using management server {0} with port {1}'.format( management_ip, rest_port))
def provider_init(provider, reset_config): logger = get_logger() provider_deprecation_notice() if os.path.exists( os.path.join(utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = ('Current directory is already initialized. ' 'Use the "-r" flag to force ' 'reinitialization (might overwrite ' 'provider configuration files if exist).') raise exceptions.CloudifyCliError(msg) else: # resetting provider configuration logger.debug('resetting configuration...') _provider_init(provider, reset_config) logger.info("Configuration reset complete") return logger.info("Initializing Cloudify") provider_module_name = _provider_init(provider, reset_config) settings = utils.CloudifyWorkingDirectorySettings() settings.set_provider(provider_module_name) settings.set_is_provider_config(True) utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() logger.info("Initialization complete")
def init(reset_config, skip_logging=False): if os.path.exists( os.path.join(utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME, constants.CLOUDIFY_WD_SETTINGS_FILE_NAME)): if not reset_config: msg = 'Current directory is already initialized' error = exceptions.CloudifyCliError(msg) error.possible_solutions = [ "Run 'cfy init -r' to force re-initialization " "(might overwrite existing " "configuration files if exist) " ] raise error else: shutil.rmtree( os.path.join(utils.get_cwd(), constants.CLOUDIFY_WD_SETTINGS_DIRECTORY_NAME)) settings = utils.CloudifyWorkingDirectorySettings() utils.dump_cloudify_working_dir_settings(settings) utils.dump_configuration_file() configure_loggers() if not skip_logging: get_logger().info('Initialization completed successfully')
def use(management_ip, rest_port): logger = get_logger() # determine SSL mode by port if rest_port == constants.SECURED_REST_PORT: protocol = constants.SECURED_PROTOCOL else: protocol = constants.DEFAULT_PROTOCOL client = utils.get_rest_client(manager_ip=management_ip, rest_port=rest_port, protocol=protocol) try: # first check this server is available. client.manager.get_status() except UserUnauthorizedError: msg = "Can't use management server {0}: User is unauthorized.".format( management_ip) raise CloudifyCliError(msg) except CloudifyClientError: msg = "Can't use management server {0}: No response.".format( management_ip) raise CloudifyCliError(msg) # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() try: response = client.manager.get_context() provider_context = response['context'] except CloudifyClientError: provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_rest_port(rest_port) wd_settings.set_protocol(protocol) logger.info('Using management server {0} with port {1}'.format( management_ip, rest_port)) # delete the previous manager deployment if exists. bs.delete_workdir()
def use(management_ip, rest_port): logger = get_logger() # check if cloudify was initialized. if not utils.is_initialized(): utils.dump_cloudify_working_dir_settings() utils.dump_configuration_file() # determine SSL mode by port if rest_port == constants.SECURED_REST_PORT: protocol = constants.SECURED_PROTOCOL else: protocol = constants.DEFAULT_PROTOCOL client = utils.get_rest_client( rest_host=management_ip, rest_port=rest_port, rest_protocol=protocol, skip_version_check=True) try: # first check this server is available. client.manager.get_status() except UserUnauthorizedError: msg = "Can't use manager {0}: User is unauthorized.".format( management_ip) raise CloudifyCliError(msg) except CloudifyClientError as e: msg = "Can't use manager {0}: {1}".format(management_ip, str(e)) raise CloudifyCliError(msg) try: response = client.manager.get_context() provider_context = response['context'] except CloudifyClientError: provider_context = None with utils.update_wd_settings() as wd_settings: wd_settings.set_management_server(management_ip) wd_settings.set_provider_context(provider_context) wd_settings.set_rest_port(rest_port) wd_settings.set_rest_protocol(protocol) logger.info('Using management server {0} with port {1}' .format(management_ip, rest_port)) # delete the previous manager deployment if exists. bs.delete_workdir()