From 675fe334ff3e86fdebb4b6928cc298c46b98e369 Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 22 Apr 2021 16:51:48 +0800 Subject: [PATCH] cloudproxy: proxy_endpoints: create-from-server: allow name as arg --- pkg/apis/cloudproxy/proxy_endpoints.go | 2 ++ pkg/cloudproxy/models/proxy_endpoints.go | 10 +++++++++- pkg/mcclient/options/cloudproxy/proxy_endpoints.go | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/apis/cloudproxy/proxy_endpoints.go b/pkg/apis/cloudproxy/proxy_endpoints.go index 3371219d8a..ae5a35cf3d 100644 --- a/pkg/apis/cloudproxy/proxy_endpoints.go +++ b/pkg/apis/cloudproxy/proxy_endpoints.go @@ -30,6 +30,8 @@ type ProxyEndpointCreateInput struct { } type ProxyEndpointCreateFromServerInput struct { + Name string + ServerId string } diff --git a/pkg/cloudproxy/models/proxy_endpoints.go b/pkg/cloudproxy/models/proxy_endpoints.go index 2ab76710fa..445dfaf7a7 100644 --- a/pkg/cloudproxy/models/proxy_endpoints.go +++ b/pkg/cloudproxy/models/proxy_endpoints.go @@ -93,6 +93,14 @@ func (man *SProxyEndpointManager) PerformCreateFromServer(ctx context.Context, u return nil, httperrors.NewBadRequestError("cannot find ssh host ip address for this server") } + name := input.Name + if name == "" { + name = serverInfo.Server.Name + } + if err := db.NewNameValidator(man, userCred, name, nil); err != nil { + return nil, httperrors.NewGeneralError(err) + } + proxyendpoint := &SProxyEndpoint{ User: "cloudroot", Host: host, @@ -101,7 +109,7 @@ func (man *SProxyEndpointManager) PerformCreateFromServer(ctx context.Context, u IntranetIpAddr: nic.IpAddr, } - proxyendpoint.Name = serverInfo.Server.Name + proxyendpoint.Name = name proxyendpoint.DomainId = userCred.GetProjectDomainId() proxyendpoint.ProjectId = userCred.GetProjectId() if err := man.TableSpec().Insert(ctx, proxyendpoint); err != nil { diff --git a/pkg/mcclient/options/cloudproxy/proxy_endpoints.go b/pkg/mcclient/options/cloudproxy/proxy_endpoints.go index c6e5c13035..c8c026b386 100644 --- a/pkg/mcclient/options/cloudproxy/proxy_endpoints.go +++ b/pkg/mcclient/options/cloudproxy/proxy_endpoints.go @@ -49,6 +49,8 @@ func (opts *ProxyEndpointCreateOptions) Params() (jsonutils.JSONObject, error) { } type ProxyEndpointCreateFromServerOptions struct { + Name string + ServerId string `required:"true"` }