Skip to content

Latest commit

 

History

History
274 lines (209 loc) · 15.1 KB

File metadata and controls

274 lines (209 loc) · 15.1 KB

InstanceTemplates

Overview

Reusable instance configuration.

Available Operations

  • List - List instance templates
  • Create - Create instance template
  • Fetch - Get instance template
  • Delete - Delete instance template

List

List all instance templates.

Example Usage

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
            }
        }
    }
}

Parameters

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.

Response

*operations.ListInstanceTemplatesResponse, error

Errors

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

Create a reusable instance template.

Example Usage

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
        }

    }
}

Parameters

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.

Response

*operations.CreateInstanceTemplateResponse, error

Errors

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 */*

Fetch

Retrieve an instance template by ID or resource path.

Example Usage

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
        }

    }
}

Parameters

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.

Response

*operations.FetchInstanceTemplateResponse, error

Errors

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

Delete an instance template. The template must not be in use by any capacity.

Example Usage

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
    }
}

Parameters

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.

Response

*operations.DeleteInstanceTemplateResponse, error

Errors

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 */*