shipyard/shipyard_airflow/dags/samples/openstack_api_call.py
Anthony Lin b66d39e468 Update OpenStack Operator
The existing OpenStack operator will only work for
Python 2.7 Airflow Containers and will fail to function
properly for Airflow Containers running on Python 3.x

This update will fix the problems with the environment
variables.

The current assumption is that the shipyard.conf will
contain the required information for the OpenStack
environment and it will be consumed by Airflow Dag to
execute the OpenStack commands.  This will likely change
in future when DeckHand is ready for integration as the
required information will be retrieved from DeckHand instead

The xcom portion has been removed as it does not really
serve any purpose at the moment.  It might get added back
in future depending on the needs.

Change-Id: I0c5fb56462fdbc43a20897373118f510cbb2e01c
2017-08-18 04:09:39 +00:00

66 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
### Openstack CLI Sample Dag
"""
import airflow
from airflow import DAG
from airflow.operators import OpenStackOperator
from datetime import timedelta
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': airflow.utils.dates.days_ago(1),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=1),
}
dag = DAG('openstack_cli', default_args=default_args, schedule_interval=None)
# Location of shiyard.conf
config_path = '/usr/local/airflow/plugins/shipyard.conf'
# Note that the shipyard.conf file needs to be placed on a volume
# that can be accessed by the containers
# openstack endpoint list
t1 = OpenStackOperator(
task_id='endpoint_list_task',
shipyard_conf=config_path,
openstack_command=['openstack', 'endpoint', 'list'],
dag=dag)
# openstack service list
t2 = OpenStackOperator(
task_id='service_list_task',
shipyard_conf=config_path,
openstack_command=['openstack', 'service', 'list'],
dag=dag)
# openstack server list
t3 = OpenStackOperator(
task_id='server_list_task',
shipyard_conf=config_path,
openstack_command=['openstack', 'server', 'list'],
dag=dag)
t2.set_upstream(t1)
t3.set_upstream(t2)