migrate to integer ID
This commit is contained in:
parent
ffb356182e
commit
7ff2a92118
4 changed files with 27 additions and 22 deletions
14
server.go
14
server.go
|
|
@ -13,7 +13,7 @@ import (
|
|||
var ErrServerNotFound = errors.New("server not found")
|
||||
|
||||
type Server struct {
|
||||
ID string `json:"vmid"`
|
||||
ID int `json:"vmid"`
|
||||
Name string `json:"name"`
|
||||
Node string
|
||||
Pool string
|
||||
|
|
@ -29,7 +29,7 @@ type Server struct {
|
|||
}
|
||||
|
||||
func (s *Server) UserDataSnippetName() string {
|
||||
return fmt.Sprintf("%s_userdata", s.ID)
|
||||
return fmt.Sprintf("%d_userdata", s.ID)
|
||||
}
|
||||
|
||||
func (s *Server) UserDataSnippet(storage string) string {
|
||||
|
|
@ -84,7 +84,7 @@ func (s *Server) Ref() *ServerRef {
|
|||
type ServerRefList []*ServerRef
|
||||
|
||||
type ServerRef struct {
|
||||
ID string `json:"vmid"`
|
||||
ID int `json:"vmid"`
|
||||
Name string `json:"name"`
|
||||
Node string
|
||||
Pool string
|
||||
|
|
@ -220,7 +220,7 @@ type ServerClient struct {
|
|||
client *Client
|
||||
}
|
||||
|
||||
func (c *ServerClient) NextID(ctx context.Context) (id string, err error) {
|
||||
func (c *ServerClient) NextID(ctx context.Context) (id int, err error) {
|
||||
req, err := c.client.NewRequest(ctx, "GET", "/cluster/nextid", nil)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -285,7 +285,7 @@ func (c *ServerClient) GetByURL(ctx context.Context, url string) (s *Server, err
|
|||
|
||||
type ServerTemplateOpts struct {
|
||||
Name string
|
||||
TemplateID string
|
||||
TemplateID int
|
||||
// TemplateNode is optional
|
||||
TemplateNode string
|
||||
Pool string
|
||||
|
|
@ -297,7 +297,7 @@ func (o *ServerTemplateOpts) Validate(ctx context.Context, c *Client) error {
|
|||
if o.Name == "" {
|
||||
return errors.New("missing name")
|
||||
}
|
||||
if o.TemplateID == "" {
|
||||
if o.TemplateID <= 0 {
|
||||
return errors.New("missing template id")
|
||||
}
|
||||
if o.TemplateNode == "" {
|
||||
|
|
@ -335,7 +335,7 @@ func (c *ServerClient) CreateFromTemplate(ctx context.Context, opts *ServerTempl
|
|||
return
|
||||
}
|
||||
body := opts.body()
|
||||
body["newid"] = nextid
|
||||
body["newid"] = strconv.Itoa(nextid)
|
||||
node := opts.TemplateNode
|
||||
if opts.TargetNode != "" && opts.TemplateNode != opts.TargetNode {
|
||||
node = opts.TargetNode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue