本文整理汇总了Python中perfrunner.helpers.remote.RemoteHelper.detect_centos_release方法的典型用法代码示例。如果您正苦于以下问题:Python RemoteHelper.detect_centos_release方法的具体用法?Python RemoteHelper.detect_centos_release怎么用?Python RemoteHelper.detect_centos_release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类perfrunner.helpers.remote.RemoteHelper
的用法示例。
在下文中一共展示了RemoteHelper.detect_centos_release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from perfrunner.helpers.remote import RemoteHelper [as 别名]
# 或者: from perfrunner.helpers.remote.RemoteHelper import detect_centos_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()