|
@@ -30,50 +30,68 @@ const (
|
|
|
)
|
|
|
|
|
|
//批量创建实例
|
|
|
-func RunInstances(TaskName, computer, flow string, num, hours int) {
|
|
|
+func RunInstances(taskName, computer, flow string, num, hours int) {
|
|
|
if esconfig, ok := ju.Config["esconfig"].(map[string]interface{}); ok {
|
|
|
- InternetMaxBandwidthOut := "0"
|
|
|
+ widthOut := "0"
|
|
|
if flow == "true" {
|
|
|
- InternetMaxBandwidthOut = "10"
|
|
|
+ widthOut = "10"
|
|
|
}
|
|
|
- log.Println(esconfig["LaunchTemplateId"+computer], InternetMaxBandwidthOut)
|
|
|
+ log.Println(esconfig["LaunchTemplateId"+computer], widthOut)
|
|
|
if b, ok := esconfig["available"].(bool); ok && b {
|
|
|
- res := GET("RunInstances", [][]string{
|
|
|
- []string{"RegionId", "cn-beijing"},
|
|
|
- []string{"LaunchTemplateId", qu.ObjToString(esconfig["LaunchTemplateId"+computer])},
|
|
|
- //[]string{"ImageId", "centos_7_06_64_20G_alibase_20181212.vhd"},
|
|
|
- //[]string{"InstanceType", "ecs.ic5.large"},
|
|
|
- //[]string{"SecurityGroupId", "sg-bp16x3td2evrejhkshp7"},
|
|
|
- []string{"VSwitchId", qu.ObjToString(esconfig["VSwitchId"])},
|
|
|
- []string{"InternetMaxBandwidthIn", "50"},
|
|
|
- []string{"InternetMaxBandwidthOut", InternetMaxBandwidthOut},
|
|
|
- []string{"InstanceChargeType", "PostPaid"},
|
|
|
- []string{"SpotStrategy", "SpotWithPriceLimit"},
|
|
|
- []string{"SpotPriceLimit", "4.99"},
|
|
|
- []string{"InstanceName", "extract"},
|
|
|
- []string{"UniqueSuffix", "true"},
|
|
|
- []string{"Password", Password},
|
|
|
- []string{"Amount", fmt.Sprint(num)},
|
|
|
- []string{"AutoReleaseTime", time.Now().Add(time.Duration(hours) * time.Hour).UTC().Format("2006-01-02T15:04:05Z")},
|
|
|
- })
|
|
|
- // {"RequestId":"95653A72-4907-4DD0-86F9-00E216193173","InstanceIdSets":{"InstanceIdSet":["i-2ze0z0xdiqgtwji5jd9s"]}}
|
|
|
- if tmp, ok := res["InstanceIdSets"].(map[string]interface{}); ok {
|
|
|
- if t, ok := tmp["InstanceIdSet"].([]interface{}); ok {
|
|
|
- //实例id持久化
|
|
|
- for _, v := range t {
|
|
|
- db.Mgo.Save("ecs", map[string]interface{}{
|
|
|
- "InstanceId": v,
|
|
|
- "TaskName": TaskName,
|
|
|
- "UseFor": "extract",
|
|
|
- })
|
|
|
+ if zoneIds, _ := esconfig["ZoneIds"].([]interface{}); ok {
|
|
|
+ pernum := num / len(zoneIds)
|
|
|
+ if pernum < 1 {
|
|
|
+ kv, _ := zoneIds[len(zoneIds)-1].(map[string]interface{})
|
|
|
+ runInstances(kv, taskName, widthOut, computer, num, hours)
|
|
|
+ } else {
|
|
|
+ for k, v := range zoneIds {
|
|
|
+ if (k == len(zoneIds)-1) && (num%len(zoneIds) != 0) {
|
|
|
+ pernum = num - pernum*(len(zoneIds)-1)
|
|
|
+ }
|
|
|
+ kv, _ := v.(map[string]interface{})
|
|
|
+ runInstances(kv, taskName, widthOut, computer, pernum, hours)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.Println(res)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func runInstances(kv map[string]interface{}, taskName, widthOut, computer string, pernum, hours int) {
|
|
|
+ log.Println(kv, taskName, widthOut, computer, pernum, hours)
|
|
|
+ res := GET("RunInstances", [][]string{
|
|
|
+ []string{"RegionId", "cn-beijing"},
|
|
|
+ []string{"ZoneId", qu.ObjToString(kv["zoneid"])},
|
|
|
+ []string{"VSwitchId", qu.ObjToString(kv["vswitchid"])},
|
|
|
+ []string{"LaunchTemplateId", qu.ObjToString(kv["LaunchTemplateId"+computer])},
|
|
|
+ //[]string{"ImageId", "centos_7_06_64_20G_alibase_20181212.vhd"},
|
|
|
+ //[]string{"InstanceType", "ecs.ic5.large"},
|
|
|
+ //[]string{"SecurityGroupId", "sg-bp16x3td2evrejhkshp7"},[]string{"InternetMaxBandwidthIn", "50"},
|
|
|
+ []string{"InternetMaxBandwidthOut", widthOut},
|
|
|
+ []string{"InstanceChargeType", "PostPaid"},
|
|
|
+ []string{"SpotStrategy", "SpotWithPriceLimit"},
|
|
|
+ []string{"SpotPriceLimit", "4.99"},
|
|
|
+ []string{"InstanceName", "extract"},
|
|
|
+ []string{"UniqueSuffix", "true"},
|
|
|
+ []string{"Password", Password},
|
|
|
+ []string{"Amount", fmt.Sprint(pernum)},
|
|
|
+ []string{"AutoReleaseTime", time.Now().Add(time.Duration(hours) * time.Hour).UTC().Format("2006-01-02T15:04:05Z")},
|
|
|
+ })
|
|
|
+ if tmp, ok := res["InstanceIdSets"].(map[string]interface{}); ok {
|
|
|
+ if t, ok := tmp["InstanceIdSet"].([]interface{}); ok {
|
|
|
+ //实例id持久化
|
|
|
+ for _, v := range t {
|
|
|
+ db.Mgo.Save("ecs", map[string]interface{}{
|
|
|
+ "InstanceId": v,
|
|
|
+ "TaskName": taskName,
|
|
|
+ "UseFor": "extract",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.Println(res)
|
|
|
+}
|
|
|
+
|
|
|
//查询多台实例的详细信息
|
|
|
func DescribeInstances() {
|
|
|
res := GET("DescribeInstances", [][]string{
|