本文整理汇总了Python中c7n.mu.PythonPackageArchive.add_file方法的典型用法代码示例。如果您正苦于以下问题:Python PythonPackageArchive.add_file方法的具体用法?Python PythonPackageArchive.add_file怎么用?Python PythonPackageArchive.add_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c7n.mu.PythonPackageArchive
的用法示例。
在下文中一共展示了PythonPackageArchive.add_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_file [as 别名]
class FunctionPackage(object):
def __init__(self, name, function_path=None, target_subscription_ids=None):
self.log = logging.getLogger('custodian.azure.function_package')
self.pkg = PythonPackageArchive()
self.name = name
self.function_path = function_path or os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'function.py')
self.enable_ssl_cert = not distutils.util.strtobool(
os.environ.get(ENV_CUSTODIAN_DISABLE_SSL_CERT_VERIFICATION, 'no'))
if target_subscription_ids is not None:
self.target_subscription_ids = target_subscription_ids
else:
self.target_subscription_ids = [None]
if not self.enable_ssl_cert:
self.log.warning('SSL Certificate Validation is disabled')
def _add_functions_required_files(self, policy, queue_name=None):
s = local_session(Session)
for target_subscription_id in self.target_subscription_ids:
name = self.name + ("_" + target_subscription_id if target_subscription_id else "")
# generate and add auth
self.pkg.add_contents(dest=name + '/auth.json',
contents=s.get_functions_auth_string(target_subscription_id))
self.pkg.add_file(self.function_path,
dest=name + '/function.py')
self.pkg.add_contents(dest=name + '/__init__.py', contents='')
if policy:
config_contents = self.get_function_config(policy, queue_name)
policy_contents = self._get_policy(policy)
self.pkg.add_contents(dest=name + '/function.json',
contents=config_contents)
self.pkg.add_contents(dest=name + '/config.json',
contents=policy_contents)
if policy['mode']['type'] == FUNCTION_EVENT_TRIGGER_MODE:
self._add_queue_binding_extensions()
self._add_host_config()
def _add_host_config(self):
config = \
{
"version": "2.0",
"healthMonitor": {
"enabled": True,
"healthCheckInterval": "00:00:10",
"healthCheckWindow": "00:02:00",
"healthCheckThreshold": 6,
"counterThreshold": 0.80
},
"functionTimeout": "00:05:00",
"logging": {
"fileLoggingMode": "debugOnly"
},
"extensions": {
"http": {
"routePrefix": "api",
"maxConcurrentRequests": 5,
"maxOutstandingRequests": 30
}
}
}
self.pkg.add_contents(dest='host.json', contents=json.dumps(config))
def _add_queue_binding_extensions(self):
bindings_dir_path = os.path.abspath(
os.path.join(os.path.join(__file__, os.pardir), 'function_binding_resources'))
bin_path = os.path.join(bindings_dir_path, 'bin')
self.pkg.add_directory(bin_path)
self.pkg.add_file(os.path.join(bindings_dir_path, 'extensions.csproj'))
def get_function_config(self, policy, queue_name=None):
config = \
{
"scriptFile": "function.py",
"bindings": [{
"direction": "in"
}]
}
mode_type = policy['mode']['type']
binding = config['bindings'][0]
if mode_type == FUNCTION_TIME_TRIGGER_MODE:
binding['type'] = 'timerTrigger'
binding['name'] = 'input'
binding['schedule'] = policy['mode']['schedule']
elif mode_type == FUNCTION_EVENT_TRIGGER_MODE:
binding['type'] = 'queueTrigger'
binding['connection'] = 'AzureWebJobsStorage'
#.........这里部分代码省略.........
示例2: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_file [as 别名]
class FunctionPackage(object):
def __init__(self, name, function_path=None):
self.log = logging.getLogger('custodian.azure.function_package')
self.pkg = PythonPackageArchive()
self.name = name
self.function_path = function_path or os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'function.py')
self.enable_ssl_cert = not distutils.util.strtobool(
os.environ.get(ENV_CUSTODIAN_DISABLE_SSL_CERT_VERIFICATION, 'no'))
if not self.enable_ssl_cert:
self.log.warning('SSL Certificate Validation is disabled')
def _add_functions_required_files(self, policy, queue_name=None):
self.pkg.add_file(self.function_path,
dest=self.name + '/function.py')
self.pkg.add_contents(dest=self.name + '/__init__.py', contents='')
self._add_host_config()
if policy:
config_contents = self.get_function_config(policy, queue_name)
policy_contents = self._get_policy(policy)
self.pkg.add_contents(dest=self.name + '/function.json',
contents=config_contents)
self.pkg.add_contents(dest=self.name + '/config.json',
contents=policy_contents)
if policy['mode']['type'] == FUNCTION_EVENT_TRIGGER_MODE:
self._add_queue_binding_extensions()
def _add_host_config(self):
config = \
{
"version": "2.0",
"healthMonitor": {
"enabled": True,
"healthCheckInterval": "00:00:10",
"healthCheckWindow": "00:02:00",
"healthCheckThreshold": 6,
"counterThreshold": 0.80
},
"functionTimeout": "00:05:00",
"logging": {
"fileLoggingMode": "debugOnly"
},
"extensions": {
"http": {
"routePrefix": "api",
"maxConcurrentRequests": 5,
"maxOutstandingRequests": 30
}
}
}
self.pkg.add_contents(dest='host.json', contents=json.dumps(config))
def _add_queue_binding_extensions(self):
bindings_dir_path = os.path.abspath(
os.path.join(os.path.join(__file__, os.pardir), 'function_binding_resources'))
bin_path = os.path.join(bindings_dir_path, 'bin')
self.pkg.add_directory(bin_path)
self.pkg.add_file(os.path.join(bindings_dir_path, 'extensions.csproj'))
def get_function_config(self, policy, queue_name=None):
config = \
{
"scriptFile": "function.py",
"bindings": [{
"direction": "in"
}]
}
mode_type = policy['mode']['type']
binding = config['bindings'][0]
if mode_type == FUNCTION_TIME_TRIGGER_MODE:
binding['type'] = 'timerTrigger'
binding['name'] = 'input'
binding['schedule'] = policy['mode']['schedule']
elif mode_type == FUNCTION_EVENT_TRIGGER_MODE:
binding['type'] = 'queueTrigger'
binding['connection'] = 'AzureWebJobsStorage'
binding['name'] = 'input'
binding['queueName'] = queue_name
else:
self.log.error("Mode not yet supported for Azure functions (%s)"
% mode_type)
return json.dumps(config, indent=2)
def _get_policy(self, policy):
return json.dumps({'policies': [policy]}, indent=2)
def _add_cffi_module(self):
#.........这里部分代码省略.........
示例3: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_file [as 别名]
class FunctionPackage(object):
def __init__(self, name, function_path=None):
self.log = logging.getLogger('custodian.azure.function_package')
self.pkg = PythonPackageArchive()
self.name = name
self.function_path = function_path or os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'function.py')
def _add_functions_required_files(self, policy):
self.pkg.add_file(self.function_path,
dest=self.name + '/function.py')
self.pkg.add_contents(dest=self.name + '/__init__.py', contents='')
self._add_host_config()
if policy:
config_contents = self.get_function_config(policy)
policy_contents = self._get_policy(policy)
self.pkg.add_contents(dest=self.name + '/function.json',
contents=config_contents)
self.pkg.add_contents(dest=self.name + '/config.json',
contents=policy_contents)
def _add_host_config(self):
config = \
{
"http": {
"routePrefix": "api",
"maxConcurrentRequests": 5,
"maxOutstandingRequests": 30
},
"logger": {
"defaultLevel": "Trace",
"categoryLevels": {
"Worker": "Trace"
}
},
"queues": {
"visibilityTimeout": "00:00:10"
},
"swagger": {
"enabled": True
},
"eventHub": {
"maxBatchSize": 1000,
"prefetchCount": 1000,
"batchCheckpointFrequency": 1
},
"healthMonitor": {
"enabled": True,
"healthCheckInterval": "00:00:10",
"healthCheckWindow": "00:02:00",
"healthCheckThreshold": 6,
"counterThreshold": 0.80
},
"functionTimeout": "00:05:00"
}
self.pkg.add_contents(dest='host.json', contents=json.dumps(config))
def get_function_config(self, policy):
config = \
{
"scriptFile": "function.py",
"bindings": [{
"direction": "in"
}]
}
mode_type = policy['mode']['type']
binding = config['bindings'][0]
if mode_type == 'azure-periodic':
binding['type'] = 'timerTrigger'
binding['name'] = 'input'
binding['schedule'] = policy['mode']['schedule']
elif mode_type == 'azure-stream':
binding['type'] = 'httpTrigger'
binding['authLevel'] = 'anonymous'
binding['name'] = 'input'
binding['methods'] = ['post']
config['bindings'].append({
"name": "$return",
"type": "http",
"direction": "out"})
else:
self.log.error("Mode not yet supported for Azure functions (%s)"
% mode_type)
return json.dumps(config, indent=2)
def _get_policy(self, policy):
return json.dumps({'policies': [policy]}, indent=2)
def _add_cffi_module(self):
"""CFFI native bits aren't discovered automatically
#.........这里部分代码省略.........