当前位置: 首页>>代码示例>>Python>>正文


Python RemoteHelper.detect_ubuntu_release方法代码示例

本文整理汇总了Python中perfrunner.helpers.remote.RemoteHelper.detect_ubuntu_release方法的典型用法代码示例。如果您正苦于以下问题:Python RemoteHelper.detect_ubuntu_release方法的具体用法?Python RemoteHelper.detect_ubuntu_release怎么用?Python RemoteHelper.detect_ubuntu_release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在perfrunner.helpers.remote.RemoteHelper的用法示例。


在下文中一共展示了RemoteHelper.detect_ubuntu_release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from perfrunner.helpers.remote import RemoteHelper [as 别名]
# 或者: from perfrunner.helpers.remote.RemoteHelper import detect_ubuntu_release [as 别名]
class CouchbaseInstaller:

    def __init__(self, cluster_spec, options):
        self.remote = RemoteHelper(cluster_spec, options.verbose)
        self.options = options

    @property
    def url(self) -> str:
        if validators.url(self.options.version):
            return self.options.version
        else:
            return self.find_package(edition=self.options.edition)

    @property
    def release(self) -> str:
        return self.options.version.split('-')[0]

    @property
    def build(self) -> str:
        split = self.options.version.split('-')
        if len(split) > 1:
            return split[1]

    def find_package(self, edition: str) -> [str, str]:
        for url in self.url_iterator(edition):
            if self.is_exist(url):
                return url
        logger.interrupt('Target build not found')

    def url_iterator(self, edition: str) -> Iterator[str]:
        os_release = None
        if self.remote.package == 'rpm':
            os_release = self.remote.detect_centos_release()
        elif self.remote.package == 'deb':
            os_release = self.remote.detect_ubuntu_release()

        for pkg_pattern in PKG_PATTERNS[self.remote.package]:
            for loc_pattern in LOCATIONS:
                url = loc_pattern + pkg_pattern
                yield url.format(release=self.release, build=self.build,
                                 edition=edition, os=os_release)

    @staticmethod
    def is_exist(url):
        try:
            status_code = requests.head(url).status_code
        except ConnectionError:
            return False
        if status_code == 200:
            return True
        return False

    def download(self):
        """Download and save a copy of the specified package."""
        if self.remote.package == 'rpm':
            logger.info('Saving a local copy of {}'.format(self.url))
            with open('couchbase.rpm', 'wb') as fh:
                resp = requests.get(self.url)
                fh.write(resp.content)
        else:
            logger.interrupt('Unsupported package format')

    def kill_processes(self):
        self.remote.kill_processes()

    def uninstall_package(self):
        self.remote.uninstall_couchbase()

    def clean_data(self):
        self.remote.clean_data()

    def install_package(self):
        logger.info('Using this URL: {}'.format(self.url))
        self.remote.upload_iss_files(self.release)
        self.remote.install_couchbase(self.url)

    def install(self):
        self.kill_processes()
        self.uninstall_package()
        self.clean_data()
        self.install_package()
开发者ID:couchbase,项目名称:perfrunner,代码行数:83,代码来源:install.py


注:本文中的perfrunner.helpers.remote.RemoteHelper.detect_ubuntu_release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。