def _get_slave(self, host, port, db): master = redis.Redis(host=host, port=port, db=db) master_info = master.info() slave_info = [ master_info.get(x) for x in master_info.keys() if x.startswith('slave') ] slaves = [] for n in slave_info: if isinstance(n, dict): slaves.append(n) elif isinstance(n, str): n_slave_str_line = n.split(',') slaves.append({ "ip": n_slave_str_line[0], "port": n_slave_str_line[1], "state": n_slave_str_line[2] }) else: logger.error("{0} not support this type {1}".format( n, type(n))) # slaves=[master_info.get(x).split(',') for x in master_info.keys() if x.startswith('slave')] slave_group = [] for m in [x for x in slaves if x.get('state') == 'online']: # for m in slaves: m_redis_instance = self._get_instance(host=m.get('ip'), port=m.get('port')) slave_group.append(m_redis_instance) return slave_group
def get_context_data(self, **kwargs): context = super(Check_upstreamTemplate, self).get_context_data(**kwargs) upstream_id = self.kwargs.get('upstream_id', None) upstream = Upstream.objects.get(id=upstream_id) all_status = True if upstream.domain_proxy: content = 'No need to check' else: result = getComStr("rsync -av {0} {1}".format( upstream_tmp_file.format(upstream.name), upstream_release_file.format(upstream.name))) if result.get('retcode') != 0: all_status = False logger.error(result) result = getComStr( "/opt/app/nginx/sbin/nginx -t -c /opt/app/nginx/conf/nginx.conf" ) if result.get('retcode') != 0: all_status = False logger.error(result) if all_status: content = "Check pass" else: content = "Check failed ! please check cmd.log" context['username'] = self.request.user.last_name context['active'] = 'nginx' context['content'] = content context['upstream'] = upstream return context
def run(self): if self.app_result['count'] == 1: res = self.app_result['results'][0] try: port = int(res.get("port", 80)) except Exception, e: logger.error(str(e)) port = 80 warmup_urls = res['warmup_urls'] if not warmup_urls: all_status = True warm_url = '' else: warm_url = '' all_status = True for m in warmup_urls: logger.debug(m) t_result = self.check( self.host, port, 'http://%s:%s%s' % (self.item, port, m["warmup_url"]), m["expected_codes"], m["expected_text"]) # if t_result: # pass # else: if not t_result: warm_url = m all_status = False break if all_status: return get_result(0, 'done') else: raise ReleaseError('warm this url %s failed' % warm_url)
def rerun(self, countdown=None): try: result = RollPublishTask().apply_async(args=(self.exec_id, ), countdown=countdown) logger.info("publish RollPublishTask<{0}>: {1}".format( result.task_id, self.mission)) except Exception, e: logger.error("publish RollPublishTask {0} fail: {1}".format( self.mission, e))
def run(self, redis_task_id): task = Redis_task.objects.get(id=redis_task_id) if task.status.name == 'in_queue': task.status = Status.objects.get(name='processing') task.save() resource = [{ "hostname": task.redis_ip.name, "username": "******", "ssh_key": "/root/.ssh/id_rsa" }] if task.master_ip: playbook_path = '/home/admin/scripts/redis_shihui/slave.yml' parametres = { "host": [task.redis_ip.name], "master_ip": task.master_ip.name, "master_port": task.master_port, "ip": task.redis_ip.name, "port": task.redis_port, "maxmemory": task.size } else: playbook_path = '/home/admin/scripts/redis_shihui/master.yml' parametres = { "host": [task.redis_ip.name], "ip": task.redis_ip.name, "port": task.redis_port, "maxmemory": task.size } rbt = ANSRunner(resource) rbt.run_playbook(playbook_path=playbook_path, extra_vars=parametres) result_data = rbt.get_playbook_result() logger.info({ "resource": resource, "result": result_data, "exec_id": redis_task_id }) publish_status = True if result_data.get('failed'): publish_status = False if result_data.get('skipped'): publish_status = False if result_data.get('unreachable'): publish_status = False if publish_status: task.status = Status.objects.get(name='done') task.result = 'done' task.save() self._get_instance(task.redis_ip.name, task.redis_port) else: logger.error(result_data) task.status = Status.objects.get(name='failed') task.result = result_data task.save() else: logger.error("{0} wrong status".format(redis_task_id))
def __init__(self, cfg_type): cf_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), API_CONFIG_PATH) self.cf = ConfigParser.ConfigParser() self.cf.read(cf_file) if cfg_type in self.type_list: self.init(self.cf.get(cfg_type, "path"), self.cf.get(cfg_type, "host"), self.cf.get(cfg_type, "user"), self.cf.get(cfg_type, "passwd")) else: self.error_info('no this type %s' % cfg_type) logger.error(self.error_info)
def run(self): logger.debug('%s' % self.cmd_name) self.set_ftp_info(ftp_flag=self.ftp_flag) self.set_send_data(arg_format=self.arg_format) self.set_rs_method() logger.info('send_data:%s' % self.send_data) try: result = CmdControlApi().post(self.send_data) except Exception, e: logger.error('run error: %s' % str(e)) result = e.message
def get_context_data(self, **kwargs): context = super(Check_confTemplate, self).get_context_data(**kwargs) site_id = self.kwargs.get('site_id', None) all_status = True site = Site.objects.get(id=site_id) result = getComStr("rsync -av {0} {1}".format( vhost_tmp_file.format(site.name), vhost_release_file.format(site.name))) if result.get('retcode') != 0: all_status = False logger.error(result) detail = [ x.upstream for x in Site_context.objects.filter(site=site) if x.upstream.app ] upstreams = [x for x in detail if x.status.name == 'undo'] for m in upstreams: result = getComStr("rsync -av {0} {1}".format( upstream_tmp_file.format(m.name), upstream_release_file.format(m.name))) if result.get('retcode') != 0: all_status = False logger.error(result) result = getComStr( "/opt/app/nginx/sbin/nginx -t -c /opt/app/nginx/conf/nginx.conf") if result.get('retcode') != 0: all_status = False logger.error(result) context['username'] = self.request.user.last_name context['active'] = 'nginx' context['site'] = site.name context['site_id'] = site_id context['group'] = site.group context['all_status'] = all_status if all_status: context['content'] = 'Check pass' else: context['content'] = 'Check failed ! please check cmd.log' return context
def run(self, exec_id, call_id=None): self.init(exec_id=exec_id) if self.mission.project.type == 'php-lumen': playbook_path = '/home/admin/scripts/php-lumen-update.yml' else: playbook_path = '/home/admin/scripts/php_update.yml' resource = [{ "hostname": x.name, "username": "******", "password": "******" } for x in self.mission.project.host_list.all()] rbt = ANSRunner(resource) rbt.run_playbook( playbook_path=playbook_path, extra_vars={ "host": [x.name for x in self.mission.project.host_list.all()], "item_name": self.project.name, "version": self.version, "file_name": self.file_name, "file_md5": self.file_md5, "download_url": self.download_url, }) result_data = rbt.get_playbook_result() logger.info({ "resource": resource, "result": result_data, "exec_id": exec_id }) publish_status = True if result_data.get('failed'): publish_status = False if result_data.get('skipped'): publish_status = False if result_data.get('unreachable'): publish_status = False if publish_status: self.mission.status = Status.objects.get(name='done') self.mission.result = 'done' self.mission.save() Version_history.objects.filter( project=self.mission.project, status=Status.objects.get(name='current')).update( status=Status.objects.get(name='release')) change_version = Version_history.objects.get( project=self.mission.project, version=self.mission.version) change_version.status = Status.objects.get(name='current') change_version.save() else: logger.error(result_data) self.mission.status = Status.objects.get(name='failed') self.mission.result = result_data self.mission.save() # return {"resource":resource,"result":result_data,"exec_id":exec_id} # {'status': {'10.120.180.3': {'unreachable': 0, 'skipped': 0, 'changed': 1, 'ok': 4, 'failed': 0}, '10.120.180.2': {'unreachable': 0, 'skipped': 0, 'changed': 1, 'ok': 4, 'failed': 0}}, # 'failed': {}, # 'skipped': {}, # 'ok': {'10.120.180.3': {'_ansible_no_log': False, 'stdout': u'ln: failed to create symbolic link \u2018/home/admin/app-run/dc.17shihui.com\u2019: Permission denied\r\ndone\r\n', 'changed': True, 'stderr': u'Shared connection to 10.120.180.3 closed.\r\n', 'rc': 0, 'stdout_lines': [u'ln: failed to create symbolic link \u2018/home/admin/app-run/dc.17shihui.com\u2019: Permission denied', u'done']}, '10.120.180.2': {'_ansible_no_log': False, 'stdout': u'done\r\n', 'changed': True, 'stderr': u'Shared connection to 10.120.180.2 closed.\r\n', 'rc': 0, 'stdout_lines': [u'done']}}, # 'unreachable': {}}