Tag representation.
All the tags associated with the UpCloud account are available via the Tags API. Tags associated with an individual server are seen in the Server.tags property.
Tags can be created by first using the Builder API, and then passing the tag to the Resource creation API.
The only required property is the name property. Existing servers can be tagged at the same time.
import static fi.linuxbox.upcloud.resource.Builder.tag
def dev = tag {
name = 'DEV'
description = 'Development servers'
servers = [
existingServer.uuid
]
}
upcloud.create dev, { resp, err ->
...
}
Tags can be modified by first using the Builder API, and then passing the tag to the Tag update API.
The only required property is the name property. Existing servers can be tagged at the same time.
import fi.linuxbox.upcloud.api.Tag
import static fi.linuxbox.upcloud.resource.Builder.tag
def prod = tag {
name = 'PROD'
description = 'Production servers'
}
def tagApi = dev.withTraits(Tag)
tagApi.update prod, { resp, err ->
...
}
Tags must be deleted one by one using the Tag delete API. Deleting a tag will automatically remove that tag from any servers.
import fi.linuxbox.upcloud.api.Tag
import static fi.linuxbox.upcloud.resource.Builder.tag
def prod = tag SESSION: session, {
name = 'PROD'
}
def tagApi = prod.withTraits(Tag)
tagApi.delete { resp, err ->
...
}
Deleting all the tags requires first listing the tags and then deleting them one by one (but concurrently).
import java.util.concurrent.CompletableFuture
import fi.linuxbox.upcloud.api.Tag
def tagsDeleted = new CompletableFuture()
upcloud.tags { resp ->
def tagDeletions = resp.tags.collect { tag ->
tag.withTraits(Tag).delete {}
}
CompletableFuture.allOf(*tagDeletions).thenRun {
tagsDeleted.complete(null)
}
}
tagsDeleted.thenRun {
close()
}
A special case of tag modification is adding one or more tags to one server. This can be done like shown above, adding the server to one tag at a time. But more efficient way is to use the Server tagging API. Similarly, removing tags from one server can be done using the Server untagging API.
Fields inherited from class | Fields |
---|---|
class Resource |
__$stMC |
Methods inherited from class | Name |
---|---|
class Resource |
setProperty, getProperty, toString, asType, getMetaClass, setMetaClass, wrapper, propertyMissing, propertyMissing, methodMissing, proj, invokeMethod, this$dist$invoke$1, this$dist$set$1, this$dist$get$1, super$1$toString, getHTTP, getSESSION, getMETA, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Description of the tag: max 255 characters.
This is available in the tag listing, and can optionally be specified when creating or modifying a tag.
Unique name of the tag: 1-32 characters A-Z
, a-z
, 0-9
, _
.
This is available in the tag listing, and must be specified when creating a tag. When modifying a tag, this is optional and allows renaming.