56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/UpCloudLtd/upcloud-go-api/upcloud"
|
|
"github.com/UpCloudLtd/upcloud-go-api/upcloud/request"
|
|
"github.com/UpCloudLtd/upcloud-go-api/upcloud/service"
|
|
)
|
|
|
|
func infoTagsFromId(s *service.Service, id string) (upcloud.TagServerSlice,error) {
|
|
var upTags upcloud.TagServerSlice
|
|
if id == "" {
|
|
fmt.Fprintf(os.Stderr, "Resouce not found to get tags\n")
|
|
return upTags,nil
|
|
}
|
|
info, err := s.GetServerDetails(&request.GetServerDetailsRequest{
|
|
UUID: id,
|
|
})
|
|
for _, tag := range info.Tags {
|
|
upTags = append(upTags, tag)
|
|
}
|
|
return upTags, err
|
|
}
|
|
func addTagsToId(s *service.Service, id string, tags []string) error {
|
|
if id == "" || len(tags) == 0 {
|
|
fmt.Fprintf(os.Stderr, "Resouce not found to add tags to (%s)\n",id)
|
|
return nil
|
|
}
|
|
var upTags upcloud.TagServerSlice
|
|
for i := 0; i < len(tags); i++ {
|
|
upTags = append(upTags,tags[i])
|
|
}
|
|
_, err := s.TagServer(&request.TagServerRequest{
|
|
UUID: id,
|
|
Tags: upTags,
|
|
})
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Unable to tag server %s: %#v", id, err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
func deleteTagsFromId(s *service.Service, id string, tags []string) error {
|
|
if id == "" || len(tags) == 0 {
|
|
fmt.Fprintf(os.Stderr, "Resouce not found to get tags (%s)\n",id)
|
|
return nil
|
|
}
|
|
_, err := s.UntagServer(&request.UntagServerRequest{
|
|
UUID: id,
|
|
Tags: tags,
|
|
})
|
|
// fmt.Printf("Delete Tag form server: %#v\n", msg)
|
|
return err
|
|
} |