def set_default_values(self): self._set_name() self.setdefault('network', constants.DEFAULT_NETWORK_NAME) self._set_ips_and_certs() self._set_tenant() # Remove the networks dict as it's no longer needed if 'networks' in self: self.pop('networks') self.setdefault('node_instance_id', ctx.instance.id) self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', defaults.MIN_WORKERS) self.setdefault('max_workers', defaults.MAX_WORKERS) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version()) self.setdefault('log_level', defaults.LOG_LEVEL) self.setdefault('log_max_bytes', defaults.LOG_FILE_SIZE) self.setdefault('log_max_history', defaults.LOG_BACKUPS) # detach agents dont use sudo, so they don't need disable-requiretty self.setdefault( 'disable_requiretty', self.get('process_management', {}).get('name') != 'detach' )
def set_default_values(self): self._set_name() self.setdefault('network', constants.DEFAULT_NETWORK_NAME) self._set_ips() self._set_broker_cert() # Remove the networks dict as it's no longer needed if 'networks' in self: self.pop('networks') self.setdefault('node_instance_id', ctx.instance.id) self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', defaults.MIN_WORKERS) self.setdefault('max_workers', defaults.MAX_WORKERS) self.setdefault('disable_requiretty', True) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version()) self.setdefault('log_level', defaults.LOG_LEVEL) self.setdefault('log_max_bytes', defaults.LOG_FILE_SIZE) self.setdefault('log_max_history', defaults.LOG_BACKUPS)
def _create_agent_env(self): # Try to get broker credentials from the tenant. If they aren't set # get them from the broker_config module tenant = self.cloudify_agent.get('rest_tenant', {}) tenant_name = tenant.get('name', defaults.DEFAULT_TENANT_NAME) broker_user = tenant.get('rabbitmq_username', broker_config.broker_username) broker_pass = tenant.get('rabbitmq_password', broker_config.broker_password) broker_vhost = tenant.get('rabbitmq_vhost', broker_config.broker_vhost) execution_env = { # mandatory values calculated before the agent # is actually created env.CLOUDIFY_DAEMON_QUEUE: self.cloudify_agent['queue'], env.CLOUDIFY_DAEMON_NAME: self.cloudify_agent['name'], env.CLOUDIFY_REST_HOST: self.cloudify_agent['rest_host'], env.CLOUDIFY_BROKER_IP: self.cloudify_agent['broker_ip'], # Optional broker values env.CLOUDIFY_BROKER_USER: broker_user, env.CLOUDIFY_BROKER_PASS: broker_pass, env.CLOUDIFY_BROKER_VHOST: broker_vhost, env.CLOUDIFY_BROKER_SSL_ENABLED: broker_config.broker_ssl_enabled, env.CLOUDIFY_BROKER_SSL_CERT_PATH: self.cloudify_agent['broker_ssl_cert_path'], # these are variables that have default values that will be set # by the agent on the remote host if not set here env.CLOUDIFY_DAEMON_USER: self.cloudify_agent.get('user'), env.CLOUDIFY_REST_PORT: self.cloudify_agent.get('rest_port'), env.CLOUDIFY_REST_TOKEN: self.cloudify_agent.get('rest_token'), env.CLOUDIFY_REST_TENANT: tenant_name, env.CLOUDIFY_DAEMON_MAX_WORKERS: self.cloudify_agent.get( 'max_workers'), env.CLOUDIFY_DAEMON_MIN_WORKERS: self.cloudify_agent.get( 'min_workers'), env.CLOUDIFY_DAEMON_PROCESS_MANAGEMENT: self.cloudify_agent['process_management']['name'], env.CLOUDIFY_DAEMON_WORKDIR: self.cloudify_agent['workdir'], env.CLOUDIFY_DAEMON_EXTRA_ENV: self.create_custom_env_file_on_target( self.cloudify_agent.get('env', {})), env.CLOUDIFY_BYPASS_MAINTENANCE_MODE: get_is_bypass_maintenance(), env.CLOUDIFY_LOCAL_REST_CERT_PATH: self.cloudify_agent['agent_rest_cert_path'], env.CLOUDIFY_CLUSTER_NODES: base64.b64encode(json.dumps( self.cloudify_agent.get('cluster', []))) } execution_env = utils.purge_none_values(execution_env) execution_env = utils.stringify_values(execution_env) self.logger.debug('Cloudify Agent will be created using the following ' 'environment: {0}'.format(execution_env)) return execution_env
def _create_agent_env(self): execution_env = { # mandatory values calculated before the agent # is actually created env.CLOUDIFY_DAEMON_QUEUE: self.cloudify_agent['queue'], env.CLOUDIFY_DAEMON_NAME: self.cloudify_agent['name'], env.CLOUDIFY_REST_HOST: self.cloudify_agent['rest_host'], env.CLOUDIFY_BROKER_IP: self.cloudify_agent['broker_ip'], # these are variables that have default values that will be set # by the agent on the remote host if not set here env.CLOUDIFY_DAEMON_USER: self.cloudify_agent.get('user'), # broker_ip might not be set yet, and retrieved from the manager env.CLOUDIFY_BROKER_PORT: self.cloudify_agent.get('broker_port'), env.CLOUDIFY_REST_PORT: self.cloudify_agent.get('rest_port'), env.CLOUDIFY_REST_TOKEN: self.cloudify_agent.get('rest_token'), env.CLOUDIFY_REST_TENANT: self.cloudify_agent.get('rest_tenant'), env.CLOUDIFY_DAEMON_MAX_WORKERS: self.cloudify_agent.get('max_workers'), env.CLOUDIFY_DAEMON_MIN_WORKERS: self.cloudify_agent.get('min_workers'), env.CLOUDIFY_DAEMON_PROCESS_MANAGEMENT: self.cloudify_agent['process_management']['name'], env.CLOUDIFY_DAEMON_WORKDIR: self.cloudify_agent['workdir'], env.CLOUDIFY_DAEMON_EXTRA_ENV: self.create_custom_env_file_on_target( self.cloudify_agent.get('env', {})), env.CLOUDIFY_BYPASS_MAINTENANCE_MODE: get_is_bypass_maintenance(), env.CLOUDIFY_LOCAL_REST_CERT_PATH: self.cloudify_agent['agent_rest_cert_path'], env.CLOUDIFY_BROKER_SSL_CERT_PATH: self.cloudify_agent['broker_ssl_cert_path'] } execution_env = utils.purge_none_values(execution_env) execution_env = utils.stringify_values(execution_env) self.logger.debug('Cloudify Agent will be created using the following ' 'environment: {0}'.format(execution_env)) return execution_env
def _cfy_agent_attributes_no_defaults(cloudify_agent): if not cloudify_agent.get('process_management'): cloudify_agent['process_management'] = {} if not cloudify_agent['process_management'].get('name'): # user did not specify process management configuration, choose the # default one according to os type. if cloudify_agent['windows']: name = 'nssm' else: name = 'init.d' cloudify_agent['process_management']['name'] = name if not cloudify_agent.get('name'): if cloudify_agent['local']: workflows_worker = cloudify_agent.get('workflows_worker', False) suffix = '_workflows' if workflows_worker else '' name = '{0}{1}'.format(ctx.deployment.id, suffix) else: name = ctx.instance.id cloudify_agent['name'] = name service_name = cloudify_agent.get('service_name') if service_name: # service_name takes precedence over name (which is deprecated) cloudify_agent['name'] = service_name if not cloudify_agent.get('queue'): # by default, queue of the agent is the same as the name cloudify_agent['queue'] = cloudify_agent['name'] if not cloudify_agent.get('rest_host'): cloudify_agent['rest_host'] = \ cloudify_utils.get_manager_rest_service_host() if not cloudify_agent.get('rest_port'): cloudify_agent['rest_port'] = \ cloudify_utils.get_manager_rest_service_port() if not cloudify_agent.get('rest_token'): cloudify_agent['rest_token'] = \ cloudify_utils.get_rest_token() if not cloudify_agent.get('rest_tenant'): cloudify_agent['rest_tenant'] = \ cloudify_utils.get_tenant_name() if not cloudify_agent.get('bypass_maintenance'): cloudify_agent['bypass_maintenance_mode'] = \ cloudify_utils.get_is_bypass_maintenance()
def set_default_values(self): self._set_name() self._set_network() self.setdefault('queue', self['name']) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', 0) self.setdefault('max_workers', 20) self.setdefault('disable_requiretty', True) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python') self.setdefault('heartbeat', None) self.setdefault('version', agent_utils.get_agent_version())
def set_default_values(self): self._set_process_management() self._set_name() self._set_network() self.setdefault('queue', self['name']) self.setdefault('rest_token', cloudify_utils.get_rest_token()) self.setdefault('rest_tenant', cloudify_utils.get_tenant()) self.setdefault('rest_port', cloudify_utils.get_manager_rest_service_port()) self.setdefault('bypass_maintenance', cloudify_utils.get_is_bypass_maintenance()) self.setdefault('min_workers', 0) self.setdefault('max_workers', 5) self.setdefault('disable_requiretty', True) self.setdefault('env', {}) self.setdefault('fabric_env', {}) self.setdefault('system_python', 'python')
def get_rest_client(tenant=None, api_token=None): """ :param tenant: optional tenant name to connect as :param api_token: optional api_token to authenticate with (instead of using REST token) :returns: A REST client configured to connect to the manager in context :rtype: cloudify_rest_client.CloudifyClient """ cluster_settings = get_cluster_settings() if cluster_settings: client_class = CloudifyClusterClient else: client_class = CloudifyClient if not tenant: tenant = utils.get_tenant_name() # Handle maintenance mode headers = {} if utils.get_is_bypass_maintenance(): headers['X-BYPASS-MAINTENANCE'] = 'True' # If api_token or execution_token was provided no need to use REST token token = None execution_token = utils.get_execution_token() if execution_token: headers[constants.CLOUDIFY_EXECUTION_TOKEN_HEADER] = execution_token elif api_token: headers[constants.CLOUDIFY_API_AUTH_TOKEN_HEADER] = api_token else: token = utils.get_rest_token() return client_class(headers=headers, host=utils.get_manager_rest_service_host(), port=utils.get_manager_rest_service_port(), tenant=tenant, token=token, protocol=constants.SECURED_PROTOCOL, cert=utils.get_local_rest_certificate(), kerberos_env=utils.get_kerberos_indication( os.environ.get(constants.KERBEROS_ENV_KEY)))
def _cfy_agent_attributes_no_defaults(cloudify_agent): if not cloudify_agent.get('process_management'): cloudify_agent['process_management'] = {} if not cloudify_agent['process_management'].get('name'): # user did not specify process management configuration, choose the # default one according to os type. if cloudify_agent['windows']: name = 'nssm' else: name = 'init.d' cloudify_agent['process_management']['name'] = name if not cloudify_agent.get('name'): if cloudify_agent['local']: workflows_worker = cloudify_agent.get('workflows_worker', False) suffix = '_workflows' if workflows_worker else '' name = '{0}{1}'.format(ctx.deployment.id, suffix) else: name = ctx.instance.id cloudify_agent['name'] = name if not cloudify_agent.get('queue'): # by default, queue of the agent is the same as the name cloudify_agent['queue'] = cloudify_agent['name'] if not cloudify_agent.get('file_server_host'): cloudify_agent['file_server_host'] = \ cloudify_utils.get_manager_file_server_host() if not cloudify_agent.get('file_server_port'): cloudify_agent['file_server_port'] = \ cloudify_utils.get_manager_file_server_port() if not cloudify_agent.get('file_server_protocol'): cloudify_agent['file_server_protocol'] = \ cloudify_utils.get_manager_file_server_protocol() if not cloudify_agent.get('rest_host'): cloudify_agent['rest_host'] = \ cloudify_utils.get_manager_rest_service_host() if not cloudify_agent.get('security_enabled'): cloudify_agent['security_enabled'] = \ cloudify_utils.is_security_enabled() if not cloudify_agent.get('rest_protocol'): cloudify_agent['rest_protocol'] = \ cloudify_utils.get_manager_rest_service_protocol() if not cloudify_agent.get('rest_port'): cloudify_agent['rest_port'] = \ cloudify_utils.get_manager_rest_service_port() if not cloudify_agent.get('rest_username'): cloudify_agent['rest_username'] = \ cloudify_utils.get_rest_username() if not cloudify_agent.get('rest_password'): cloudify_agent['rest_password'] = \ cloudify_utils.get_rest_password() if not cloudify_agent.get('rest_token'): cloudify_agent['rest_token'] = \ cloudify_utils.get_rest_token() if not cloudify_agent.get('rest_cert_content'): cloudify_agent['rest_cert_content'] = \ cloudify_utils.get_rest_cert_content() if not cloudify_agent.get('verify_rest_certificate'): cloudify_agent['verify_rest_certificate'] = \ cloudify_utils.is_verify_rest_certificate() if not cloudify_agent.get('bypass_maintenance'): cloudify_agent['bypass_maintenance_mode'] = \ cloudify_utils.get_is_bypass_maintenance()
def _create_agent_env(self): execution_env = { # mandatory values calculated before the agent # is actually created env.CLOUDIFY_DAEMON_QUEUE: self.cloudify_agent['queue'], env.CLOUDIFY_DAEMON_NAME: self.cloudify_agent['name'], env.CLOUDIFY_FILE_SERVER_HOST: self.cloudify_agent['file_server_host'], env.CLOUDIFY_REST_HOST: self.cloudify_agent['rest_host'], env.CLOUDIFY_BROKER_IP: self.cloudify_agent['broker_ip'], # these are variables that have default values that will be set # by the agent on the remote host if not set here env.CLOUDIFY_DAEMON_USER: self.cloudify_agent.get('user'), # broker_ip might not be set yet, and retrieved from the manager env.CLOUDIFY_BROKER_PORT: self.cloudify_agent.get('broker_port'), env.CLOUDIFY_REST_PORT: self.cloudify_agent.get('rest_port'), env.CLOUDIFY_REST_PROTOCOL: self.cloudify_agent.get( 'rest_protocol'), env.CLOUDIFY_FILE_SERVER_PORT: self.cloudify_agent.get('file_server_port'), env.CLOUDIFY_FILE_SERVER_PROTOCOL: self.cloudify_agent.get('file_server_protocol'), env.CLOUDIFY_SECURITY_ENABLED: self.cloudify_agent.get('security_enabled'), env.CLOUDIFY_REST_USERNAME: self.cloudify_agent.get('rest_username'), env.CLOUDIFY_REST_PASSWORD: self.cloudify_agent.get('rest_password'), env.CLOUDIFY_REST_TOKEN: self.cloudify_agent.get('rest_token'), env.CLOUDIFY_VERIFY_REST_CERTIFICATE: self.cloudify_agent.get('verify_rest_certificate'), env.CLOUDIFY_REST_CERT_CONTENT: self.cloudify_agent.get('rest_cert_content'), env.CLOUDIFY_DAEMON_MAX_WORKERS: self.cloudify_agent.get( 'max_workers'), env.CLOUDIFY_DAEMON_MIN_WORKERS: self.cloudify_agent.get( 'min_workers'), env.CLOUDIFY_DAEMON_PROCESS_MANAGEMENT: self.cloudify_agent['process_management']['name'], env.CLOUDIFY_DAEMON_WORKDIR: self.cloudify_agent['workdir'], env.CLOUDIFY_DAEMON_EXTRA_ENV: self.create_custom_env_file_on_target( self.cloudify_agent.get('env', {})), env.CLOUDIFY_BYPASS_MAINTENANCE_MODE: get_is_bypass_maintenance(), env.CLOUDIFY_AGENT_REST_CERT_PATH: self.cloudify_agent['agent_rest_cert_path'], env.CLOUDIFY_BROKER_SSL_CERT_PATH: self.cloudify_agent['broker_ssl_cert_path'] } execution_env = utils.purge_none_values(execution_env) execution_env = utils.stringify_values(execution_env) self.logger.debug('Cloudify Agent will be created using the following ' 'environment: {0}'.format(execution_env)) return execution_env
def _create_agent_env(self): tenant = get_tenant() tenant_name = tenant.get('name', defaults.DEFAULT_TENANT_NAME) tenant_user = tenant.get('rabbitmq_username', broker_config.broker_username) tenant_pass = tenant.get('rabbitmq_password', broker_config.broker_password) broker_vhost = tenant.get('rabbitmq_vhost', broker_config.broker_vhost) # Get the agent's broker credentials broker_user = self.cloudify_agent.get('broker_user', tenant_user) broker_pass = self.cloudify_agent.get('broker_pass', tenant_pass) manager_ip = self.cloudify_agent.get_manager_ip() network = self.cloudify_agent.get('network') execution_env = { # mandatory values calculated before the agent # is actually created env.CLOUDIFY_DAEMON_QUEUE: self.cloudify_agent['queue'], env.CLOUDIFY_DAEMON_NAME: self.cloudify_agent['name'], env.CLOUDIFY_REST_HOST: manager_ip, env.CLOUDIFY_BROKER_IP: ','.join( broker.networks[network] for broker in ctx.get_brokers(network=network) ), # Optional broker values env.CLOUDIFY_BROKER_USER: broker_user, env.CLOUDIFY_BROKER_PASS: broker_pass, env.CLOUDIFY_BROKER_VHOST: broker_vhost, env.CLOUDIFY_BROKER_SSL_ENABLED: broker_config.broker_ssl_enabled, env.CLOUDIFY_BROKER_SSL_CERT_PATH: ( self.cloudify_agent['broker_ssl_cert_path'] ), env.CLOUDIFY_HEARTBEAT: ( self.cloudify_agent.get('heartbeat') ), # these are variables that have default values that will be set # by the agent on the remote host if not set here env.CLOUDIFY_DAEMON_USER: self.cloudify_agent.get('user'), env.CLOUDIFY_REST_PORT: self.cloudify_agent.get('rest_port'), env.CLOUDIFY_REST_TOKEN: get_rest_token(), env.CLOUDIFY_REST_TENANT: tenant_name, env.CLOUDIFY_DAEMON_MAX_WORKERS: self.cloudify_agent.get( 'max_workers'), env.CLOUDIFY_DAEMON_MIN_WORKERS: self.cloudify_agent.get( 'min_workers'), env.CLOUDIFY_DAEMON_PROCESS_MANAGEMENT: self.cloudify_agent['process_management']['name'], env.CLOUDIFY_DAEMON_WORKDIR: self.cloudify_agent['workdir'], env.CLOUDIFY_DAEMON_EXTRA_ENV: self.create_custom_env_file_on_target( self.cloudify_agent.get('env', {})), env.CLOUDIFY_BYPASS_MAINTENANCE_MODE: get_is_bypass_maintenance(), env.CLOUDIFY_LOCAL_REST_CERT_PATH: ( self.cloudify_agent['agent_rest_cert_path'] ), env.CLOUDIFY_CLUSTER_NODES: base64.b64encode(json.dumps( self.cloudify_agent.get('cluster', []))), env.CLOUDIFY_NETWORK_NAME: network, ENV_CFY_EXEC_TEMPDIR: self.cloudify_agent.get( 'executable_temp_path'), ENV_AGENT_LOG_LEVEL: self.cloudify_agent.get('log_level'), ENV_AGENT_LOG_MAX_BYTES: self.cloudify_agent.get('log_max_bytes'), ENV_AGENT_LOG_MAX_HISTORY: self.cloudify_agent.get( 'log_max_history') } execution_env = utils.purge_none_values(execution_env) execution_env = utils.stringify_values(execution_env) self.logger.debug('Cloudify Agent will be created using the following ' 'environment: {0}'.format(execution_env)) return execution_env
def _create_agent_env(self): # pop to not leave creds around tenant = self.cloudify_agent.pop('tenant') tenant_name = tenant.get('name', defaults.DEFAULT_TENANT_NAME) tenant_user = tenant.get('rabbitmq_username', broker_config.broker_username) tenant_pass = tenant.get('rabbitmq_password', broker_config.broker_password) broker_vhost = tenant.get('rabbitmq_vhost', broker_config.broker_vhost) # Get the agent's broker credentials broker_user = self.cloudify_agent.get('broker_user', tenant_user) broker_pass = self.cloudify_agent.get('broker_pass', tenant_pass) network = self.cloudify_agent.get('network') execution_env = { # mandatory values calculated before the agent # is actually created env.CLOUDIFY_DAEMON_QUEUE: self.cloudify_agent['queue'], env.AGENT_NAME: self.cloudify_agent['name'], env.CLOUDIFY_REST_HOST: ','.join(self.cloudify_agent['rest_host']), env.CLOUDIFY_BROKER_IP: ','.join(self.cloudify_agent['broker_ip']), # Optional broker values env.CLOUDIFY_BROKER_USER: broker_user, env.CLOUDIFY_BROKER_PASS: broker_pass, env.CLOUDIFY_BROKER_VHOST: broker_vhost, env.CLOUDIFY_BROKER_SSL_ENABLED: broker_config.broker_ssl_enabled, env.CLOUDIFY_BROKER_SSL_CERT_PATH: (self.cloudify_agent['broker_ssl_cert_path']), env.CLOUDIFY_HEARTBEAT: (self.cloudify_agent.get('heartbeat')), # these are variables that have default values that will be set # by the agent on the remote host if not set here env.CLOUDIFY_DAEMON_USER: self.cloudify_agent.get('user'), env.CLOUDIFY_REST_PORT: self.cloudify_agent.get('rest_port'), env.CLOUDIFY_REST_TOKEN: get_rest_token(), env.CLOUDIFY_REST_TENANT: tenant_name, env.CLOUDIFY_DAEMON_MAX_WORKERS: self.cloudify_agent.get('max_workers'), env.CLOUDIFY_DAEMON_MIN_WORKERS: self.cloudify_agent.get('min_workers'), env.CLOUDIFY_DAEMON_PROCESS_MANAGEMENT: self.cloudify_agent['process_management']['name'], env.CLOUDIFY_DAEMON_WORKDIR: self.cloudify_agent['workdir'], env.CLOUDIFY_DAEMON_EXTRA_ENV: self.create_custom_env_file_on_target( self.cloudify_agent.get('env', {})), env.CLOUDIFY_BYPASS_MAINTENANCE_MODE: get_is_bypass_maintenance(), env.CLOUDIFY_LOCAL_REST_CERT_PATH: (self.cloudify_agent['agent_rest_cert_path']), env.CLOUDIFY_NETWORK_NAME: network, ENV_CFY_EXEC_TEMPDIR: self.cloudify_agent.get('executable_temp_path'), ENV_AGENT_LOG_LEVEL: self.cloudify_agent.get('log_level'), ENV_AGENT_LOG_MAX_BYTES: self.cloudify_agent.get('log_max_bytes'), ENV_AGENT_LOG_MAX_HISTORY: self.cloudify_agent.get('log_max_history') } execution_env = utils.purge_none_values(execution_env) execution_env = utils.stringify_values(execution_env) self.logger.debug('Cloudify Agent will be created using the following ' 'environment: {0}'.format(execution_env)) return execution_env