mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
Merge pull request #9675 from bistuzx/feature/meter-budget-master
feat(meter): add meter budget&event module
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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 meter
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/meter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.Budgets).WithKeyword("budget")
|
||||
cmd.List(new(options.BudgetListOptions))
|
||||
cmd.Create(new(options.BudgetCreateOptions))
|
||||
cmd.Update(new(options.BudgetUpdateOptions))
|
||||
cmd.Delete(new(options.BudgetDeleteOptions))
|
||||
cmd.Perform("sync-alerts", new(options.BudgetSyncAlertsOptions))
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 meter
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell/events"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
)
|
||||
|
||||
func doMeterEventList(s *mcclient.ClientSession, args *events.EventListOptions) error {
|
||||
return events.DoEventList(modules.MeterLogs, s, args)
|
||||
}
|
||||
|
||||
func init() {
|
||||
R(&events.EventListOptions{}, "meter-event-show", "Show operation meter event logs", doMeterEventList)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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 meter
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/meter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.Reservations).WithKeyword("reservation")
|
||||
cmd.List(new(options.ReservationListOptions))
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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 modules
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
|
||||
var (
|
||||
Budgets modulebase.ResourceManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
Budgets = NewMeterManager("budget", "budgets",
|
||||
[]string{"period_type", "start_time", "end_time", "brand", "cloudaccount_id", "cloudaccount",
|
||||
"cloudprovider_id", "cloudprovider_name", "region_id", "region",
|
||||
"domain_id_filter", "domain_filter", "project_id_filter", "project_filter",
|
||||
"resource_type", "currency", "amount", "alerts", "availability_status", "budget_scope"},
|
||||
[]string{},
|
||||
)
|
||||
register(&Budgets)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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 modules
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
|
||||
var (
|
||||
MeterLogs modulebase.ResourceManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
MeterLogs = NewMeterManager("meter_event", "meter_events",
|
||||
[]string{"id", "ops_time", "obj_id", "obj_type", "obj_name", "user", "user_id", "tenant", "tenant_id", "owner_tenant_id", "action", "notes"},
|
||||
[]string{})
|
||||
register(&MeterLogs)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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 modules
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
|
||||
var (
|
||||
Reservations modulebase.ResourceManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
Reservations = NewMeterManager("reservation", "reservations",
|
||||
[]string{"cloudaccount_id", "resource_type", "reservation_years", "lookback_days", "payment_option",
|
||||
"offering_class", "category", "spec", "instance_amount", "monthly_savings_amount", "upfront_cost",
|
||||
"average_utilization", "monthly_cost", "total_savings_amount", "total_savings_percentage",
|
||||
"currency", "details"},
|
||||
[]string{},
|
||||
)
|
||||
register(&Reservations)
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package meter
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
type BudgetListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
|
||||
func (opt *BudgetListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
|
||||
type BudgetCreateOptions struct {
|
||||
Name string
|
||||
PeriodType string `help:"period of budget, example:year/quarter/month/day" json:"period_type"`
|
||||
StartTime string `help:"start time of budget" json:"start_time"`
|
||||
EndTime string `help:"end time of budget" json:"end_time"`
|
||||
|
||||
Brand string `help:"brand of budget cost filter" json:"brand"`
|
||||
CloudaccountId string `help:"cloudaccount id of budget cost filter" json:"cloudaccount_id"`
|
||||
Cloudaccount string `help:"cloudaccount name of budget cost filter" json:"cloudaccount"`
|
||||
CloudproviderId string `help:"cloudprovider id of budget cost filter" json:"cloudprovider_id"`
|
||||
CloudproviderName string `help:"cloudprovider name of budget cost filter" json:"cloudprovider_name"`
|
||||
RegionId string `help:"region id of budget cost filter" json:"region_id"`
|
||||
Region string `help:"region name of budget cost filter" json:"region"`
|
||||
DomainIdFilter string `help:"domain id of budget cost filter" json:"domain_id_filter"`
|
||||
ProjectIdFilter string `help:"project id of budget cost filter" json:"project_id_filter"`
|
||||
DomainFilter string `help:"domain of budget cost filter" json:"domain_filter"`
|
||||
ProjectFilter string `help:"project of budget cost filter" json:"project_filter"`
|
||||
ResourceType string `help:"resource type of budget cost filter" json:"resource_type"`
|
||||
Currency string `help:"currency of budget cost filter" json:"currency"`
|
||||
|
||||
Amount float64 `help:"amount of budget cost" json:"amount"`
|
||||
}
|
||||
|
||||
func (opt *BudgetCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
|
||||
type BudgetUpdateOptions struct {
|
||||
ID string `help:"ID of budget" json:"-"`
|
||||
|
||||
Brand string `help:"brand of budget cost filter" json:"brand"`
|
||||
CloudaccountId string `help:"cloudaccount id of budget cost filter" json:"cloudaccount_id"`
|
||||
Cloudaccount string `help:"cloudaccount name of budget cost filter" json:"cloudaccount"`
|
||||
CloudproviderId string `help:"cloudprovider id of budget cost filter" json:"cloudprovider_id"`
|
||||
CloudproviderName string `help:"cloudprovider name of budget cost filter" json:"cloudprovider_name"`
|
||||
RegionId string `help:"region id of budget cost filter" json:"region_id"`
|
||||
Region string `help:"region name of budget cost filter" json:"region"`
|
||||
DomainIdFilter string `help:"domain id of budget cost filter" json:"domain_id_filter"`
|
||||
ProjectIdFilter string `help:"project id of budget cost filter" json:"project_id_filter"`
|
||||
DomainFilter string `help:"domain of budget cost filter" json:"domain_filter"`
|
||||
ProjectFilter string `help:"project of budget cost filter" json:"project_filter"`
|
||||
ResourceType string `help:"resource type of budget cost filter" json:"resource_type"`
|
||||
Currency string `help:"currency of budget cost filter" json:"currency"`
|
||||
|
||||
Amount float64 `help:"amount of budget cost" json:"amount"`
|
||||
}
|
||||
|
||||
func (opt *BudgetUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
|
||||
func (opt *BudgetUpdateOptions) GetId() string {
|
||||
return opt.ID
|
||||
}
|
||||
|
||||
type BudgetDeleteOptions struct {
|
||||
ID string `help:"ID of budget" json:"-"`
|
||||
}
|
||||
|
||||
func (opt *BudgetDeleteOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
|
||||
func (opt *BudgetDeleteOptions) GetId() string {
|
||||
return opt.ID
|
||||
}
|
||||
|
||||
type BudgetSyncAlertsOptions struct {
|
||||
ID string `help:"ID of budget" json:"-"`
|
||||
|
||||
Alerts []BudgetAlert `help:"alerts of budget" json:"alerts"`
|
||||
}
|
||||
|
||||
type BudgetAlert struct {
|
||||
AlertType string `help:"alert type, example:cost" json:"alert_type"`
|
||||
|
||||
AlertThresholdType string `help:"alert type, example:percert/amount" json:"alert_threshold_type"`
|
||||
AlertThreshold float64 `help:"alert amount" json:"alert_threshold"`
|
||||
UserIds []string `help:"id of users" json:"user_ids"`
|
||||
}
|
||||
|
||||
func (opt *BudgetSyncAlertsOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
|
||||
func (opt *BudgetSyncAlertsOptions) GetId() string {
|
||||
return opt.ID
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package meter // import "yunion.io/x/onecloud/pkg/mcclient/options/meter"
|
||||
@@ -0,0 +1,22 @@
|
||||
package meter
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
type ReservationListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
CloudaccountId string `help:"cloudaccount id of reservation" json:"cloudaccount_id"`
|
||||
ResourceType string `help:"resource type of reservation" json:"resource_type"`
|
||||
ReservationYears string `help:"number of reservation years" json:"reservation_years"`
|
||||
LookbackDays string `help:"number of previous days will be consider" json:"lookback_days"`
|
||||
PaymentOption string `help:"payment option of reservation, example:all_upfront/partial_upfront/no_upfront" json:"payment_option"`
|
||||
OfferingClass string `help:"offering class of reservation, example:standard/convertible" json:"offering_class"`
|
||||
}
|
||||
|
||||
func (opt *ReservationListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return options.StructToParams(opt)
|
||||
}
|
||||
Reference in New Issue
Block a user