def save_regions(): for region_name, order, abbr, chinese_name in regions: region_info = RegionInfo(region=region_name, deploy_order=order, abbr=abbr, chinese_name=chinese_name) region_info.save()
def upload_file(request): """ if request is post: upload files to server and deal with these(unzip or save to database) else: show upload page Args: request (django.http.request.HttpRequest) """ if request.method == "POST": region = request.POST['region'] upload_files = request.FILES.getlist('file') upload_dir = '/tmp' for uploadFile in upload_files: upload_file_name = uploadFile.name # when upload zip, unzip and copy to dirname(${BASE_DIR}) if upload_file_name.endswith('.zip'): filepath = os.path.join(os.path.dirname(BASE_DIR), upload_file_name) with open(filepath, 'wb+') as f: for chunk in uploadFile.chunks(): f.write(chunk) else: return HttpResponse('error', status=500) return HttpResponse('success') current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) uploader_page = SitePage.objects.get(name='uploader') return render(request, 'uploader/upload_bak.html', locals())
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) service_order = BasicServiceStarter.get_service_order(current_region) service_list = [] for services in service_order.values(): service_list += services basic_service_instances = ec2api.find_basic_instances( current_region, service_list) basic_service_infos = {} for order in service_order: basic_service_infos[order] = {} for instance in basic_service_instances: instance_state = instance.state['Name'] instance_name = ec2api.get_instance_tag_name(instance) logger.debug('instance name: %s' % instance_name) service_name = ec2api.get_module_info(instance_name)[0] ip = instance.private_ip_address service_state = True service_order = BasicServiceDeployInfo.objects.get( service_name=service_name).order service_info = basic_service_infos[service_order].get(service_name) if service_info: service_info['total_count'] += 1 if instance_state == 'running': service_info['running_count'] += 1 else: service_info['service_state'] = False service_info.get('details').append( (instance_name, ip, instance_state)) else: if instance_state == 'running': running_count = 1 else: running_count = 0 service_state = False basic_service_infos[service_order].update({ service_name: { 'total_count': 1, 'running_count': running_count, 'service_state': service_state, 'details': [(instance_name, ip, instance_state)] } }) logger.debug('basic service info after one instance: %s ' % json.dumps(basic_service_infos)) logger.debug('basic service infos: %s' % json.dumps(basic_service_infos)) basic_service_page = SitePage.objects.get(name='basic') return render( request, 'basic/basic-service-details.html', { 'basic_service_infos': basic_service_infos, 'current_region': current_region, 'regions': regions, 'basic_service_page': basic_service_page })
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) launcher_page = SitePage.objects.get(name='launcher') return render(request, 'launcher/ec2-launcher.html', { 'current_region': current_region, 'regions': regions, 'launcher_page': launcher_page, 'account_name': ACCOUNT_NAME })
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) elb_page = SitePage.objects.get(name='elb') return render(request, 'elb/loadbalancer-info.html', { 'current_region': current_region, 'regions': regions, 'elb_page': elb_page })
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) script_exec_logs = ScriptExecLog.objects.order_by('-exec_time')[:10] module_page = SitePage.objects.get(name='module') return render(request, 'module/index.html', { 'regions': regions, 'current_region': current_region, 'module_page': module_page, 'script_logs': script_exec_logs })
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) bizmodule_page = SitePage.objects.get(name='bizmodule') return render( request, 'bizmodule/business-module.html', { 'current_region': current_region, 'regions': regions, 'bizmodule_page': bizmodule_page })
def home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) deploy_page = SitePage.objects.get(name='deploy') return render( request, 'deploy/index.html', { 'current_region': current_region, 'regions': regions, 'deploy_page': deploy_page, 'username': request.user.username })
def auto_deploy_home(request): current_region = RegionInfo.get_region(request) regions = RegionInfo.get_regions_infos(['region', 'chinese_name'], exclude_regions=[current_region]) autodeploy_historys = AutoDeployHistory.objects.all().order_by('-id') deploy_history_info = [] for auto_deploy_history in autodeploy_historys: deploy_history_info.append([ auto_deploy_history.id, auto_deploy_history.upgrade_version, auto_deploy_history.is_deploy_finish and auto_deploy_history.is_result_finish, auto_deploy_history.is_success, auto_deploy_history.start_time, auto_deploy_history.managers, auto_deploy_history.end_time ]) logger.debug(deploy_history_info) return render(request, 'autodeploy/autodeploy-index.html', locals())
def get_resources_num(request): """ get num of EC2, ELB, AMI in selected region Args: request (django.http.request.HttpRequest) """ region = RegionInfo.get_region(request) awssession = AwsAccount.get_awssession(region) elb_client = awssession.client('elb') elbs = elb_client.describe_load_balancers() elbnum = len(elbs['LoadBalancerDescriptions']) ec2conn = awssession.resource('ec2') instances = ec2conn.instances.filter(Filters=[{ 'Name': 'tag:Name', 'Values': ['preprd-*', 'prd-*', 'PRD-*'] }]) ec2num = 0 for _ in instances: ec2num += 1 images = ec2conn.images.filter(Filters=[{ 'Name': 'is-public', 'Values': ['false'] }]) aminum = 0 for _ in images: aminum += 1 logger.debug('thers are %s ec2, %s elb, %s ami' % (ec2num, elbnum, aminum)) return HttpResponse(json.dumps({'aminum': aminum, 'ec2num': ec2num, 'elbnum': elbnum}))
def __init__(self): self.region_order_dict = RegionInfo.get_all_regions_group_by_order() self.flag = True self.results = {} for order in self.region_order_dict: for region in self.region_order_dict[order]: self.results.update({region: {'success': [], 'failed': []}}) self.start_topo_and_basic_instances()
def __call__(self): regions = RegionInfo.get_all_regions() thread_pool = threadpool.ThreadPool(len(regions)) thread_requests = threadpool.makeRequests(self.stop_env_in_region, regions) [thread_pool.putRequest(req) for req in thread_requests] thread_pool.wait() stop_result = self.__check_thread_success() if not stop_result['ret']: return {'ret': False, 'msg': stop_result['msg']} logger.info('success stop all environments in regions: %s' % regions) return {'ret': True, 'msg': u'所有区域[%s]环境已停止' % ','.join(regions)}
def __init__(self, **args): self.username = args['username'] self.method = args['method'] self.round_num = 1 if self.method == 'deploy': self.round_num = args['round_num'] self.region_order_dict = RegionInfo.get_all_regions_group_by_order() self.flag = True self.results = {} for order in self.region_order_dict: for region in self.region_order_dict[order]: self.results.update({region: {'success': [], 'failed': []}})
def update_basic_ips(request): regions = RegionInfo.get_all_regions() BasicServiceIps.objects.all().delete() logger.info('truncate table basicserviceips table.') for account in ['beta', 'prd']: try: basic_service_infos = get_basic_ips(regions, account) except Exception as e: logger.error(e.message) return HttpResponse(e.message, status=500) logger.info('save ips to db, account: %s' % account) for service_name in basic_service_infos: basic_service_ips_obj = BasicServiceIps( service_name=service_name, account=account, ips=json.dumps(basic_service_infos[service_name])) basic_service_ips_obj.save(True) logger.info('finish saving basic service ips in account: %s' % account) return HttpResponse('success update service ips')
def __init__(self): self.regions = RegionInfo.get_all_regions() self.flag = True self.result_reason = None
def __init__(self, **args): self.regions = RegionInfo.get_all_regions() self.results = {} self.username = args['username']
def current_region_cn_name(context): current_region = context['current_region'] return RegionInfo.get_region_attribute(current_region, 'chinese_name')
def __init__(self, infos_json): self.upgrade_content = infos_json self.current_regions = RegionInfo.get_all_regions() self.parse_list = infos_json.keys()
def __init__(self): self.region_order = RegionInfo.get_all_regions_group_by_order() self.service_type_dict = {}