def check_platforms(cls, platforms): if not platforms: return cur_platform = pf.get_platform() cur_version = semver.Version(cur_platform.version) cur_kernel = semver.Version(cur_platform.kernel) for platform_name, cpus in platforms.iteritems(): if isinstance(cpus, (str, int)): cpus = [int(cpus)] if cpus.strip() else None cpus = cpus or [32, 64] # Check cpu if cur_platform.cpu not in cpus: continue # Check system system, version = pf.split_platform(platform_name) if system in (cur_platform.system, cur_platform.dist): if not version: return elif (system == 'Windows' and semver.Spec(version).match( cur_kernel)) or \ semver.Spec(version).match(cur_version): return raise NotMatchError( "Current {!r} doesn't match platform require: {!r}".format( cur_platform, platforms))
def get_first_report(): platform = pf.get_platform() ips = [{ 'ip': info.ipv4, 'netmask': info.netmask } for info in sysutil.network_info()] physical_memory = round(sysutil.physical_memory() / (1024 * 1024 * 1024.0), 2) disk = round( sum(part.total for part in sysutil.disk_info()) / (1024 * 1024 * 1024.0), 2) first_report = { 'id': config['id'], 'network_domain': config['network_domain'], 'version': config['version'], 'system': platform.system, 'dist': platform.dist, 'dist_version': platform.version, 'arch': platform.cpu, 'kernel': platform.kernel, 'ips': ips, 'ip': config.get('ip') or sysutil.main_ip(), 'home': settings.ROOT_DIR, 'is_virtual': sysutil.is_virtual_machine(), 'node_type': sysutil.node_type(), 'physical_cpu_count': sysutil.physical_cpu_count(), 'physical_memory': physical_memory, 'disk': disk } logger.debug(first_report) return first_report
def get_first_report(): platform = pf.get_platform() config = get_agent_config() num = 0 while not config.get('id') and num < 10: time.sleep(1) config = get_agent_config() num += 1 if not config.get('id'): print(json.dumps({})) return first_report = { 'id': config.get('id'), 'system': platform.system, 'dist': platform.dist, 'dist_version': platform.version, 'arch': platform.cpu, 'kernel': platform.kernel, 'network_domain': config.get('network_domain'), 'ip': config.get('ip') or sysutil.main_ip() } print(json.dumps(first_report)) return first_report
def deal_cmd(cmd): if isinstance(cmd, dict): platform = pf.get_platform() if platform.dist in cmd: cmd = cmd.get(platform.dist) elif platform.system in cmd: cmd = cmd.get(platform.system) else: return None return cmd
import json import netifaces import os import platform import psutil from pf import get_platform from sysutil import cpu_info from sysutil import disk_info from sysutil import get_with_bytes_unit from sysutil import network_info from util import get_machine_type, get_hostname pf_platform = get_platform() def gohai_consts(): consts = { 'build_date': 'Thu Apr 21 18:04:10 UTC 2016', 'git_hash': '0234f68', 'git_branch': '5.7.x-agent', 'go_version': 'go version go1.3.3 linux/amd64' } return consts def get_network_info(): network = [] for net in network_info():
# coding: utf-8 import os import pf import nfs import json import traceback from tornado import web, gen from ci import logger from ci.notification.dingding import Dingding from ci.utils import (excutor_cmd, get_branch_by_ref, get_version, scp_upload_file, cd, get_config, execute) from ci.constants import (AGENT_BUILD_TEMPLATE_CMD, INSTALL_DIR, REPO_DIR, PROGRESS_TEMPLATE_SIGN, WINDOWS, SUSE) platform = pf.get_platform() ant_build_url = get_config()['projects']['ant-build'] class DeployHandler(web.RequestHandler): @gen.coroutine def get(self): self.write('deploy webhook for ci server') @gen.coroutine def post(self): payload = json.loads(self.request.body) if payload['object_kind'] == 'push': project_name = payload['repository']['name'], project_url = payload['repository']['url'], project_branch = get_branch_by_ref(payload['ref'])
import os from os.path import dirname, join from pf import get_platform IS_WINDOWS = os.name == 'nt' PLATFORM = get_platform() SYSTEM = PLATFORM.system.lower() DIST = PLATFORM.dist.lower() ROOT_DIR = dirname(dirname(__file__)) PROJECT_ROOT = join(ROOT_DIR, 'projects') DIST_ROOT = join(ROOT_DIR, 'dist') BIN_ROOT = join(ROOT_DIR, 'bin') SAVE_DIR = '/home/repo/develop/ant' EXCLUDE_DIRS = ('tests', 'test', 'requirements') EXCLUDE_FILES = ('setup.py', 'README.md', 'CHANGELOG.md', 'MANIFEST.in', 'tox.ini') MODULE_PROJECT = ['node', 'python', 'nginx', 'dispatcher', 'manager', 'manager-web'] AGENT_PROJECT = ['agent', 'openresty'] PLUGIN_PROJECT = ['discovery', 'monitor', 'automation'] AGENT_NAME = 'agent' DISPATCHER_NAME = 'dispatcher' MANAGER_NAME = 'manager' MANAGERWEB_NAME = 'manager-web' PKG_NAME = 'platform-ant' GLOBAL_VERSION = 'V2.0'
def get_os_version(): from pf import get_platform return get_platform().dist