Reusable instance configuration.
- List - List instance templates
- Create - Create instance template
- Fetch - Get instance template
- Delete - Delete instance template
List all instance templates.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.InstanceTemplates.List(ctx, operations.ListInstanceTemplatesRequest{
Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
ID: []string{
"ntmpl_k3R-nX9vLm7Qp2Yw5Jd8F",
},
StartingAfter: sfc.Pointer("itmplc_gqXR7s0Kj5mHvE2wNpLc4Q"),
EndingBefore: sfc.Pointer("itmplc_gqXR7s0Kj5mHvE2wNpLc4Q"),
})
if err != nil {
log.Fatal(err)
}
if res.ListInstanceTemplatesResponse != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
operations.ListInstanceTemplatesRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.ListInstanceTemplatesResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Create a reusable instance template.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"github.com/sfcompute/sfc-go/optionalnullable"
"github.com/sfcompute/sfc-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.InstanceTemplates.Create(ctx, components.CreateInstanceTemplateRequest{
Name: optionalnullable.From(sfc.Pointer("my-resource-name")),
Workspace: "wksp_k3R-nX9vLm7Qp2Yw5Jd8F",
Image: "image_k3R-nX9vLm7Qp2Yw5Jd8F",
CloudInitUserData: sfc.Pointer("IyEvYmluL2Jhc2gKZWNobyBoZWxsbyB3b3JsZAo="),
})
if err != nil {
log.Fatal(err)
}
if res.InstanceTemplateResponse != nil {
switch res.InstanceTemplateResponse.Image.Type {
case components.ExpandableImageIDImageSummaryUnionTypeStr:
// res.InstanceTemplateResponse.Image.Str is populated
case components.ExpandableImageIDImageSummaryUnionTypeExpandableImageIDImageSummary:
// res.InstanceTemplateResponse.Image.ExpandableImageIDImageSummary is populated
default:
// Unknown type - use res.InstanceTemplateResponse.Image.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.CreateInstanceTemplateRequest | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateInstanceTemplateResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Retrieve an instance template by ID or resource path.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
"github.com/sfcompute/sfc-go/models/components"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.InstanceTemplates.Fetch(ctx, "ntmpl_k3R-nX9vLm7Qp2Yw5Jd8F", nil)
if err != nil {
log.Fatal(err)
}
if res.InstanceTemplateResponse != nil {
switch res.InstanceTemplateResponse.Image.Type {
case components.ExpandableImageIDImageSummaryUnionTypeStr:
// res.InstanceTemplateResponse.Image.Str is populated
case components.ExpandableImageIDImageSummaryUnionTypeExpandableImageIDImageSummary:
// res.InstanceTemplateResponse.Image.ExpandableImageIDImageSummary is populated
default:
// Unknown type - use res.InstanceTemplateResponse.Image.GetUnknownRaw() for raw JSON
}
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | ntmpl_k3R-nX9vLm7Qp2Yw5Jd8F |
expand |
[]string |
➖ | N/A | |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FetchInstanceTemplateResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Delete an instance template. The template must not be in use by any capacity.
package main
import(
"context"
sfc "github.com/sfcompute/sfc-go"
"log"
)
func main() {
ctx := context.Background()
s := sfc.New(
sfc.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
res, err := s.InstanceTemplates.Delete(ctx, "ntmpl_k3R-nX9vLm7Qp2Yw5Jd8F")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. | |
id |
string |
✔️ | N/A | ntmpl_k3R-nX9vLm7Qp2Yw5Jd8F |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.DeleteInstanceTemplateResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.UnauthorizedError | 401 | application/json |
| apierrors.NotFoundError | 404 | application/json |
| apierrors.UnprocessableEntityError | 422 | application/json |
| apierrors.InternalServerError | 500 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |