cloudproxy: proxy_endpoints: create-from-server: allow name as arg

This commit is contained in:
Yousong Zhou
2021-04-22 16:51:48 +08:00
parent 56c3b704fc
commit 675fe334ff
3 changed files with 13 additions and 1 deletions

View File

@@ -30,6 +30,8 @@ type ProxyEndpointCreateInput struct {
}
type ProxyEndpointCreateFromServerInput struct {
Name string
ServerId string
}

View File

@@ -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 {

View File

@@ -49,6 +49,8 @@ func (opts *ProxyEndpointCreateOptions) Params() (jsonutils.JSONObject, error) {
}
type ProxyEndpointCreateFromServerOptions struct {
Name string
ServerId string `required:"true"`
}