added search for template node
This commit is contained in:
parent
78911eca56
commit
3c9a99682e
1 changed files with 13 additions and 5 deletions
18
server.go
18
server.go
|
|
@ -290,15 +290,16 @@ func (c *ServerClient) GetByURL(ctx context.Context, url string) (s *Server, err
|
|||
}
|
||||
|
||||
type ServerTemplateOpts struct {
|
||||
Name string
|
||||
TemplateID string
|
||||
Name string
|
||||
TemplateID string
|
||||
// TemplateNode is optional
|
||||
TemplateNode string
|
||||
Pool string
|
||||
TargetStorage string
|
||||
TargetNode string
|
||||
}
|
||||
|
||||
func (o ServerTemplateOpts) Validate() error {
|
||||
func (o ServerTemplateOpts) Validate(ctx context.Context, c *Client) error {
|
||||
if o.Name == "" {
|
||||
return errors.New("missing name")
|
||||
}
|
||||
|
|
@ -306,7 +307,14 @@ func (o ServerTemplateOpts) Validate() error {
|
|||
return errors.New("missing template id")
|
||||
}
|
||||
if o.TemplateNode == "" {
|
||||
return errors.New("missing template node")
|
||||
ref, err := c.Node.FindServerByID(ctx, o.TemplateID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("template node not found err: %w", err)
|
||||
}
|
||||
if ref.Node == "" {
|
||||
return errors.New("missing template node")
|
||||
}
|
||||
o.TemplateNode = ref.Node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -324,7 +332,7 @@ func (o ServerTemplateOpts) body() httpbody {
|
|||
}
|
||||
|
||||
func (c *ServerClient) CreateFromTemplate(ctx context.Context, opts ServerTemplateOpts) (t *Task, url string, err error) {
|
||||
err = opts.Validate()
|
||||
err = opts.Validate(ctx, c.client)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue