From 034bf55af76d9faccd033dcdf5d9fce85a66c2d7 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Tue, 23 Feb 2021 15:32:56 +0800 Subject: [PATCH] climc: add commands for cloudproxy --- cmd/climc/main.go | 1 + cmd/climc/shell/cloudproxy/forwards.go | 33 +++++ cmd/climc/shell/cloudproxy/proxy_agents.go | 31 +++++ cmd/climc/shell/cloudproxy/proxy_endpoints.go | 32 +++++ cmd/climc/shell/cloudproxy/proxy_matches.go | 31 +++++ pkg/mcclient/modules/cloudproxy/common.go | 31 +++++ pkg/mcclient/modules/cloudproxy/doc.go | 15 +++ .../modules/cloudproxy/mod_cloudmatches.go | 45 +++++++ .../modules/cloudproxy/mod_forwards.go | 52 ++++++++ .../modules/cloudproxy/mod_proxyagents.go | 44 +++++++ .../modules/cloudproxy/mod_proxyendpoints.go | 45 +++++++ pkg/mcclient/options/base.go | 2 +- pkg/mcclient/options/cloudproxy/doc.go | 15 +++ pkg/mcclient/options/cloudproxy/forwards.go | 120 ++++++++++++++++++ .../options/cloudproxy/proxy_agents.go | 67 ++++++++++ .../options/cloudproxy/proxy_endpoints.go | 109 ++++++++++++++++ .../options/cloudproxy/proxy_matches.go | 70 ++++++++++ 17 files changed, 742 insertions(+), 1 deletion(-) create mode 100644 cmd/climc/shell/cloudproxy/forwards.go create mode 100644 cmd/climc/shell/cloudproxy/proxy_agents.go create mode 100644 cmd/climc/shell/cloudproxy/proxy_endpoints.go create mode 100644 cmd/climc/shell/cloudproxy/proxy_matches.go create mode 100644 pkg/mcclient/modules/cloudproxy/common.go create mode 100644 pkg/mcclient/modules/cloudproxy/doc.go create mode 100644 pkg/mcclient/modules/cloudproxy/mod_cloudmatches.go create mode 100644 pkg/mcclient/modules/cloudproxy/mod_forwards.go create mode 100644 pkg/mcclient/modules/cloudproxy/mod_proxyagents.go create mode 100644 pkg/mcclient/modules/cloudproxy/mod_proxyendpoints.go create mode 100644 pkg/mcclient/options/cloudproxy/doc.go create mode 100644 pkg/mcclient/options/cloudproxy/forwards.go create mode 100644 pkg/mcclient/options/cloudproxy/proxy_agents.go create mode 100644 pkg/mcclient/options/cloudproxy/proxy_endpoints.go create mode 100644 pkg/mcclient/options/cloudproxy/proxy_matches.go diff --git a/cmd/climc/main.go b/cmd/climc/main.go index c5adb213c1..640bce3f1e 100644 --- a/cmd/climc/main.go +++ b/cmd/climc/main.go @@ -21,6 +21,7 @@ import ( _ "yunion.io/x/onecloud/cmd/climc/shell/cloudevent" _ "yunion.io/x/onecloud/cmd/climc/shell/cloudid" _ "yunion.io/x/onecloud/cmd/climc/shell/cloudnet" + _ "yunion.io/x/onecloud/cmd/climc/shell/cloudproxy" _ "yunion.io/x/onecloud/cmd/climc/shell/compute" _ "yunion.io/x/onecloud/cmd/climc/shell/etcd" _ "yunion.io/x/onecloud/cmd/climc/shell/events" diff --git a/cmd/climc/shell/cloudproxy/forwards.go b/cmd/climc/shell/cloudproxy/forwards.go new file mode 100644 index 0000000000..4c8833e455 --- /dev/null +++ b/cmd/climc/shell/cloudproxy/forwards.go @@ -0,0 +1,33 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" + options "yunion.io/x/onecloud/pkg/mcclient/options/cloudproxy" +) + +func init() { + cmd := shell.NewResourceCmd(&modules.Forwards) + cmd = cmd.WithKeyword("proxy-forward") + cmd.Create(&options.ForwardCreateOptions{}) + cmd.PerformClass("create-from-server", &options.ForwardCreateFromServerOptions{}) + cmd.Perform("heartbeat", &options.ForwardHeartbeatOptions{}) + cmd.Update(&options.ForwardUpdateOptions{}) + cmd.List(&options.ForwardListOptions{}) + cmd.Show(&options.ForwardShowOptions{}) + cmd.Delete(&options.ForwardDeleteOptions{}) +} diff --git a/cmd/climc/shell/cloudproxy/proxy_agents.go b/cmd/climc/shell/cloudproxy/proxy_agents.go new file mode 100644 index 0000000000..3ec8b56f09 --- /dev/null +++ b/cmd/climc/shell/cloudproxy/proxy_agents.go @@ -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 cloudproxy + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" + options "yunion.io/x/onecloud/pkg/mcclient/options/cloudproxy" +) + +func init() { + cmd := shell.NewResourceCmd(&modules.ProxyAgents) + cmd = cmd.WithKeyword("proxy-agent") + cmd.Create(&options.ProxyAgentCreateOptions{}) + cmd.Update(&options.ProxyAgentUpdateOptions{}) + cmd.List(&options.ProxyAgentListOptions{}) + cmd.Show(&options.ProxyAgentShowOptions{}) + cmd.Delete(&options.ProxyAgentDeleteOptions{}) +} diff --git a/cmd/climc/shell/cloudproxy/proxy_endpoints.go b/cmd/climc/shell/cloudproxy/proxy_endpoints.go new file mode 100644 index 0000000000..033d425a13 --- /dev/null +++ b/cmd/climc/shell/cloudproxy/proxy_endpoints.go @@ -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 cloudproxy + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" + options "yunion.io/x/onecloud/pkg/mcclient/options/cloudproxy" +) + +func init() { + cmd := shell.NewResourceCmd(&modules.ProxyEndpoints) + cmd = cmd.WithKeyword("proxy-endpoint") + cmd.Create(&options.ProxyEndpointCreateOptions{}) + cmd.PerformClass("create-from-server", &options.ProxyEndpointCreateFromServerOptions{}) + cmd.Update(&options.ProxyEndpointUpdateOptions{}) + cmd.List(&options.ProxyEndpointListOptions{}) + cmd.Show(&options.ProxyEndpointShowOptions{}) + cmd.Delete(&options.ProxyEndpointDeleteOptions{}) +} diff --git a/cmd/climc/shell/cloudproxy/proxy_matches.go b/cmd/climc/shell/cloudproxy/proxy_matches.go new file mode 100644 index 0000000000..2290839f0c --- /dev/null +++ b/cmd/climc/shell/cloudproxy/proxy_matches.go @@ -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 cloudproxy + +import ( + "yunion.io/x/onecloud/cmd/climc/shell" + modules "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" + options "yunion.io/x/onecloud/pkg/mcclient/options/cloudproxy" +) + +func init() { + cmd := shell.NewResourceCmd(&modules.ProxyMatches) + cmd = cmd.WithKeyword("proxy-match") + cmd.Create(&options.ProxyMatchCreateOptions{}) + cmd.Update(&options.ProxyMatchUpdateOptions{}) + cmd.List(&options.ProxyMatchListOptions{}) + cmd.Show(&options.ProxyMatchShowOptions{}) + cmd.Delete(&options.ProxyMatchDeleteOptions{}) +} diff --git a/pkg/mcclient/modules/cloudproxy/common.go b/pkg/mcclient/modules/cloudproxy/common.go new file mode 100644 index 0000000000..1a1b4dc478 --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/common.go @@ -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 cloudproxy + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) + +func NewCloudProxyManager(keyword, keywordPlural string, columns, adminColumns []string) modulebase.ResourceManager { + return modulebase.ResourceManager{ + BaseManager: *modulebase.NewBaseManager("cloudproxy", "", "", columns, adminColumns), + Keyword: keyword, KeywordPlural: keywordPlural} +} + +var ( + registerV2 = func(mod modulebase.IBaseManager) { + modulebase.Register("v2", mod) + } +) diff --git a/pkg/mcclient/modules/cloudproxy/doc.go b/pkg/mcclient/modules/cloudproxy/doc.go new file mode 100644 index 0000000000..3f23f9c228 --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/doc.go @@ -0,0 +1,15 @@ +// 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 cloudproxy // import "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy" diff --git a/pkg/mcclient/modules/cloudproxy/mod_cloudmatches.go b/pkg/mcclient/modules/cloudproxy/mod_cloudmatches.go new file mode 100644 index 0000000000..91ab3d7a4d --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/mod_cloudmatches.go @@ -0,0 +1,45 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) + +type ProxyMatchManager struct { + modulebase.ResourceManager +} + +var ( + ProxyMatches ProxyMatchManager +) + +func init() { + ProxyMatches = ProxyMatchManager{ + NewCloudProxyManager( + "proxy_match", + "proxy_matches", + []string{ + "id", + "name", + "proxy_endpoint_id", + "match_scope", + "match_value", + }, + []string{"tenant"}, + ), + } + registerV2(&ProxyMatches) +} diff --git a/pkg/mcclient/modules/cloudproxy/mod_forwards.go b/pkg/mcclient/modules/cloudproxy/mod_forwards.go new file mode 100644 index 0000000000..cd8e8e9cd6 --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/mod_forwards.go @@ -0,0 +1,52 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) + +type ForwardManager struct { + modulebase.ResourceManager +} + +var ( + Forwards ForwardManager +) + +func init() { + Forwards = ForwardManager{ + NewCloudProxyManager( + "forward", + "forwards", + []string{ + "id", + "name", + "type", + "remote_addr", + "remote_port", + "bind_port", + "last_seen", + }, + []string{ + "proxy_endpoint_id", + "proxy_agent_id", + "bind_port_req", + "tenant", + }, + ), + } + registerV2(&Forwards) +} diff --git a/pkg/mcclient/modules/cloudproxy/mod_proxyagents.go b/pkg/mcclient/modules/cloudproxy/mod_proxyagents.go new file mode 100644 index 0000000000..f5c7fd9809 --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/mod_proxyagents.go @@ -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 cloudproxy + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) + +type ProxyAgentManager struct { + modulebase.ResourceManager +} + +var ( + ProxyAgents ProxyAgentManager +) + +func init() { + ProxyAgents = ProxyAgentManager{ + NewCloudProxyManager( + "proxy_agent", + "proxy_agents", + []string{ + "id", + "name", + "bind_addr", + "advertise_addr", + }, + []string{}, + ), + } + registerV2(&ProxyAgents) +} diff --git a/pkg/mcclient/modules/cloudproxy/mod_proxyendpoints.go b/pkg/mcclient/modules/cloudproxy/mod_proxyendpoints.go new file mode 100644 index 0000000000..5008c00721 --- /dev/null +++ b/pkg/mcclient/modules/cloudproxy/mod_proxyendpoints.go @@ -0,0 +1,45 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/onecloud/pkg/mcclient/modulebase" +) + +type ProxyEndpointManager struct { + modulebase.ResourceManager +} + +var ( + ProxyEndpoints ProxyEndpointManager +) + +func init() { + ProxyEndpoints = ProxyEndpointManager{ + NewCloudProxyManager( + "proxy_endpoint", + "proxy_endpoints", + []string{ + "id", + "name", + "user", + "host", + "port", + }, + []string{"tenant"}, + ), + } + registerV2(&ProxyEndpoints) +} diff --git a/pkg/mcclient/options/base.go b/pkg/mcclient/options/base.go index 3a8d3ebd41..4e697e3a57 100644 --- a/pkg/mcclient/options/base.go +++ b/pkg/mcclient/options/base.go @@ -371,7 +371,7 @@ func (opts *BasePublicOptions) Params() (jsonutils.JSONObject, error) { } type BaseCreateOptions struct { - NAME string `help:"Resource Name"` + NAME string `json:"name" help:"Resource Name"` Desc string `metavar:"" help:"Description" json:"description"` } diff --git a/pkg/mcclient/options/cloudproxy/doc.go b/pkg/mcclient/options/cloudproxy/doc.go new file mode 100644 index 0000000000..1a4ddbe09d --- /dev/null +++ b/pkg/mcclient/options/cloudproxy/doc.go @@ -0,0 +1,15 @@ +// 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 cloudproxy // import "yunion.io/x/onecloud/pkg/mcclient/options/cloudproxy" diff --git a/pkg/mcclient/options/cloudproxy/forwards.go b/pkg/mcclient/options/cloudproxy/forwards.go new file mode 100644 index 0000000000..16ea9fb45d --- /dev/null +++ b/pkg/mcclient/options/cloudproxy/forwards.go @@ -0,0 +1,120 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type ForwardCreateOptions struct { + NAME string + + ProxyEndpointId string `required:"true"` + ProxyAgentId string + BindPortReq *int + + Type string `choices:"local|remote" required:"true"` + RemoteAddr string `required:"true"` + RemotePort int `required:"true"` + + LastSeenTimeout int `json:",omitzero"` + + Opaque string +} + +func (o *ForwardCreateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +type ForwardCreateFromServerOptions struct { + ServerId string `required:"true"` + + Type string `choices:"local|remote" required:"true"` + BindPortReq int `json:",omitzero"` + RemotePort string `required:"true"` + + LastSeenTimeout int `json:",omitzero"` + + Opaque string +} + +func (opts *ForwardCreateFromServerOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(opts) +} + +type ForwardHeartbeatOptions struct { + ID string `json:"-"` +} + +func (o *ForwardHeartbeatOptions) GetId() string { + return o.ID +} + +func (o *ForwardHeartbeatOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +type ForwardShowOptions struct { + options.BaseShowOptions +} + +type ForwardUpdateOptions struct { + ID string `json:"-"` + Name string + + ProxyEndpointId string + ProxyAgentId string + + Type string `choices:"local|remote"` + RemoteAddr string + RemotePortReq *int + BindPortReq *int + + LastSeenTimeout int `json:",omitzero"` + + Opaque string +} + +func (o *ForwardUpdateOptions) GetId() string { + return o.ID +} + +func (o *ForwardUpdateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +type ForwardDeleteOptions struct { + options.BaseIdOptions +} + +type ForwardListOptions struct { + options.BaseListOptions + + ProxyEndpointId string + ProxyAgentId string + + Type string `choices:"local|remote"` + RemoteAddr string + RemotePort *int + BindPortReq *int + + Opaque string +} + +func (o *ForwardListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} diff --git a/pkg/mcclient/options/cloudproxy/proxy_agents.go b/pkg/mcclient/options/cloudproxy/proxy_agents.go new file mode 100644 index 0000000000..ed593c78dd --- /dev/null +++ b/pkg/mcclient/options/cloudproxy/proxy_agents.go @@ -0,0 +1,67 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type ProxyAgentCreateOptions struct { + NAME string + + BindAddr string `json:"bind_addr"` + AdvertiseAddr string `json:"advertise_addr"` +} + +func (o *ProxyAgentCreateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +type ProxyAgentShowOptions struct { + options.BaseShowOptions +} + +type ProxyAgentUpdateOptions struct { + ID string `help:"ID or Name of resource to update"` + Name string `help:"Name of resource to update"` + + BindAddr string `json:"bind_addr"` + AdvertiseAddr string `json:"advertise_addr"` +} + +func (o *ProxyAgentUpdateOptions) GetId() string { + return o.ID +} + +func (o *ProxyAgentUpdateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(o) +} + +type ProxyAgentDeleteOptions struct { + options.BaseIdOptions +} + +type ProxyAgentListOptions struct { + options.BaseListOptions + + BindAddr string `json:"bind_addr"` + AdvertiseAddr string `json:"advertise_addr"` +} + +func (o *ProxyAgentListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} diff --git a/pkg/mcclient/options/cloudproxy/proxy_endpoints.go b/pkg/mcclient/options/cloudproxy/proxy_endpoints.go new file mode 100644 index 0000000000..c6e5c13035 --- /dev/null +++ b/pkg/mcclient/options/cloudproxy/proxy_endpoints.go @@ -0,0 +1,109 @@ +// 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 cloudproxy + +import ( + "io/ioutil" + + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type ProxyEndpointCreateOptions struct { + NAME string + + User string + Host string + Port int `json:",omitzero"` + PrivateKey string + + IntranetIpAddr string `required:"true"` +} + +func (opts *ProxyEndpointCreateOptions) Params() (jsonutils.JSONObject, error) { + params, err := options.StructToParams(opts) + if err != nil { + return nil, err + } + if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' { + data, err := ioutil.ReadFile(opts.PrivateKey[1:]) + if err != nil { + return nil, err + } + params.Set("private_key", jsonutils.NewString(string(data))) + } + return params, nil +} + +type ProxyEndpointCreateFromServerOptions struct { + ServerId string `required:"true"` +} + +func (opts *ProxyEndpointCreateFromServerOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(opts) +} + +type ProxyEndpointShowOptions struct { + options.BaseShowOptions +} + +type ProxyEndpointUpdateOptions struct { + ID string `json:"-"` + Name string + + User string + Host string + Port int `json:",omitzero"` + PrivateKey string +} + +func (opts *ProxyEndpointUpdateOptions) GetId() string { + return opts.ID +} + +func (opts *ProxyEndpointUpdateOptions) Params() (jsonutils.JSONObject, error) { + params, err := options.StructToParams(opts) + if err != nil { + return nil, err + } + if opts.PrivateKey != "" && opts.PrivateKey[0] == '@' { + data, err := ioutil.ReadFile(opts.PrivateKey[1:]) + if err != nil { + return nil, err + } + params.Set("private_key", jsonutils.NewString(string(data))) + } + return params, nil +} + +type ProxyEndpointDeleteOptions struct { + options.BaseShowOptions +} + +type ProxyEndpointListOptions struct { + options.BaseListOptions + + //User string + Host string + Port int `json:",omitzero"` + + VpcId string + NetworkId string +} + +func (opts *ProxyEndpointListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(opts) +} diff --git a/pkg/mcclient/options/cloudproxy/proxy_matches.go b/pkg/mcclient/options/cloudproxy/proxy_matches.go new file mode 100644 index 0000000000..2a278cdc20 --- /dev/null +++ b/pkg/mcclient/options/cloudproxy/proxy_matches.go @@ -0,0 +1,70 @@ +// 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 cloudproxy + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type ProxyMatchCreateOptions struct { + NAME string + + ProxyEndpointId string `required:"true"` + MatchScope string `required:"true" choices:"vpc|network"` + MatchValue string `required:"true"` +} + +func (opts *ProxyMatchCreateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(opts) +} + +type ProxyMatchShowOptions struct { + options.BaseShowOptions +} + +type ProxyMatchUpdateOptions struct { + ID string `json:"-"` + Name string + + ProxyEndpointId string + MatchScope string `choices:"vpc|network"` + MatchValue string +} + +func (opts *ProxyMatchUpdateOptions) GetId() string { + return opts.ID +} + +func (opts *ProxyMatchUpdateOptions) Params() (jsonutils.JSONObject, error) { + return options.StructToParams(opts) +} + +type ProxyMatchDeleteOptions struct { + options.BaseShowOptions +} + +type ProxyMatchListOptions struct { + options.BaseListOptions + + ProxyEndpointId string + MatchScope string `choices:"vpc|network"` + MatchValue string +} + +func (opts *ProxyMatchListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(opts) +}