pull/46/head
starsliao 2 years ago
parent 70a47a2e66
commit 097e9d14e6

@ -124,7 +124,7 @@ def group(account):
data = {'count':'','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/alicloud/{account}/group', data)
def ecs(account,region):
def ecs(account,region,isextip=False):
ak,sk = consul_kv.get_aksk('alicloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')
group_dict = consul_kv.get_value(f'ConsulManager/assets/alicloud/group/{account}')
@ -145,11 +145,17 @@ def ecs(account,region):
ecs = client.describe_instances(describe_instances_request)
ecs_list = ecs.body.instances.to_map()['Instance']
ecs_dict_temp = {i['InstanceId']:{
'name':i['InstanceName'],'group':group_dict.get(i['ResourceGroupId'],''),'ostype':i['OSType'].lower(),
'status':i['Status'],'region':region,
'ip':i["InnerIpAddress"]["IpAddress"] if len(i["InnerIpAddress"]["IpAddress"]) != 0 else i['NetworkInterfaces']['NetworkInterface'][0]['PrimaryIpAddress'],
'name':i['InstanceName'],'group':group_dict.get(i['ResourceGroupId'],''),'ostype':i['OSType'].lower(),'status':i['Status'],'region':region,
'ip':i["InnerIpAddress"]["IpAddress"][0] if i["InnerIpAddress"]["IpAddress"] else i['NetworkInterfaces']['NetworkInterface'][0]['PrimaryIpAddress'],
'cpu':f"{i['Cpu']}",'mem':f"{str(round(i['Memory']/1024,1)).rstrip('.0')}GB",'exp':i['ExpiredTime'].split('T')[0],'ecstag': i.get('Tags',{}).get('Tag',[])
}for i in ecs_list}
if isextip:
for i in ecs_list:
try:
ecs_dict_temp[i['InstanceId']]['ip'] = i['PublicIpAddress']['IpAddress'][0] if i['PublicIpAddress']['IpAddress'] else i["EipAddress"]["IpAddress"]
except:
pass
ecs_dict.update(ecs_dict_temp)
next_token = ecs.body.next_token

@ -126,7 +126,7 @@ def group(account):
data = {'count':'','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/huaweicloud/{account}/group', data)
def ecs(account,region):
def ecs(account,region,isextip=False):
ak,sk = consul_kv.get_aksk('huaweicloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')
group_dict = consul_kv.get_value(f'ConsulManager/assets/huaweicloud/group/{account}')

@ -114,7 +114,7 @@ def group(account):
data = {'count':'','update':f'失败','status':50000,'msg':str(e)}
consul_kv.put_kv(f'ConsulManager/record/jobs/tencent_cloud/{account}/group', data)
def ecs(account,region):
def ecs(account,region,isextip=False):
from tencentcloud.cvm.v20170312 import cvm_client, models
ak,sk = consul_kv.get_aksk('tencent_cloud',account)
now = datetime.datetime.now().strftime('%m.%d/%H:%M')

@ -3,7 +3,7 @@ from flask_restful import reqparse, Resource, Api
from flask_apscheduler import APScheduler
from config import vendors,regions
from units import token_auth,consul_kv
from .jobs import deljob,addjob,runjob,modjob_interval
from .jobs import deljob,addjob,runjob,modjob_interval,modjob_args
import json
blueprint = Blueprint('edit_cloud',__name__)
api = Api(blueprint)
@ -34,16 +34,18 @@ class Edit(Resource):
region = args['region']
restype = ['group']
interval = {'proj_interval': 60, 'ecs_interval': 5, 'rds_interval': 5}
isextip = False
for i in self.job_list:
if f'{vendor}/{account}/group' == i['id']:
interval['proj_interval'] = i['minutes']
elif f'{vendor}/{account}/ecs/{region}' == i['id']:
restype.append('ecs')
interval['ecs_interval'] = i['minutes']
isextip = i["args"][-1] if len(i["args"]) == 3 else False
elif f'{vendor}/{account}/rds/{region}' == i['id']:
restype.append('rds')
interval['rds_interval'] = i['minutes']
return {'code': 20000, 'restype': restype, 'interval': interval}
return {'code': 20000, 'restype': restype, 'interval': interval, 'isextip': isextip}
def post(self,stype):
if stype == 'commit':
args = parser.parse_args()
@ -52,6 +54,7 @@ class Edit(Resource):
account = editjob_dict['account']
region = editjob_dict['region']
restype = editjob_dict['restype']
isextip = editjob_dict['isextip']
proj_interval = int(editjob_dict['proj_interval'])
ecs_interval = int(editjob_dict['ecs_interval'])
rds_interval = int(editjob_dict['rds_interval'])
@ -74,11 +77,17 @@ class Edit(Resource):
isecs = [x for x in self.job_list if x['id'] == f'{vendor}/{account}/ecs/{region}']
if len(isecs) == 1:
if ecs_interval != isecs[0]['minutes']:
isecs[0]['minutes'] = ecs_interval
consul_kv.put_kv(f'ConsulManager/jobs/{ecs_jobid}',isecs[0])
modjob_interval(ecs_jobid,ecs_interval)
if len(isecs[0]['args']) != 3 or isextip != isecs[0]['args'][2]:
isecs[0]['args'][2] = isextip
consul_kv.put_kv(f'ConsulManager/jobs/{ecs_jobid}',isecs[0])
modjob_args(ecs_jobid,isecs[0]['args'])
else:
job_func = f"__main__:{vendor}.ecs"
job_args = [account,region]
job_args = [account,region,isextip]
job_interval = ecs_interval
addjob(ecs_jobid, job_func, job_args, job_interval)
job_dict = {'id':ecs_jobid,'func':job_func,'args':job_args,'minutes':job_interval,
@ -95,6 +104,7 @@ class Edit(Resource):
isrds = [x for x in self.job_list if x['id'] == f'{vendor}/{account}/rds/{region}']
if len(isrds) == 1:
if rds_interval != isrds[0]['minutes']:
isrds[0]['minutes'] = rds_interval
consul_kv.put_kv(f'ConsulManager/jobs/{rds_jobid}',isrds[0])
modjob_interval(rds_jobid,rds_interval)
else:

@ -23,6 +23,9 @@ def deljob(jobid):
def modjob_interval(jobid,job_interval):
Scheduler.modify_job(jobid,trigger='interval',minutes=job_interval)
def modjob_args(jobid,args):
Scheduler.modify_job(jobid,args=args)
def addjob(job_id,job_func,job_args,job_interval):
Scheduler.add_job(id=job_id, func=job_func, args=job_args, trigger='interval',
minutes=job_interval, replace_existing=True)
@ -97,7 +100,10 @@ class Jobs(Resource):
for reg in job_dict['region']:
res_job_id = f"{job_dict['vendor']}/{job_dict['account']}/{res}/{reg}"
res_job_func = f"__main__:{job_dict['vendor']}.{res}"
res_job_args = [job_dict['account'],reg]
if reg == 'ecs':
res_job_args = [job_dict['account'],reg,job_dict['isextip']]
else:
res_job_args = [job_dict['account'],reg]
res_job_interval = int(job_dict[f'{res}_interval'])
Scheduler.add_job(id=res_job_id, func=res_job_func, args=res_job_args, trigger='interval',
minutes=res_job_interval, replace_existing=True)

@ -46,7 +46,7 @@ Object.keys(filters).forEach(key => {
})
Vue.config.productionTip = false
Vue.prototype.VER = 'v0.10.1'
Vue.prototype.VER = 'v0.10.2'
new Vue({
el: '#app',

@ -92,6 +92,8 @@
<el-select v-model="ecsJob.vendor" placeholder="请选择" @change="ecsJob.region=[]">
<el-option v-for="item in vendors" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<span v-if="ecsJob.vendor === 'huaweicloud'"><br><font size="3px" color="#ff0000">(--)</font></span>
<span v-if="ecsJob.vendor === 'alicloud'">ECS</span>
</el-form-item>
<el-form-item prop="account">
<span slot="label">
@ -123,7 +125,9 @@
<el-checkbox label="rds">MySQL</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item v-if="restype.includes('ecs') && ecsJob.vendor === 'alicloud'" label="优先获取外网IP" prop="isextip">
<el-checkbox v-model="ecsJob.isextip">(ECS)</el-checkbox>
</el-form-item>
<el-form-item prop="proj_interval">
<span slot="label">
<span class="span-box">
@ -170,7 +174,7 @@
</el-select>
</el-form-item>
<el-form-item label="修改密钥">
<el-switch v-model="editJob.akskswitch" />
<el-switch v-model="editJob.akskswitch" active-text="" />
</el-form-item>
<el-form-item v-if="editJob.akskswitch" label="Access Key" prop="ak">
<el-input v-model="editJob.ak" placeholder="请输AccessKey ID" />
@ -192,7 +196,9 @@
<el-checkbox label="rds">MySQL</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item v-if="editJob.restype.includes('ecs') && editJob.vendor === 'alicloud'" label="优先获取外网IP" prop="isextip">
<el-checkbox v-model="editJob.isextip">(ECS)</el-checkbox>
</el-form-item>
<el-form-item prop="proj_interval">
<span slot="label">
<span class="span-box">
@ -377,6 +383,7 @@ export default {
this.listLoading = true
findGroup(vendor, account, region).then(response => {
this.editJob.restype = response.restype
this.editJob.isextip = response.isextip
this.editJob.proj_interval = response.interval.proj_interval
this.editJob.ecs_interval = response.interval.ecs_interval
this.editJob.rds_interval = response.interval.rds_interval
@ -384,14 +391,14 @@ export default {
})
},
handleEdit() {
this.editJob = { vendor: '', akskswitch: false, ak: '', sk: '', region: '', account: '', restype: ['group'], proj_interval: 60, ecs_interval: 10, rds_interval: 20 }
this.editJob = { vendor: '', akskswitch: false, ak: '', sk: '', region: '', account: '', restype: ['group'], proj_interval: 60, ecs_interval: 10, rds_interval: 20, isextip: false }
getCloud().then(response => {
this.cloud_dict = response.cloud_dict
})
this.editFormVisible = true
},
handleCreate() {
this.ecsJob = { vendor: '', ak: '', sk: '', region: [], account: '', proj_interval: 60, ecs_interval: 10, rds_interval: 20 }
this.ecsJob = { vendor: '', ak: '', sk: '', region: [], account: '', proj_interval: 60, ecs_interval: 10, rds_interval: 20, isextip: false }
this.ecsJob.account = this.query.account
this.newFormVisible = true
},

Loading…
Cancel
Save