def run_base(self, context): # Read and parse shiyard.conf config = configparser.ConfigParser() config.read(self.shipyard_conf) # Initialize variables self.deckhand_client_read_timeout = int( config.get('requests_config', 'deckhand_client_read_timeout')) self.validation_read_timeout = int( config.get('requests_config', 'validation_read_timeout')) # Logs uuid of Shipyard action LOG.info("Executing Shipyard Action %s", self.action_info['id']) # Retrieve Endpoint Information self.deckhand_svc_endpoint = self.endpoints.endpoint_by_name( service_endpoint.DECKHAND) LOG.info("Deckhand endpoint is %s", self.deckhand_svc_endpoint) # Set up DeckHand Client LOG.info("Setting up DeckHand Client...") # NOTE: The communication between the Airflow workers # and Deckhand happens via the 'internal' endpoint. self.deckhandclient = deckhand_client.Client(session=self.svc_session, endpoint_type='internal') if not self.deckhandclient: raise AirflowException('Failed to set up deckhand client!')
def get_client(self): """Retrieve a deckhand client""" """ Notes: TODO(bryan-strassner): If/when the airflow plugin modules move to using oslo config, consider using the example here: https://github.com/att-comdev/deckhand/blob/cef3b52a104e620e88a24caf70ed2bb1297c268f/deckhand/barbican/client_wrapper.py#L53 which will load the attributes from the config more flexibly. Keystoneauth1 also provides for a simpler solution with: https://docs.openstack.org/keystoneauth/latest/api/keystoneauth1.loading.html if oslo config is used. """ keystone_auth = {} # Construct Session Argument for attr in ('auth_url', 'password', 'project_domain_name', 'project_name', 'username', 'user_domain_name'): keystone_auth[attr] = self.config.get('keystone_authtoken', attr) # Set up keystone session auth = keystone_v3.Password(**keystone_auth) sess = keystone_session.Session(auth=auth) LOG.info("Setting up Deckhand client with parameters") for attr in keystone_auth: if attr != 'password': LOG.debug('%s = %s', attr, keystone_auth[attr]) return deckhand_client.Client(session=sess, endpoint_type='internal')
def deckhand_base(self, context): # Read and parse shiyard.conf config = configparser.ConfigParser() config.read(self.shipyard_conf) # Initialize variables self.deckhand_client_read_timeout = int(config.get( 'requests_config', 'deckhand_client_read_timeout')) self.validation_read_timeout = int(config.get( 'requests_config', 'validation_read_timeout')) # Define task_instance task_instance = context['task_instance'] # Set up and retrieve values from xcom self.xcom_puller = XcomPuller(self.main_dag_name, task_instance) self.action_info = self.xcom_puller.get_action_info() # Logs uuid of Shipyard action logging.info("Executing Shipyard Action %s", self.action_info['id']) # Retrieve Endpoint Information self.deckhand_svc_endpoint = ucp_service_endpoint( self, svc_type=self.deckhand_svc_type) logging.info("Deckhand endpoint is %s", self.deckhand_svc_endpoint) # Set up DeckHand Client logging.info("Setting up DeckHand Client...") # NOTE: The communication between the Airflow workers # and Deckhand happens via the 'internal' endpoint. self.deckhandclient = deckhand_client.Client( session=self.svc_session, endpoint_type='internal') if not self.deckhandclient: raise AirflowException('Failed to set up deckhand client!') # Retrieve 'revision_id' from xcom for tasks other than # 'deckhand_get_design_version' # # NOTE: In the case of 'deploy_site', the dag_id will # be 'deploy_site.deckhand_get_design_version' for the # 'deckhand_get_design_version' task. We need to extract # the xcom value from it in order to get the value of the # last committed revision ID if self.task_id != 'deckhand_get_design_version': # Retrieve 'revision_id' from xcom self.revision_id = self.xcom_puller.get_design_version() if self.revision_id: logging.info("Revision ID is %d", self.revision_id) else: raise AirflowException('Failed to retrieve Revision ID!')
def run_base(self, context): # Read and parse shiyard.conf config = configparser.ConfigParser() config.read(self.shipyard_conf) # Initialize variables self.deckhand_client_read_timeout = int( config.get('requests_config', 'deckhand_client_read_timeout')) self.validation_read_timeout = int( config.get('requests_config', 'validation_read_timeout')) # Logs uuid of Shipyard action LOG.info("Executing Shipyard Action %s", self.action_id) # Create additional headers dict to pass context marker # and end user addl_headers = { CustomHeaders.CONTEXT_MARKER.value: self.context_marker, CustomHeaders.END_USER.value: self.user } # Retrieve Endpoint Information self.deckhand_svc_endpoint = self.endpoints.endpoint_by_name( service_endpoint.DECKHAND, addl_headers=addl_headers) # update additional headers self.svc_session.additional_headers.update(addl_headers) LOG.info("Deckhand endpoint is %s", self.deckhand_svc_endpoint) # Set up DeckHand Client LOG.info("Setting up DeckHand Client...") # NOTE: The communication between the Airflow workers # and Deckhand happens via the 'internal' endpoint. self.deckhandclient = deckhand_client.Client(session=self.svc_session, endpoint_type='internal') if not self.deckhandclient: raise AirflowException('Failed to set up deckhand client!')
def deckhand_client(): """Retrieve a Deckhand client""" return dh_client.Client(session=svc_endpoints.get_session(), endpoint_type='internal')