mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10991 from rainzm/automated-cherry-pick-of-#10990-upstream-release-3.7
Automated cherry pick of #10990: fix for install monitor agent
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
FROM registry.cn-beijing.aliyuncs.com/yunionio/ansibleserver-base:v1.0.3
|
||||
|
||||
# install playbook and telegraf install pkg
|
||||
COPY --from=registry.cn-beijing.aliyuncs.com/yunionio/file-repo:v0.1.1 /opt/yunion/playbook /opt/yunion/playbook
|
||||
COPY --from=registry.cn-beijing.aliyuncs.com/yunionio/file-repo:v0.1.1 /opt/yunion/ansible-install-pkg /opt/yunion/ansible-install-pkg
|
||||
COPY --from=registry.cn-beijing.aliyuncs.com/yunionio/file-repo:v0.1.2 /opt/yunion/playbook /opt/yunion/playbook
|
||||
COPY --from=registry.cn-beijing.aliyuncs.com/yunionio/file-repo:v0.1.2 /opt/yunion/ansible-install-pkg /opt/yunion/ansible-install-pkg
|
||||
|
||||
ADD ./_output/alpine-build/bin/ansibleserver /opt/yunion/bin/ansibleserver
|
||||
|
||||
@@ -72,7 +72,11 @@ func (self *ApplyScriptTask) taskFailed(ctx context.Context, sa *models.SScriptA
|
||||
log.Errorf("unable to StartApply script %s to server %s", sa.ScriptId, sa.GuestId)
|
||||
}
|
||||
}
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
var errMsg string
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
}
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(errMsg))
|
||||
}
|
||||
|
||||
func (self *ApplyScriptTask) taskSuccess(ctx context.Context, sa *models.SScriptApply, sar *models.SScriptApplyRecord) {
|
||||
@@ -325,7 +329,7 @@ func (self *ApplyScriptTask) OnAnsiblePlaybookComplete(ctx context.Context, obj
|
||||
sarId, _ := self.Params.GetString("script_apply_record_id")
|
||||
osar, err := models.ScriptApplyRecordManager.FetchById(sarId)
|
||||
if err != nil {
|
||||
log.Errorf("unable to fetch script apply record %s", sarId)
|
||||
log.Errorf("unable to fetch script apply record %s: %v", sarId, err)
|
||||
self.taskSuccess(ctx, sa, nil)
|
||||
}
|
||||
self.taskSuccess(ctx, sa, osar.(*models.SScriptApplyRecord))
|
||||
@@ -337,13 +341,13 @@ func (self *ApplyScriptTask) OnAnsiblePlaybookCompleteFailed(ctx context.Context
|
||||
forwardId, _ := self.Params.GetString("proxy_forward_id")
|
||||
_, err := cloudproxy.Forwards.Delete(session, forwardId, nil)
|
||||
if err != nil {
|
||||
log.Errorf("unable to delete proxy forward %s", forwardId)
|
||||
log.Errorf("unable to delete proxy forward %s: %v", forwardId, err)
|
||||
}
|
||||
sa := obj.(*models.SScriptApply)
|
||||
sarId, _ := self.Params.GetString("script_apply_record_id")
|
||||
osar, err := models.ScriptApplyRecordManager.FetchById(sarId)
|
||||
if err != nil {
|
||||
log.Errorf("unable to fetch script apply record %s", sarId)
|
||||
log.Errorf("unable to fetch script apply record %s: %v", sarId, err)
|
||||
self.taskSuccess(ctx, sa, nil)
|
||||
}
|
||||
self.taskFailed(ctx, sa, osar.(*models.SScriptApplyRecord), errors.Error(body.String()))
|
||||
|
||||
@@ -65,6 +65,7 @@ func proxyEndpoints(ctx context.Context, proxyEndpointId string, info sServerInf
|
||||
for _, netId := range info.NetworkIds {
|
||||
filter := jsonutils.NewDict()
|
||||
filter.Set("network_id", jsonutils.NewString(netId))
|
||||
filter.Set("scope", jsonutils.NewString("system"))
|
||||
lr, err := cloudproxy.ProxyEndpoints.List(session, filter)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to list proxy endpoint in network %q", netId)
|
||||
@@ -81,6 +82,7 @@ func proxyEndpoints(ctx context.Context, proxyEndpointId string, info sServerInf
|
||||
}
|
||||
filter := jsonutils.NewDict()
|
||||
filter.Set("vpc_id", jsonutils.NewString(info.VpcId))
|
||||
filter.Set("scope", jsonutils.NewString("system"))
|
||||
lr, err := cloudproxy.ProxyEndpoints.List(session, filter)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "unable to list proxy endpoint in vpc %q", info.VpcId)
|
||||
@@ -138,8 +140,12 @@ func convertInfluxdbUrl(ctx context.Context, pUrl string, endpointId string) (po
|
||||
if err != nil {
|
||||
return 0, nil, errors.Wrap(err, "failed to list forward")
|
||||
}
|
||||
var forwardId string
|
||||
var lastSeen string
|
||||
if len(lr.Data) > 0 {
|
||||
port, _ = lr.Data[0].Int("bind_port")
|
||||
forwardId, _ = lr.Data[0].GetString("id")
|
||||
lastSeen, _ = lr.Data[0].GetString("last_seen")
|
||||
} else {
|
||||
var rUrl *url.URL
|
||||
rUrl, err = url.Parse(pUrl)
|
||||
@@ -161,13 +167,32 @@ func convertInfluxdbUrl(ctx context.Context, pUrl string, endpointId string) (po
|
||||
err = errors.Wrapf(err, "unable to create forward with create params %s", createP.String())
|
||||
return
|
||||
}
|
||||
forwardId, _ := forward.GetString("id")
|
||||
forwardId, _ = forward.GetString("id")
|
||||
lastSeen, _ = forward.GetString("last_seen")
|
||||
recycle = func() error {
|
||||
_, err := cloudproxy.Forwards.Delete(session, forwardId, nil)
|
||||
return err
|
||||
}
|
||||
port, _ = forward.Int("bind_port")
|
||||
}
|
||||
// wait forward last seen not empty
|
||||
times, waitTime := 0, time.Second
|
||||
var data jsonutils.JSONObject
|
||||
for lastSeen == "" && times < 10 {
|
||||
time.Sleep(waitTime)
|
||||
times += 1
|
||||
waitTime += time.Second * time.Duration(times)
|
||||
data, err = cloudproxy.Forwards.GetSpecific(session, forwardId, "last_seen", nil)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "unable to check last_seen for forward %s", forwardId)
|
||||
return
|
||||
}
|
||||
log.Infof("data of last seen: %s", data)
|
||||
lastSeen, _ = data.GetString("last_seen")
|
||||
}
|
||||
if lastSeen == "" {
|
||||
err = errors.Wrapf(err, "last_seen of forward %s always is empty, something wrong", forwardId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -274,7 +299,7 @@ func checkUrl(ctx context.Context, url string, host *ansible_api.AnsibleHost) (b
|
||||
}
|
||||
}()
|
||||
times, waitTimes := 0, time.Second
|
||||
for times < 5 {
|
||||
for times < 10 {
|
||||
time.Sleep(waitTimes)
|
||||
times++
|
||||
waitTimes += time.Second * time.Duration(times)
|
||||
|
||||
Reference in New Issue
Block a user