feature: fetch options of an application via api (#14398)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-06-04 10:33:31 +08:00
committed by GitHub
parent 6f5c0a6962
commit 43d04043a5
12 changed files with 181 additions and 14 deletions
+1
View File
@@ -62,6 +62,7 @@ func init() {
cmd.Get("ipmi", &options.BaseIdOptions{})
cmd.Get("vnc", &options.BaseIdOptions{})
cmd.Get("app-options", &options.BaseIdOptions{})
R(&options.BaseIdOptions{}, "host-logininfo", "Get SSH login information of a host", func(s *mcclient.ClientSession, args *options.BaseIdOptions) error {
srvid, e := modules.Hosts.GetId(s, args.ID, nil)
+34
View File
@@ -0,0 +1,34 @@
// 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 misc
import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
func init() {
type AppOptionsOptions struct {
SERVICE string `help:"Service type"`
}
R(&AppOptionsOptions{}, "app-options-show", "query backend service for its options", func(s *mcclient.ClientSession, args *AppOptionsOptions) error {
opts, err := modules.GetAppOptions(s, args.SERVICE)
if err != nil {
return err
}
printObject(opts)
return nil
})
}
+4
View File
@@ -25,9 +25,11 @@ import (
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/baremetal"
"yunion.io/x/onecloud/pkg/baremetal/options"
baremetalstatus "yunion.io/x/onecloud/pkg/baremetal/status"
"yunion.io/x/onecloud/pkg/baremetal/tasks"
baremetaltypes "yunion.io/x/onecloud/pkg/baremetal/types"
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient/auth"
)
@@ -60,6 +62,8 @@ func customizeHandlerInfo(info *appsrv.SHandlerInfo) {
}
func initBaremetalsHandler(app *appsrv.Application) {
app_common.ExportOptionsHandler(app, &options.Options)
// baremetal actions handler
AddHandler(app, "GET", bmActionPrefix("notify"), bmObjMiddleware(handleBaremetalNotify))
AddHandler(app, "POST", bmActionPrefix("maintenance"), bmObjMiddleware(handleBaremetalMaintenance))
+44
View File
@@ -0,0 +1,44 @@
// 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 app
import (
"context"
"net/http"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/util/rbacutils"
)
func ExportOptionsHandler(app *appsrv.Application, options interface{}) {
hf := func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
userCred := auth.FetchUserCredential(ctx, policy.FilterPolicyCredential)
result := policy.PolicyManager.Allow(rbacutils.ScopeSystem, userCred, consts.GetServiceType(), "app-options", "list")
if result.Result == rbacutils.Deny {
httperrors.ForbiddenError(ctx, w, "Not allow to access")
return
}
appsrv.SendJSON(w, jsonutils.Marshal(options))
}
ahf := auth.Authenticate(hf)
name := "get_app_options"
app.AddHandler2("GET", "/app-options", ahf, nil, name, nil)
}
+4
View File
@@ -6031,3 +6031,7 @@ func (self *SHost) GetPinnedCpusetCores(ctx context.Context, userCred mcclient.T
}
return ret, nil
}
func (h *SHost) GetDetailsAppOptions(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
return h.Request(ctx, userCred, httputils.GET, "/app-options", nil, nil)
}
+4
View File
@@ -17,6 +17,7 @@ package service
import (
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/appsrv/dispatcher"
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/proxy"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
@@ -24,6 +25,7 @@ import (
"yunion.io/x/onecloud/pkg/compute/capabilities"
"yunion.io/x/onecloud/pkg/compute/misc"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/compute/specs"
"yunion.io/x/onecloud/pkg/compute/sshkeys"
"yunion.io/x/onecloud/pkg/compute/usages"
@@ -50,6 +52,8 @@ func InitHandlers(app *appsrv.Application) {
taskman.AddTaskHandler("", app)
misc.AddMiscHandler("", app)
app_common.ExportOptionsHandler(app, &options.Options)
for _, manager := range []db.IModelManager{
taskman.TaskManager,
taskman.SubTaskManager,
+2
View File
@@ -143,6 +143,8 @@ func (host *SHostService) initHandlers(app *appsrv.Application) {
downloader.AddDownloadHandler("", app)
kubehandlers.AddKubeAgentHandler("", app)
hosthandler.AddHostHandler("", app)
app_common.ExportOptionsHandler(app, &options.HostOptions)
}
func (host *SHostService) initEtcdConfig() error {
+23 -14
View File
@@ -21,10 +21,21 @@ import (
"yunion.io/x/onecloud/pkg/util/fileutils2"
)
type SHostOptions struct {
type SHostBaseOptions struct {
common_options.HostCommonOptions
ManageNtpConfiguration bool `default:"true"`
DisableSecurityGroup bool `help:"disable security group" default:"false"`
}
type SHostOptions struct {
common_options.EtcdOptions
SHostBaseOptions
CommonConfigFile string `help:"common config file for container"`
HostType string `help:"Host server type, either hypervisor or kubelet" default:"hypervisor"`
ListenInterface string `help:"Master address of host server"`
BridgeDriver string `help:"Bridge driver, bridge or openvswitch" default:"openvswitch"`
@@ -54,14 +65,16 @@ type SHostOptions struct {
EnableMonitor bool `help:"Enable monitor"`
ReportInterval int `help:"Report interval in seconds" default:"60"`
BwDownloadBandwidth int `help:"Default ingress bandwidth in mbit (0 disabled)" default:"10"`
BwDownloadBandwidth int `help:"Default ingress bandwidth in mbit (0 disabled)" default:"1000"`
DnsServer string `help:"Address of host DNS server"`
DnsServerLegacy string `help:"Deprecated Address of host DNS server"`
ChntpwPath string `help:"path to chntpw tool" default:"/usr/local/bin/chntpw.static"`
OvmfPath string `help:"Path to OVMF.fd" default:"/opt/cloud/contrib/OVMF.fd"`
LinuxDefaultRootUser bool `help:"Default account for linux system is root"`
ChntpwPath string `help:"path to chntpw tool" default:"/usr/local/bin/chntpw.static"`
OvmfPath string `help:"Path to OVMF.fd" default:"/opt/cloud/contrib/OVMF.fd"`
LinuxDefaultRootUser bool `help:"Default account for linux system is root"`
WindowsDefaultAdminUser bool `default:"true" help:"Default account for Windows system is Administrator"`
BlockIoScheduler string `help:"Block IO scheduler, deadline or cfq" default:"deadline"`
EnableKsm bool `help:"Enable Kernel Same Page Merging"`
@@ -99,9 +112,8 @@ type SHostOptions struct {
EnableCpuBinding bool `default:"true" help:"Enable cpu binding and rebalance"`
EnableOpenflowController bool `default:"false"`
PingRegionInterval int `default:"60" help:"interval to ping region, deefault is 1 minute"`
ManageNtpConfiguration bool `default:"true"`
LogSystemdUnits []string `help:"Systemd units log collected by fluent-bit"`
PingRegionInterval int `default:"60" help:"interval to ping region, deefault is 1 minute"`
LogSystemdUnits []string `help:"Systemd units log collected by fluent-bit"`
// 更改默认带宽限速为400GBps, qiujian
BandwidthLimit int `default:"400000" help:"Bandwidth upper bound when migrating disk image in MB/sec, default 400GBps"`
// 热迁移带宽,预期不低于8MBps, 1G Memory takes 128 seconds
@@ -111,8 +123,7 @@ type SHostOptions struct {
SnapshotDirSuffix string `help:"Snapshot dir name equal diskId concat snapshot dir suffix" default:"_snap"`
SnapshotRecycleDay int `default:"1" help:"Snapshot Recycle delete Duration day"`
EnableTelegraf bool `default:"true" help:"enable send monitoring data to telegraf"`
WindowsDefaultAdminUser bool `default:"true" help:"Default account for Windows system is Administrator"`
EnableTelegraf bool `default:"true" help:"enable send monitoring data to telegraf"`
HostCpuPassthrough bool `default:"true" help:"if it is true, set qemu cpu type as -cpu host, otherwise, qemu64. default is true"`
DisableSetCgroup bool `default:"false" help:"disable cgroup for guests"`
@@ -121,8 +132,6 @@ type SHostOptions struct {
DefaultRequestWorkerCount int `default:"8" help:"default request worker count"`
CommonConfigFile string `help:"common config file for container"`
AllowSwitchVMs bool `help:"allow machines run as switch (spoof mac)" default:"true"`
AllowRouterVMs bool `help:"allow machines run as router (spoof ip)" default:"true"`
@@ -179,11 +188,11 @@ var (
func Parse() (hostOpts SHostOptions) {
common_options.ParseOptions(&hostOpts, os.Args, "host.conf", "host")
if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) {
commonCfg := &common_options.HostCommonOptions{}
commonCfg := &SHostBaseOptions{}
commonCfg.Config = hostOpts.CommonConfigFile
common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host")
baseOpt := hostOpts.BaseOptions.BaseOptions
hostOpts.HostCommonOptions = *commonCfg
hostOpts.SHostBaseOptions = *commonCfg
// keep base options
hostOpts.BaseOptions.BaseOptions = baseOpt
}
+4
View File
@@ -17,10 +17,12 @@ package service
import (
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/appsrv/dispatcher"
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/image/models"
"yunion.io/x/onecloud/pkg/image/options"
"yunion.io/x/onecloud/pkg/image/usages"
)
@@ -42,6 +44,8 @@ func InitHandlers(app *appsrv.Application) {
usages.AddUsageHandler(API_VERSION, app)
taskman.AddTaskHandler(API_VERSION, app)
app_common.ExportOptionsHandler(app, &options.Options)
for _, manager := range []db.IModelManager{
taskman.TaskManager,
taskman.SubTaskManager,
+4
View File
@@ -17,11 +17,13 @@ package service
import (
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/appsrv/dispatcher"
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/keystone/cronjobs"
"yunion.io/x/onecloud/pkg/keystone/models"
"yunion.io/x/onecloud/pkg/keystone/options"
"yunion.io/x/onecloud/pkg/keystone/tokens"
"yunion.io/x/onecloud/pkg/keystone/usages"
)
@@ -42,6 +44,8 @@ func InitHandlers(app *appsrv.Application) {
usages.AddUsageHandler(API_VERSION, app)
taskman.AddTaskHandler(API_VERSION, app)
app_common.ExportOptionsHandler(app, &options.Options)
tokens.AddHandler(app)
for _, manager := range []db.IModelManager{
+31
View File
@@ -0,0 +1,31 @@
// 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 modulebase
import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/onecloud/pkg/mcclient"
)
func GetAppOptions(s *mcclient.ClientSession, serviceType string) (jsonutils.JSONObject, error) {
man := NewBaseManager(serviceType, "", "", nil, nil)
_, resp, err := man.jsonRequest(s, "GET", "/app-options", nil, nil)
if err != nil {
return nil, errors.Wrap(err, "rawBaseUrlRequest")
}
return resp, nil
}
+26
View File
@@ -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 modules
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
)
func GetAppOptions(s *mcclient.ClientSession, serviceType string) (jsonutils.JSONObject, error) {
return modulebase.GetAppOptions(s, serviceType)
}