From 291230694dad28719edf0ee482495731dcdc6b89 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Sun, 22 Mar 2020 18:06:45 +0800 Subject: [PATCH] mcclient: add proxysettings manager --- cmd/climc/shell/proxysettings.go | 73 +++++++++++++++++++++++ pkg/mcclient/modules/mod_proxysettings.go | 40 +++++++++++++ pkg/mcclient/options/proxysettings.go | 42 +++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 cmd/climc/shell/proxysettings.go create mode 100644 pkg/mcclient/modules/mod_proxysettings.go create mode 100644 pkg/mcclient/options/proxysettings.go diff --git a/cmd/climc/shell/proxysettings.go b/cmd/climc/shell/proxysettings.go new file mode 100644 index 0000000000..f3f0d7bf81 --- /dev/null +++ b/cmd/climc/shell/proxysettings.go @@ -0,0 +1,73 @@ +// 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 shell + +import ( + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +func init() { + R(&options.ProxySettingCreateOptions{}, "proxysetting-create", "Create proxysetting", func(s *mcclient.ClientSession, opts *options.ProxySettingCreateOptions) error { + params, err := options.StructToParams(opts) + if err != nil { + return err + } + proxysetting, err := modules.ProxySettings.Create(s, params) + if err != nil { + return err + } + printObject(proxysetting) + return nil + }) + R(&options.ProxySettingGetOptions{}, "proxysetting-show", "Show proxysetting", func(s *mcclient.ClientSession, opts *options.ProxySettingGetOptions) error { + proxysetting, err := modules.ProxySettings.Get(s, opts.ID, nil) + if err != nil { + return err + } + printObject(proxysetting) + return nil + }) + R(&options.ProxySettingListOptions{}, "proxysetting-list", "List proxysettings", func(s *mcclient.ClientSession, opts *options.ProxySettingListOptions) error { + params, err := options.ListStructToParams(opts) + if err != nil { + return err + } + result, err := modules.ProxySettings.List(s, params) + if err != nil { + return err + } + printList(result, modules.ProxySettings.GetColumns(s)) + return nil + }) + R(&options.ProxySettingUpdateOptions{}, "proxysetting-update", "Update proxysetting", func(s *mcclient.ClientSession, opts *options.ProxySettingUpdateOptions) error { + params, err := options.StructToParams(opts) + proxysetting, err := modules.ProxySettings.Update(s, opts.ID, params) + if err != nil { + return err + } + printObject(proxysetting) + return nil + }) + R(&options.ProxySettingDeleteOptions{}, "proxysetting-delete", "Delete proxysetting", func(s *mcclient.ClientSession, opts *options.ProxySettingDeleteOptions) error { + proxysetting, err := modules.ProxySettings.Delete(s, opts.ID, nil) + if err != nil { + return err + } + printObject(proxysetting) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_proxysettings.go b/pkg/mcclient/modules/mod_proxysettings.go new file mode 100644 index 0000000000..1d10347897 --- /dev/null +++ b/pkg/mcclient/modules/mod_proxysettings.go @@ -0,0 +1,40 @@ +// 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" +) + +type ProxySettingManager struct { + modulebase.ResourceManager +} + +var ( + ProxySettings ProxySettingManager +) + +func init() { + ProxySettings = ProxySettingManager{NewComputeManager("proxysetting", "proxysettings", + []string{ + "ID", + "Name", + "http_proxy", + "https_proxy", + "no_proxy", + }, + []string{})} + registerCompute(&ProxySettings) +} diff --git a/pkg/mcclient/options/proxysettings.go b/pkg/mcclient/options/proxysettings.go new file mode 100644 index 0000000000..f8838014ff --- /dev/null +++ b/pkg/mcclient/options/proxysettings.go @@ -0,0 +1,42 @@ +// 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 options + +type ProxySettingCreateOptions struct { + NAME string + + HTTPProxy string + HTTPSProxy string + NoProxy string +} + +type ProxySettingGetOptions struct { + ID string `json:"-"` +} + +type ProxySettingUpdateOptions struct { + ID string `json:"-"` + Name string + + BackendGroup string +} + +type ProxySettingDeleteOptions struct { + ID string `json:"-"` +} + +type ProxySettingListOptions struct { + BaseListOptions +}