本文整理汇总了Python中c7n.mu.PythonPackageArchive.add_modules方法的典型用法代码示例。如果您正苦于以下问题:Python PythonPackageArchive.add_modules方法的具体用法?Python PythonPackageArchive.add_modules怎么用?Python PythonPackageArchive.add_modules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c7n.mu.PythonPackageArchive
的用法示例。
在下文中一共展示了PythonPackageArchive.add_modules方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_modules [as 别名]
#.........这里部分代码省略.........
@property
def cache_folder(self):
c7n_azure_root = os.path.dirname(__file__)
return os.path.join(c7n_azure_root, 'cache')
def build(self, policy, modules, non_binary_packages, excluded_packages, queue_name=None,):
wheels_folder = os.path.join(self.cache_folder, 'wheels')
wheels_install_folder = os.path.join(self.cache_folder, 'dependencies')
packages = \
DependencyManager.get_dependency_packages_list(modules, excluded_packages)
if not DependencyManager.check_cache(self.cache_folder, wheels_install_folder, packages):
self.log.info("Cached packages not found or requirements were changed.")
# If cache check fails, wipe all previous wheels, installations etc
if os.path.exists(self.cache_folder):
self.log.info("Removing cache folder...")
shutil.rmtree(self.cache_folder)
self.log.info("Preparing non binary wheels...")
DependencyManager.prepare_non_binary_wheels(non_binary_packages, wheels_folder)
self.log.info("Downloading wheels...")
DependencyManager.download_wheels(packages, wheels_folder)
self.log.info("Installing wheels...")
DependencyManager.install_wheels(wheels_folder, wheels_install_folder)
self.log.info("Updating metadata file...")
DependencyManager.create_cache_metadata(self.cache_folder,
wheels_install_folder,
packages)
for root, _, files in os.walk(wheels_install_folder):
arc_prefix = os.path.relpath(root, wheels_install_folder)
for f in files:
dest_path = os.path.join(arc_prefix, f)
if f.endswith('.pyc') or f.endswith('.c'):
continue
f_path = os.path.join(root, f)
self.pkg.add_file(f_path, dest_path)
exclude = os.path.normpath('/cache/') + os.path.sep
self.pkg.add_modules(lambda f: (exclude in f),
*[m.replace('-', '_') for m in modules])
# add config and policy
self._add_functions_required_files(policy, queue_name)
def wait_for_status(self, deployment_creds, retries=10, delay=15):
for r in range(retries):
if self.status(deployment_creds):
return True
else:
self.log.info('(%s/%s) Will retry Function App status check in %s seconds...'
% (r + 1, retries, delay))
time.sleep(delay)
return False
def status(self, deployment_creds):
status_url = '%s/api/deployments' % deployment_creds.scm_uri
try:
r = requests.get(status_url, timeout=30, verify=self.enable_ssl_cert)
except requests.exceptions.ReadTimeout:
self.log.error("Your Function app is not responding to a status request.")
return False
if r.status_code != 200:
self.log.error("Application service returned an error.\n%s\n%s"
% (r.status_code, r.text))
return False
return True
def publish(self, deployment_creds):
self.close()
# update perms of the package
self._update_perms_package()
zip_api_url = '%s/api/zipdeploy?isAsync=true' % deployment_creds.scm_uri
self.log.info("Publishing Function package from %s" % self.pkg.path)
zip_file = self.pkg.get_bytes()
try:
r = requests.post(zip_api_url, data=zip_file, timeout=300, verify=self.enable_ssl_cert)
except requests.exceptions.ReadTimeout:
self.log.error("Your Function App deployment timed out after 5 minutes. Try again.")
r.raise_for_status()
self.log.info("Function publish result: %s" % r.status_code)
def close(self):
self.pkg.close()
示例2: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_modules [as 别名]
#.........这里部分代码省略.........
"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):
"""CFFI native bits aren't discovered automatically
so for now we grab them manually from supported platforms"""
self.pkg.add_modules('cffi')
# Add native libraries that are missing
site_pkg = FunctionPackage._get_site_packages()[0]
# linux
platform = sys.platform
if platform == "linux" or platform == "linux2":
for so_file in os.listdir(site_pkg):
if fnmatch.fnmatch(so_file, '*ffi*.so*'):
self.pkg.add_file(os.path.join(site_pkg, so_file))
self.pkg.add_directory(os.path.join(site_pkg, '.libs_cffi_backend'))
# MacOS
elif platform == "darwin":
raise NotImplementedError('Cannot package Azure Function in MacOS host OS, '
'please use linux.')
# Windows
elif platform == "win32":
raise NotImplementedError('Cannot package Azure Function in Windows host OS, '
'please use linux or WSL.')
def _update_perms_package(self):
os.chmod(self.pkg.path, 0o0644)
def build(self, policy, queue_name=None, entry_point=None, extra_modules=None):
# Get dependencies for azure entry point
entry_point = entry_point or \
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'entry.py')
modules, so_files = FunctionPackage._get_dependencies(entry_point)
# add all loaded modules
示例3: FunctionPackage
# 需要导入模块: from c7n.mu import PythonPackageArchive [as 别名]
# 或者: from c7n.mu.PythonPackageArchive import add_modules [as 别名]
#.........这里部分代码省略.........
}
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
so for now we grab them manually from supported platforms"""
self.pkg.add_modules('cffi')
# Add native libraries that are missing
site_pkg = FunctionPackage._get_site_packages()[0]
# linux
platform = sys.platform
if platform == "linux" or platform == "linux2":
for so_file in os.listdir(site_pkg):
if fnmatch.fnmatch(so_file, '*ffi*.so*'):
self.pkg.add_file(os.path.join(site_pkg, so_file))
self.pkg.add_directory(os.path.join(site_pkg, '.libs_cffi_backend'))
# MacOS
elif platform == "darwin":
raise NotImplementedError('Cannot package Azure Function in MacOS host OS, '
'please use linux.')
# Windows
elif platform == "win32":
raise NotImplementedError('Cannot package Azure Function in Windows host OS, '
'please use linux or WSL.')
def _update_perms_package(self):
os.chmod(self.pkg.path, 0o0644)
def build(self, policy, entry_point=None, extra_modules=None):
# Get dependencies for azure entry point
entry_point = entry_point or \
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'entry.py')
modules, so_files = FunctionPackage._get_dependencies(entry_point)
# add all loaded modules