當前位置: 首頁>>代碼示例>>Python>>正文


Python PythonPackageArchive.get_bytes方法代碼示例

本文整理匯總了Python中c7n.mu.PythonPackageArchive.get_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python PythonPackageArchive.get_bytes方法的具體用法?Python PythonPackageArchive.get_bytes怎麽用?Python PythonPackageArchive.get_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在c7n.mu.PythonPackageArchive的用法示例。


在下文中一共展示了PythonPackageArchive.get_bytes方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_function

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import get_bytes [as 別名]
    def create_function(self, client, name):
        archive = PythonPackageArchive()
        self.addCleanup(archive.remove)
        archive.add_contents('index.py', SAMPLE_FUNC)
        archive.close()

        lfunc = client.create_function(
            FunctionName=name,
            Runtime="python2.7",
            MemorySize=128,
            Handler='index.handler',
            Publish=True,
            Role='arn:aws:iam::644160558196:role/lambda_basic_execution',
            Code={'ZipFile': archive.get_bytes()})
        self.addCleanup(client.delete_function, FunctionName=name)
        return lfunc
開發者ID:kapilt,項目名稱:cloud-custodian,代碼行數:18,代碼來源:test_lambda.py

示例2: FunctionPackage

# 需要導入模塊: from c7n.mu import PythonPackageArchive [as 別名]
# 或者: from c7n.mu.PythonPackageArchive import get_bytes [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()
開發者ID:capitalone,項目名稱:cloud-custodian,代碼行數:104,代碼來源:function_package.py


注:本文中的c7n.mu.PythonPackageArchive.get_bytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。