fix(region): vendor update (#23369)

This commit is contained in:
屈轩
2025-09-24 17:22:57 +08:00
committed by GitHub
parent 4c3186f4a1
commit 0bbc92e46d
98 changed files with 20504 additions and 64 deletions
-58
View File
@@ -30,7 +30,6 @@ import (
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/modules/identity"
"yunion.io/x/onecloud/pkg/mcclient/modules/logger"
"yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
"yunion.io/x/onecloud/pkg/mcclient/modules/webconsole"
)
@@ -544,63 +543,6 @@ func (self *SRegion) CreateInstance(hostId, hypervisor string, opts *cloudprovid
return ins, self.create(&modules.Servers, input, ins)
}
type SMetricData struct {
Id string `json:"id"`
Time time.Time `json:"time"`
Value float64 `json:"value"`
}
func (cli *SCloudpodsClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
brandArr := []string{"OneCloud"}
metrics := []SMetricData{}
usefulResourceType := []cloudprovider.TResourceType{cloudprovider.METRIC_RESOURCE_TYPE_HOST, cloudprovider.METRIC_RESOURCE_TYPE_SERVER}
isUse, _ := utils.InArray(opts.ResourceType, usefulResourceType)
if !isUse {
return nil, nil
}
for i := 0; i < len(brandArr); i++ {
params := map[string]interface{}{
"metric_name": opts.MetricType,
"start_time": opts.StartTime,
"end_time": opts.EndTime,
"interval": "1m",
"tag_pairs": map[string]interface{}{
"brand": brandArr[i],
},
}
onecloudObj, err := monitor.UnifiedMonitorManager.Get(cli.s, "simple-query", jsonutils.Marshal(params))
if err != nil {
return nil, err
}
tmp := []SMetricData{}
onecloudObj.Unmarshal(&tmp, "values")
metrics = append(metrics, tmp...)
}
idWithMetric := map[string][]cloudprovider.MetricValue{}
for _, v := range metrics {
if _, isExist := idWithMetric[v.Id]; !isExist {
idWithMetric[v.Id] = []cloudprovider.MetricValue{{
Timestamp: v.Time,
Value: v.Value}}
} else {
idWithMetric[v.Id] = append(idWithMetric[v.Id], cloudprovider.MetricValue{
Timestamp: v.Time,
Value: v.Value})
}
}
res := []cloudprovider.MetricValues{}
for _, metric := range metrics {
res = append(res, cloudprovider.MetricValues{
Id: metric.Id,
MetricType: opts.MetricType,
Values: idWithMetric[metric.Id],
})
}
return res, nil
}
func (self *SInstance) CreateDisk(ctx context.Context, opts *cloudprovider.GuestDiskCreateOptions) (string, error) {
diskIds := []string{}
for _, disk := range self.DisksInfo {
+131
View File
@@ -0,0 +1,131 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cloudpods
import (
"crypto/sha256"
"fmt"
"strings"
"time"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
monitorapi "yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
)
func (cli *SCloudpodsClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
usefulResourceType := []cloudprovider.TResourceType{cloudprovider.METRIC_RESOURCE_TYPE_HOST, cloudprovider.METRIC_RESOURCE_TYPE_SERVER}
isUse, _ := utils.InArray(opts.ResourceType, usefulResourceType)
if !isUse {
return nil, nil
}
info := strings.Split(string(opts.MetricType), ".")
if len(info) != 2 {
return nil, errors.Errorf("invalid metric type: %s", opts.MetricType)
}
measurement := info[0]
field := info[1]
from := fmt.Sprintf("now-%dm", int(time.Now().Sub(opts.StartTime).Minutes()))
to := fmt.Sprintf("now-%dm", int(time.Now().Sub(opts.EndTime).Minutes()))
query := &monitorapi.AlertQuery{
Model: monitorapi.MetricQuery{
Database: "telegraf",
Measurement: measurement,
Selects: []monitorapi.MetricQuerySelect{
{
{
Type: "field",
Params: []string{field},
},
},
},
Tags: []monitorapi.MetricQueryTag{
{
Key: "brand",
Operator: "=",
Value: "OneCloud",
},
},
},
From: from,
To: to,
}
input := monitorapi.MetricQueryInput{
From: from,
To: to,
Scope: "system",
Interval: "1m",
MetricQuery: []*monitorapi.AlertQuery{
query,
},
SkipCheckSeries: true,
}
if cli.debug {
input.ShowMeta = true
}
data := jsonutils.Marshal(input).(*jsonutils.JSONDict)
sum256 := sha256.Sum256([]byte(data.String()))
data.Set("signature", jsonutils.NewString(fmt.Sprintf("%x", sum256)))
resp, err := monitor.UnifiedMonitorManager.PerformClassAction(cli.s, "query", data)
if err != nil {
return nil, errors.Wrapf(err, "query metric")
}
metrics := &monitorapi.MetricsQueryResult{}
err = resp.Unmarshal(metrics)
if err != nil {
return nil, errors.Wrapf(err, "query metric Unmarshal")
}
res := []cloudprovider.MetricValues{}
for _, serie := range metrics.Series {
if len(serie.Tags) == 0 || (len(serie.Tags["vm_id"]) == 0 && len(serie.Tags["host_id"]) == 0) {
continue
}
id := serie.Tags["vm_id"]
if len(id) == 0 {
id = serie.Tags["host_id"]
}
metric := cloudprovider.MetricValues{
Id: id,
MetricType: opts.MetricType,
Values: []cloudprovider.MetricValue{},
}
values := []cloudprovider.MetricValue{}
for _, point := range serie.Points {
if len(point) != 2 {
continue
}
values = append(values, cloudprovider.MetricValue{
Timestamp: point.Time(),
Value: point.Value(),
})
}
if len(values) == 0 {
continue
}
metric.Values = values
res = append(res, metric)
}
return res, nil
}
+8
View File
@@ -15,6 +15,8 @@
package shell
import (
"time"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/log"
"yunion.io/x/pkg/util/shellutils"
@@ -24,6 +26,12 @@ import (
func init() {
shellutils.R(&cloudprovider.MetricListOptions{}, "metric-list", "List metrics in a namespace", func(cli *cloudpods.SRegion, args *cloudprovider.MetricListOptions) error {
if args.StartTime.IsZero() {
args.StartTime = time.Now().Add(-time.Minute * 10)
}
if args.EndTime.IsZero() {
args.EndTime = time.Now().Add(-time.Minute * 1)
}
metrics, err := cli.GetClient().GetMetrics(args)
if err != nil {
return err