Updates for pep-8 compliance. Changed many files cosmetically
Added a file exclusion to tox.ini, and also excluded rule for unused named variables. excluded more things that are system or tox related. Change-Id: I022b72cbe048e3fe1f70e6017038248e6a2e9538
This commit is contained in:
@@ -14,26 +14,27 @@
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
from airflow.exceptions import AirflowException
|
||||
from airflow.models import BaseOperator
|
||||
from airflow.plugins_manager import AirflowPlugin
|
||||
from airflow.utils.decorators import apply_defaults
|
||||
|
||||
|
||||
class OpenStackOperator(BaseOperator):
|
||||
"""
|
||||
Performs OpenStack CLI calls
|
||||
:openrc_file: Path of the openrc file
|
||||
:openstack_command: The OpenStack command to be executed
|
||||
"""
|
||||
|
||||
@apply_defaults
|
||||
def __init__(self,
|
||||
openrc_file,
|
||||
openstack_command=None,
|
||||
xcom_push=False,
|
||||
*args, **kwargs):
|
||||
*args,
|
||||
**kwargs):
|
||||
|
||||
super(OpenStackOperator, self).__init__(*args, **kwargs)
|
||||
self.openrc_file = openrc_file
|
||||
@@ -44,13 +45,17 @@ class OpenStackOperator(BaseOperator):
|
||||
logging.info("Running OpenStack Command: %s", self.openstack_command)
|
||||
|
||||
# Emulate "source" in bash. Sets up environment variables.
|
||||
pipe = subprocess.Popen(". %s; env" % self.openrc_file, stdout=subprocess.PIPE, shell=True)
|
||||
pipe = subprocess.Popen(
|
||||
". %s; env" % self.openrc_file, stdout=subprocess.PIPE, shell=True)
|
||||
data = pipe.communicate()[0]
|
||||
os_env = dict((line.split("=", 1) for line in data.splitlines()))
|
||||
|
||||
# Execute the OpenStack CLI Command
|
||||
openstack_cli = subprocess.Popen(self.openstack_command, env=os_env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
|
||||
# Execute the OpenStack CLI Command
|
||||
openstack_cli = subprocess.Popen(
|
||||
self.openstack_command,
|
||||
env=os_env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
# Logs Output
|
||||
logging.info("Output:")
|
||||
@@ -60,18 +65,15 @@ class OpenStackOperator(BaseOperator):
|
||||
line = line.strip()
|
||||
logging.info(line)
|
||||
|
||||
|
||||
# Wait for child process to terminate. Set and return returncode attribute.
|
||||
# Wait for child process to terminate.
|
||||
# Set and return returncode attribute.
|
||||
openstack_cli.wait()
|
||||
logging.info("Command exited with "
|
||||
"return code {0}".format(openstack_cli.returncode))
|
||||
|
||||
|
||||
# Raise Execptions if OpenStack Command Fails
|
||||
if openstack_cli.returncode:
|
||||
raise AirflowException("OpenStack Command Failed")
|
||||
|
||||
|
||||
"""
|
||||
Push response to an XCom if xcom_push is True
|
||||
"""
|
||||
@@ -82,4 +84,3 @@ class OpenStackOperator(BaseOperator):
|
||||
class OpenStackCliPlugin(AirflowPlugin):
|
||||
name = "openstack_cli_plugin"
|
||||
operators = [OpenStackOperator]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user