本文整理汇总了Python中airflow.models.Variable.set方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.set方法的具体用法?Python Variable.set怎么用?Python Variable.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.models.Variable
的用法示例。
在下文中一共展示了Variable.set方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: variables
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def variables(args):
if args.get:
try:
var = Variable.get(args.get,
deserialize_json=args.json,
default_var=args.default)
print(var)
except ValueError as e:
print(e)
if args.delete:
session = settings.Session()
session.query(Variable).filter_by(key=args.delete).delete()
session.commit()
session.close()
if args.set:
Variable.set(args.set[0], args.set[1])
# Work around 'import' as a reserved keyword
imp = getattr(args, 'import')
if imp:
if os.path.exists(imp):
import_helper(imp)
else:
print("Missing variables file.")
if args.export:
export_helper(args.export)
if not (args.set or args.get or imp or args.export or args.delete):
# list all variables
session = settings.Session()
vars = session.query(Variable)
msg = "\n".join(var.key for var in vars)
print(msg)
示例2: test_var_with_encryption_rotate_fernet_key
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def test_var_with_encryption_rotate_fernet_key(self, mock_get):
"""
Tests rotating encrypted variables.
"""
key1 = Fernet.generate_key()
key2 = Fernet.generate_key()
mock_get.return_value = key1.decode()
Variable.set('key', 'value')
session = settings.Session()
test_var = session.query(Variable).filter(Variable.key == 'key').one()
self.assertTrue(test_var.is_encrypted)
self.assertEqual(test_var.val, 'value')
self.assertEqual(Fernet(key1).decrypt(test_var._val.encode()), b'value')
# Test decrypt of old value with new key
mock_get.return_value = ','.join([key2.decode(), key1.decode()])
crypto._fernet = None
self.assertEqual(test_var.val, 'value')
# Test decrypt of new value with new key
test_var.rotate_fernet_key()
self.assertTrue(test_var.is_encrypted)
self.assertEqual(test_var.val, 'value')
self.assertEqual(Fernet(key2).decrypt(test_var._val.encode()), b'value')
示例3: __call__
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def __call__(self):
# read the configuration out of S3
with open(local_cfg_file_location) as data_file:
config = json.load(data_file)
# setup the environment variables
for var in config['variables']:
Variable.set(var['name'],var['value'])
示例4: test_variable_with_encryption
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def test_variable_with_encryption(self, mock_get):
"""
Test variables with encryption
"""
mock_get.return_value = Fernet.generate_key().decode()
Variable.set('key', 'value')
session = settings.Session()
test_var = session.query(Variable).filter(Variable.key == 'key').one()
self.assertTrue(test_var.is_encrypted)
self.assertEqual(test_var.val, 'value')
示例5: test_variable_no_encryption
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def test_variable_no_encryption(self, mock_get):
"""
Test variables without encryption
"""
mock_get.return_value = ''
Variable.set('key', 'value')
session = settings.Session()
test_var = session.query(Variable).filter(Variable.key == 'key').one()
self.assertFalse(test_var.is_encrypted)
self.assertEqual(test_var.val, 'value')
示例6: variables
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def variables(args):
if args.get:
try:
var = Variable.get(args.get, deserialize_json=args.json, default_var=args.default)
print(var)
except ValueError as e:
print(e)
if args.set:
Variable.set(args.set[0], args.set[1])
if not args.set and not args.get:
# list all variables
session = settings.Session()
vars = session.query(Variable)
msg = "\n".join(var.key for var in vars)
print(msg)
示例7: MonthlyGenerateTestArgs
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def MonthlyGenerateTestArgs(**kwargs):
"""Loads the configuration that will be used for this Iteration."""
conf = kwargs['dag_run'].conf
if conf is None:
conf = dict()
# If version is overriden then we should use it otherwise we use it's
# default or monthly value.
version = conf.get('VERSION') or istio_common_dag.GetVariableOrDefault('monthly-version', None)
if not version or version == 'INVALID':
raise ValueError('version needs to be provided')
Variable.set('monthly-version', 'INVALID')
#GCS_MONTHLY_STAGE_PATH is of the form ='prerelease/{version}'
gcs_path = 'prerelease/%s' % (version)
branch = conf.get('BRANCH') or istio_common_dag.GetVariableOrDefault('monthly-branch', None)
if not branch or branch == 'INVALID':
raise ValueError('branch needs to be provided')
Variable.set('monthly-branch', 'INVALID')
mfest_commit = conf.get('MFEST_COMMIT') or branch
default_conf = environment_config.GetDefaultAirflowConfig(
branch=branch,
gcs_path=gcs_path,
mfest_commit=mfest_commit,
pipeline_type='monthly',
verify_consistency='true',
version=version)
config_settings = dict()
for name in default_conf.iterkeys():
config_settings[name] = conf.get(name) or default_conf[name]
# These are the extra params that are passed to the dags for monthly release
monthly_conf = dict()
monthly_conf['DOCKER_HUB' ] = 'istio'
monthly_conf['GCR_RELEASE_DEST' ] = 'istio-io'
monthly_conf['GCS_GITHUB_PATH' ] = 'istio-secrets/github.txt.enc'
monthly_conf['RELEASE_PROJECT_ID' ] = 'istio-io'
# GCS_MONTHLY_RELEASE_PATH is of the form 'istio-release/releases/{version}'
monthly_conf['GCS_MONTHLY_RELEASE_PATH'] = 'istio-release/releases/%s' % (version)
for name in monthly_conf.iterkeys():
config_settings[name] = conf.get(name) or monthly_conf[name]
testMonthlyConfigSettings(config_settings)
return config_settings
示例8: import_helper
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def import_helper(filepath):
with open(filepath, 'r') as varfile:
var = varfile.read()
try:
d = json.loads(var)
except Exception:
print("Invalid variables file.")
else:
try:
n = 0
for k, v in d.items():
if isinstance(v, dict):
Variable.set(k, v, serialize_json=True)
else:
Variable.set(k, v)
n += 1
except Exception:
pass
finally:
print("{} of {} variables successfully updated.".format(n, len(d)))
示例9: ReportMonthlySuccessful
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def ReportMonthlySuccessful(task_instance, **kwargs):
del kwargs
version = istio_common_dag.GetSettingPython(task_instance, 'VERSION')
try:
match = re.match(r'([0-9])\.([0-9])\.([0-9]).*', version)
major, minor, patch = match.group(1), match.group(2), match.group(3)
Variable.set('major_version', major)
Variable.set('released_version_minor', minor)
Variable.set('released_version_patch', patch)
except (IndexError, AttributeError):
logging.error('Could not extract released version infomation. \n'
'Please set airflow version Variables manually.'
'After you are done hit Mark Success.')
示例10: ReportDailySuccessful
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def ReportDailySuccessful(task_instance, **kwargs):
date = kwargs['execution_date']
latest_run = float(Variable.get('latest_daily_timestamp'))
timestamp = time.mktime(date.timetuple())
logging.info('Current run\'s timestamp: %s \n'
'latest_daily\'s timestamp: %s', timestamp, latest_run)
if timestamp >= latest_run:
Variable.set('latest_daily_timestamp', timestamp)
run_sha = task_instance.xcom_pull(task_ids='get_git_commit')
latest_version = GetSettingPython(task_instance, 'VERSION')
logging.info('setting latest green daily to: %s', run_sha)
Variable.set('latest_sha', run_sha)
Variable.set('latest_daily', latest_version)
logging.info('latest_sha test to %s', run_sha)
示例11: test_variable_set_get_round_trip_json
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def test_variable_set_get_round_trip_json(self):
value = {"a": 17, "b": 47}
Variable.set("tested_var_set_id", value, serialize_json=True)
assert value == Variable.get("tested_var_set_id", deserialize_json=True)
示例12: test_variable_set_get_round_trip
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def test_variable_set_get_round_trip(self):
Variable.set("tested_var_set_id", "Monday morning breakfast")
assert "Monday morning breakfast" == Variable.get("tested_var_set_id")
示例13: set_group
# 需要导入模块: from airflow.models import Variable [as 别名]
# 或者: from airflow.models.Variable import set [as 别名]
def set_group(*args, **kwargs):
if datetime.now().hour > 18 or datetime.now().hour < 8:
Variable.set('group', 'night_shift')
else:
Variable.set('group', 'day_shift')