govrealize

package module
v0.0.0-...-7c635a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2017 License: BSD-3-Clause Imports: 11 Imported by: 0

README

govrealize

A Go library for interacting with vRealize Automation 6.2 REST API

Introduction

govrealize is a Golang client library for interacting with the vRealize REST API detailed here: https://developercenter.vmware.com/web/sdk/6.2.0/vrealize-automation. Currently only the creation, reading and deletion of machines is implemented.

Usage

Create a vRealize client

client := m.(*govrealize.Client)

Create a machine

entries := []govrealize.MachineRequestDataEntry{}

mrde := govrealize.MachineRequestDataEntry{
	Key: key,
	Value: govrealize.MachineRequestDataEntryValue{
		Type:  "string",
		Value: "value",
	},
}
entries = append(entries, mrde)

opts := &govrealize.MachineCreateRequest{
  Type: "CatalogItemRequest",
	CatalogItemRef: govrealize.MachineCreateRequestCatalogItemRef{
		ID: "xxxx-xxxxx-xxxxx-xxxx",
	},
	Organization: govrealize.MachineCreateRequestOrganization{
		TenantRef:    "tenant",
		SubtenantRef: "subtenant",
	},
	State:         "SUBMITTED",
	RequestNumber: 0,
	RequestData: govrealize.MachineCreateRequestRequestData{
		Entries: entries,
	},
}

machine, resp, err := client.Machine.CreateMachine(opts)

Get a machine

machine, resp, err := client.Machine.GetMachine("xxxx-xxxx-xxxx-xxxx")

Destroy a machine

destroyed, resp, err := client.Machine.DestroyMachine("xxxx-xxxx-xxxx-xxxx")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it, but unlike Int32 its argument value is an int.

func StreamToString

func StreamToString(stream io.Reader) string

StreamToString converts a reader to a string

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// Username for client
	Username string

	// Password for client
	Password string

	// Tenant for client
	Tenant string

	// Services used for communicating with the API
	Machine MachineService
	// contains filtered or unexported fields
}

Client manages communication with the vRealize API 6.2

func New

func New(httpClient *http.Client, opts ...ClientOpt) (*Client, error)

New returns a new vRealize API client instance.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new vRealize API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

func (*Client) OnRequestCompleted

func (c *Client) OnRequestCompleted(rc RequestCompletionCallback)

OnRequestCompleted sets the DO API request completion callback

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New.

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL.

func SetPassword

func SetPassword(password string) ClientOpt

SetPassword is a client option for setting the Password.

func SetTenant

func SetTenant(tenant string) ClientOpt

SetTenant is a client option for setting the Tenant.

func SetUsername

func SetUsername(username string) ClientOpt

SetUsername is a client option for setting the Username.

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	Errors []ErrorResponseError `json:"errors"`
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ErrorResponseError

type ErrorResponseError struct {
	Code          int         `json:"code"`
	Message       string      `json:"message"`
	SystemMessage string      `json:"systemMessage"`
	MoreInfoURL   interface{} `json:"moreInfoUrl"`
}

ErrorResponseError represents an API error

type Link struct {
	Type string `json:"@type"`
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

Link is a representation of a link

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	Limit int `url:"limit,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type Machine

type Machine struct {
	ID string `json:"id"`
	// IconID          string `json:"iconId"`
	ResourceTypeRef MachineResourceTypeRef `json:"resourceTypeRef"`
	Name            string                 `json:"name"`
	Description     string                 `json:"description"`
	Status          string                 `json:"status"`
	CatalogItem     MachineCatalogItem     `json:"catalogItem"`
	RequestID       string                 `json:"requestId"`
	// ProviderBinding struct {
	// 	BindingID   string `json:"bindingId"`
	// 	ProviderRef struct {
	// 		ID    string `json:"id"`
	// 		Label string `json:"label"`
	// 	} `json:"providerRef"`
	// } `json:"providerBinding"`
	// Owners []struct {
	// 	TenantName string `json:"tenantName"`
	// 	Ref        string `json:"ref"`
	// 	Type       string `json:"type"`
	// 	Value      string `json:"value"`
	// } `json:"owners"`
	Organization MachineOrganization `json:"organization"`
	DateCreated  time.Time           `json:"dateCreated"`
	LastUpdated  time.Time           `json:"lastUpdated"`
	HasLease     bool                `json:"hasLease"`
	// Lease       struct {
	// 	Start time.Time `json:"start"`
	// } `json:"lease"`
	LeaseForDisplay interface{} `json:"leaseForDisplay"`
	// HasCosts        bool        `json:"hasCosts"`
	// Costs           struct {
	// 	LeaseRate struct {
	// 		Type string `json:"type"`
	// 		Cost struct {
	// 			Type         string  `json:"type"`
	// 			CurrencyCode string  `json:"currencyCode"`
	// 			Amount       float64 `json:"amount"`
	// 		} `json:"cost"`
	// 		Basis struct {
	// 			Type   string `json:"type"`
	// 			Unit   string `json:"unit"`
	// 			Amount int    `json:"amount"`
	// 		} `json:"basis"`
	// 	} `json:"leaseRate"`
	// } `json:"costs"`
	// CostToDate struct {
	// 	Type         string  `json:"type"`
	// 	CurrencyCode string  `json:"currencyCode"`
	// 	Amount       float64 `json:"amount"`
	// } `json:"costToDate"`
	// TotalCost      interface{}   `json:"totalCost"`
	// ChildResources []interface{} `json:"childResources"`
	Operations []MachineOperation `json:"operations"`
	// Forms struct {
	// 	CatalogResourceInfoHidden bool `json:"catalogResourceInfoHidden"`
	// 	Details                   struct {
	// 		Type             string      `json:"type"`
	// 		ExtensionID      string      `json:"extensionId"`
	// 		ExtensionPointID interface{} `json:"extensionPointId"`
	// 	} `json:"details"`
	// } `json:"forms"`
	ResourceData MachineResourceData `json:"resourceData"`
}

Machine represents a vRealize machine. Commented properties left to be implmented in future.

func (Machine) DestroyActionID

func (m Machine) DestroyActionID() string

DestroyActionID returns the ID of the Destroy action

func (Machine) IPAddress

func (m Machine) IPAddress() string

IPAddress returns the IP Address of the machine

func (Machine) MachineName

func (m Machine) MachineName() string

MachineName returns the name of the machine

func (Machine) ReconfigureActionID

func (m Machine) ReconfigureActionID() string

ReconfigureActionID returns the ID of the Reconfigure action

type MachineCatalogItem

type MachineCatalogItem struct {
	ID string `json:"id"`
}

MachineCatalogItem represents a catalogueItem

type MachineCreateRequest

type MachineCreateRequest struct {
	Type           string                             `json:"@type"`
	CatalogItemRef MachineCreateRequestCatalogItemRef `json:"catalogItemRef"`
	Organization   MachineCreateRequestOrganization   `json:"organization"`
	State          string                             `json:"state"`
	RequestNumber  int                                `json:"requestNumber"`
	RequestData    MachineCreateRequestRequestData    `json:"requestData"`
}

MachineCreateRequest represents a request to create a machine

type MachineCreateRequestCatalogItemRef

type MachineCreateRequestCatalogItemRef struct {
	ID string `json:"id"`
}

MachineCreateRequestCatalogItemRef represents a catalogItemRef

type MachineCreateRequestOrganization

type MachineCreateRequestOrganization struct {
	TenantRef    string `json:"tenantRef"`
	SubtenantRef string `json:"subtenantRef"`
}

MachineCreateRequestOrganization represents an organization

type MachineCreateRequestRequestData

type MachineCreateRequestRequestData struct {
	Entries []MachineRequestDataEntry `json:"entries"`
}

MachineCreateRequestRequestData represents a requestData

type MachineCreateResponse

type MachineCreateResponse struct {
	Location url.URL
}

MachineCreateResponse represents a response to a request to create a machine

func (MachineCreateResponse) String

func (mcr MachineCreateResponse) String() string

type MachineDataEntry

type MachineDataEntry struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

MachineDataEntry represents a dataEntry

type MachineOperation

type MachineOperation struct {
	Name           string      `json:"name"`
	Description    string      `json:"description"`
	IconID         string      `json:"iconId"`
	Type           string      `json:"type"`
	ID             string      `json:"id"`
	ExtensionID    string      `json:"extensionId"`
	ProviderTypeID interface{} `json:"providerTypeId"`
	BindingID      interface{} `json:"bindingId"`
	HasForm        bool        `json:"hasForm"`
	FormScale      interface{} `json:"formScale"`
}

MachineOperation represents an operation

type MachineOrganization

type MachineOrganization struct {
	TenantRef    string `json:"tenantRef"`
	SubtenantRef string `json:"subtenantRef"`
}

MachineOrganization represents an organization

type MachineRequestDataEntry

type MachineRequestDataEntry struct {
	Key   string                       `json:"key"`
	Value MachineRequestDataEntryValue `json:"value"`
}

MachineRequestDataEntry represents a requestDataEntry

type MachineRequestDataEntryValue

type MachineRequestDataEntryValue struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

MachineRequestDataEntryValue represents a dataEntryValue

type MachineResourceData

type MachineResourceData struct {
	Entries []MachineDataEntry `json:"entries"`
}

MachineResourceData represents resourceData

type MachineResourceTypeRef

type MachineResourceTypeRef struct {
	ID    string `json:"id"`
	Label string `json:"label"`
}

MachineResourceTypeRef represents a resourceTypeRef

type MachineService

type MachineService interface {
	ListMachines(*ListOptions) ([]Machine, *Response, error)
	GetMachine(string) (*Machine, *Response, error)
	CreateMachine(*MachineCreateRequest) (*Machine, *Response, error)
	DestroyMachine(string) (bool, *Response, error)
}

MachineService is an interface for interfacing with the storage endpoints of the vRealize API.

type MachineServiceOp

type MachineServiceOp struct {
	// contains filtered or unexported fields
}

MachineServiceOp handles communication with the machines related methods of the vRealize API.

func (*MachineServiceOp) CreateMachine

func (svc *MachineServiceOp) CreateMachine(createRequest *MachineCreateRequest) (*Machine, *Response, error)

CreateMachine creates a machine.

func (*MachineServiceOp) DestroyMachine

func (svc *MachineServiceOp) DestroyMachine(id string) (bool, *Response, error)

DestroyMachine Destroys a machine.

func (*MachineServiceOp) GetMachine

func (svc *MachineServiceOp) GetMachine(id string) (*Machine, *Response, error)

GetMachine retrieves an individual machine.

func (*MachineServiceOp) ListMachines

func (svc *MachineServiceOp) ListMachines(opt *ListOptions) ([]Machine, *Response, error)

ListMachines lists all machines.

type RequestCompletionCallback

type RequestCompletionCallback func(*http.Request, *http.Response)

RequestCompletionCallback defines the type of the request callback function

type Response

type Response struct {
	*http.Response

	Links []Link
}

Response is a vRealize response. This wraps the standard http.Response returned from vRealize.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL