sdk

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeHeader   = "Content-Type"
	AuthorizationHeader = "Authorization"
	ConnectionHeader    = "Connection"
	AcceptHeader        = "Accept"
	AppJSON             = "application/json"
	CloseConnection     = "close"
	GET                 = "GET"
	POST                = "POST"
	PATCH               = "PATCH"
	PUT                 = "PUT"
	DELETE              = "DELETE"
)

client constants

View Source
const (
	IdentityAPI                 = "/identity/api"
	Tokens                      = IdentityAPI + "/tokens"
	Tenants                     = IdentityAPI + "/tenants"
	CatalogService              = "/catalog-service"
	CatalogServiceAPI           = CatalogService + "/api"
	Consumer                    = CatalogServiceAPI + "/consumer"
	ConsumerRequests            = Consumer + "/requests"
	ConsumerResources           = Consumer + "/resources"
	EntitledCatalogItems        = Consumer + "/entitledCatalogItems"
	EntitledCatalogItemViewsAPI = Consumer + "/entitledCatalogItemViews"
	GetResourceAPI              = Consumer + "/resources/%s"
	GetRequestResourcesAPI      = ConsumerRequests + "/" + "%s" + "/resources"
	ResourceActions             = ConsumerResources + "/" + "%s" + "/actions"
	PostActionTemplateAPI       = ResourceActions + "/" + "%s" + "/requests"
	GetActionTemplateAPI        = PostActionTemplateAPI + "/template"
	GetRequestResourceViewAPI   = ConsumerRequests + "/" + "%s" + "/resourceViews"
	RequestTemplateAPI          = EntitledCatalogItems + "/" + "%s" + "/requests/template"

	InProgress             = "IN_PROGRESS"
	Successful             = "SUCCESSFUL"
	Failed                 = "FAILED"
	Submitted              = "SUBMITTED"
	InfrastructureVirtual  = "Infrastructure.Virtual"
	DeploymentResourceType = "composition.resource.type.deployment"
	Component              = "Component"
	Reconfigure            = "Reconfigure"
	Destroy                = "Destroy"
	ScaleOut               = "Scale Out"
	ScaleIn                = "Scale In"
	DeploymentDestroy      = "Deployment Destroy"
)

API constants

Variables

This section is empty.

Functions

func FromAPIRequestToHTTPRequest

func FromAPIRequestToHTTPRequest(apiReq *APIRequest) (*http.Request, error)

FromAPIRequestToHTTPRequest converts API request object to http request

func GetAPIError

func GetAPIError(respBody []byte, statusCode int) error

GetAPIError reads an error out of the HTTP response, or does nothing if no error occurred.

Types

type APIClient

type APIClient struct {
	Username    string
	Password    string
	BaseURL     string
	Tenant      string
	Insecure    bool
	BearerToken string
	Client      *http.Client
}

APIClient represents the vra http client used throughout this provider

func NewClient

func NewClient(user, password, tenant, baseURL string, insecure bool) APIClient

NewClient creates a new APIClient object

func (*APIClient) Authenticate

func (c *APIClient) Authenticate() error

Authenticate authenticates for the first time when the provider is invoked

func (*APIClient) BuildEncodedURL

func (c *APIClient) BuildEncodedURL(relativePath string, queryParameters map[string]string) string

BuildEncodedURL build the url by adding the base url and headers, etc

func (*APIClient) Delete

func (c *APIClient) Delete(url string, body io.Reader, headers map[string]string) (*APIResponse, error)

Delete HTTP DELETE method

func (*APIClient) DoLogin

func (c *APIClient) DoLogin(apiReq *APIRequest) error

DoLogin returns the bearer token

func (*APIClient) DoRequest

func (c *APIClient) DoRequest(req *APIRequest, login bool) (*APIResponse, error)

DoRequest makes the request and returns the response

func (*APIClient) Get

func (c *APIClient) Get(encodedURL string, headers map[string]string) (*APIResponse, error)

Get HTTP GET method

func (*APIClient) GetBusinessGroupID

func (c *APIClient) GetBusinessGroupID(businessGroupName string, tenant string) (string, error)

GetBusinessGroupID retrieves business group id from business group name

func (*APIClient) GetCatalogItemRequestTemplate

func (c *APIClient) GetCatalogItemRequestTemplate(catalogItemID string) (*CatalogItemRequestTemplate, error)

GetCatalogItemRequestTemplate - Call to retrieve a request template for a catalog item.

func (*APIClient) GetRequestResourceView

func (c *APIClient) GetRequestResourceView(catalogRequestID string) (*RequestResourceView, error)

GetRequestResourceView retrieves the resources that were provisioned as a result of a given request.

func (*APIClient) GetRequestResources

func (c *APIClient) GetRequestResources(catalogItemRequestID string) (*Resources, error)

GetRequestResources get the resource actions allowed for a resource

func (*APIClient) GetRequestStatus

func (c *APIClient) GetRequestStatus(requestID string) (*RequestStatusView, error)

GetRequestStatus - To read request status of resource which is used to show information to user post create call.

func (*APIClient) GetResource

func (c *APIClient) GetResource(resourceID string) (*ResourceContent, error)

GetResource get the resource actions allowed for a resource

func (*APIClient) GetResourceActionTemplate

func (c *APIClient) GetResourceActionTemplate(resourceID, actionID string) (*ResourceActionTemplate, error)

GetResourceActionTemplate get the action template corresponding to the action id

func (*APIClient) GetResourceActions

func (c *APIClient) GetResourceActions(resourceID string) ([]Operation, error)

GetResourceActions get the resource actions allowed for a resource

func (*APIClient) Patch

func (c *APIClient) Patch(url string, body io.Reader, headers map[string]string) (*APIResponse, error)

Patch HTTP PATCH method

func (*APIClient) Post

func (c *APIClient) Post(url string, body io.Reader, headers map[string]string) (*APIResponse, error)

Post HTTP POST method

func (*APIClient) PostResourceAction

func (c *APIClient) PostResourceAction(resourceID, actionID string, resourceActionTemplate *ResourceActionTemplate) (string, error)

PostResourceAction updates the resource

func (*APIClient) Put

func (c *APIClient) Put(url string, body io.Reader, headers map[string]string) (*APIResponse, error)

Put HTTP PUT method

func (*APIClient) ReadCatalogItemByName

func (c *APIClient) ReadCatalogItemByName(catalogName string) (string, error)

ReadCatalogItemByName to read id of catalog from vRA using catalog_name

func (*APIClient) ReadCatalogItemNameByID

func (c *APIClient) ReadCatalogItemNameByID(catalogItemID string) (string, error)

ReadCatalogItemNameByID - This function returns the catalog item name using catalog item ID

func (*APIClient) RequestCatalogItem

func (c *APIClient) RequestCatalogItem(requestTemplate *CatalogItemRequestTemplate) (*CatalogRequest, error)

RequestCatalogItem - Make a catalog request.

type APIError

type APIError struct {
	Errors []Error `json:"errors"`
}

APIError represents an error from the vRA API.

func (APIError) Error

func (e APIError) Error() string

Error Implement Go error interface for ApiError

type APIRequest

type APIRequest struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    io.Reader
}

APIRequest struct

func (*APIRequest) AddHeader

func (ar *APIRequest) AddHeader(key, val string)

AddHeader adds headers to the request

func (*APIRequest) ContentType

func (ar *APIRequest) ContentType() string

ContentType returns the content type set in the request header

func (*APIRequest) CopyHeadersTo

func (ar *APIRequest) CopyHeadersTo(req *http.Request)

CopyHeadersTo Add headers to request object

type APIResponse

type APIResponse struct {
	Headers    http.Header
	Body       []byte
	Status     string
	StatusCode int
	Location   string
}

APIResponse struct

func FromHTTPRespToAPIResp

func FromHTTPRespToAPIResp(resp *http.Response) (*APIResponse, error)

FromHTTPRespToAPIResp converts Http response to API response

type AuthResponse

type AuthResponse struct {
	Expires time.Time `json:"expires"`
	ID      string    `json:"id"`
	Tenant  string    `json:"tenant"`
}

AuthResponse - This struct contains response of user authentication call.

type AuthenticationRequest

type AuthenticationRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Tenant   string `json:"tenant"`
}

AuthenticationRequest represents the auth request to vra

type BusinessGroup

type BusinessGroup struct {
	Name string `json:"name,omitempty"`
	ID   string `json:"id,omitempty"`
}

BusinessGroup - detail view of a business group

type BusinessGroups

type BusinessGroups struct {
	Content []BusinessGroup `json:"content,omitempty"`
}

BusinessGroups - list of business groups

type CatalogItem

type CatalogItem struct {
	CatalogItem catalogName `json:"catalogItem"`
}

CatalogItem - This struct holds the value of response of catalog item list

type CatalogItemRequestTemplate

type CatalogItemRequestTemplate struct {
	Type            string                 `json:"type,omitempty"`
	CatalogItemID   string                 `json:"catalogItemId,omitempty"`
	RequestedFor    string                 `json:"requestedFor,omitempty"`
	BusinessGroupID string                 `json:"businessGroupId,omitempty"`
	Description     string                 `json:"description,omitempty"`
	Reasons         string                 `json:"reasons,omitempty"`
	Data            map[string]interface{} `json:"data,omitempty"`
}

CatalogItemRequestTemplate - A structure that captures a catalog request template, to be filled in and POSTED.

type CatalogRequest

type CatalogRequest struct {
	ID           string      `json:"id"`
	IconID       string      `json:"iconId"`
	Version      int         `json:"version"`
	State        string      `json:"state"`
	Description  string      `json:"description"`
	Reasons      interface{} `json:"reasons"`
	RequestedFor string      `json:"requestedFor"`
	RequestedBy  string      `json:"requestedBy"`
	Organization struct {
		TenantRef      string `json:"tenantRef"`
		TenantLabel    string `json:"tenantLabel"`
		SubtenantRef   string `json:"subtenantRef"`
		SubtenantLabel string `json:"subtenantLabel"`
	} `json:"organization"`

	RequestorEntitlementID   string                 `json:"requestorEntitlementId"`
	PreApprovalID            string                 `json:"preApprovalId"`
	PostApprovalID           string                 `json:"postApprovalId"`
	DateCreated              time.Time              `json:"dateCreated"`
	LastUpdated              time.Time              `json:"lastUpdated"`
	DateSubmitted            time.Time              `json:"dateSubmitted"`
	DateApproved             time.Time              `json:"dateApproved"`
	DateCompleted            time.Time              `json:"dateCompleted"`
	Quote                    interface{}            `json:"quote"`
	RequestData              map[string]interface{} `json:"requestData"`
	RequestCompletion        string                 `json:"requestCompletion"`
	RetriesRemaining         int                    `json:"retriesRemaining"`
	RequestedItemName        string                 `json:"requestedItemName"`
	RequestedItemDescription string                 `json:"requestedItemDescription"`
	Components               string                 `json:"components"`
	StateName                string                 `json:"stateName"`

	CatalogItemProviderBinding struct {
		BindingID   string `json:"bindingId"`
		ProviderRef struct {
			ID    string `json:"id"`
			Label string `json:"label"`
		} `json:"providerRef"`
	} `json:"catalogItemProviderBinding"`

	Phase           string `json:"phase"`
	ApprovalStatus  string `json:"approvalStatus"`
	ExecutionStatus string `json:"executionStatus"`
	WaitingStatus   string `json:"waitingStatus"`
	CatalogItemRef  struct {
		ID    string `json:"id"`
		Label string `json:"label"`
	} `json:"catalogItemRef"`
}

CatalogRequest - A structure that captures a vRA catalog request.

type EntitledCatalogItemViews

type EntitledCatalogItemViews struct {
	Links    interface{} `json:"links"`
	Content  interface{} `json:"content"`
	Metadata Metadata    `json:"metadata"`
}

EntitledCatalogItemViews represents catalog items in an active state, the current user is entitled to consume

type Error

type Error struct {
	Code          int    `json:"code"`
	Message       string `json:"message"`
	SystemMessage string `json:"systemMessage"`
}

Error API Error

type HTTPClient

type HTTPClient interface {
	DoRequest(req *APIRequest) (*APIResponse, error)
}

HTTPClient interface

type Metadata

type Metadata struct {
	Size          int `json:"size"`
	TotalElements int `json:"totalElements"`
	TotalPages    int `json:"totalPages"`
	Number        int `json:"number"`
}

Metadata - Metadata used to store metadata of resource list response

type Operation

type Operation struct {
	Name        string `json:"name,omitempty"`
	ID          string `json:"id,omitempty"`
	Description string `json:"description,omitempty"`
	Type        string `json:"type,omitempty"`
}

Operation - detailed view of an operation allowed on a resource

type RequestResourceView

type RequestResourceView struct {
	Content []interface{} `json:"content,omitempty"`
	Links   []interface{} `json:"links,omitempty"`
}

RequestResourceView - resource view of a provisioned request

type RequestResponse

type RequestResponse struct {
	Content []interface{} `json:"content,omitempty"`
	Links   []interface{} `json:"links,omitempty"`
}

RequestResponse is the response structure of any request

type RequestStatusView

type RequestStatusView struct {
	RequestCompletion struct {
		RequestCompletionState string `json:"requestCompletionState"`
		CompletionDetails      string `json:"CompletionDetails"`
	} `json:"requestCompletion"`
	Phase string `json:"phase"`
}

RequestStatusView - used to store REST response of request triggered against any resource.

type ResourceActionTemplate

type ResourceActionTemplate struct {
	Type        string                 `json:"type,omitempty"`
	ResourceID  string                 `json:"resourceId,omitempty"`
	ActionID    string                 `json:"actionId,omitempty"`
	Description string                 `json:"description,omitempty"`
	Reasons     string                 `json:"reasons,omitempty"`
	Data        map[string]interface{} `json:"data,omitempty"`
}

ResourceActionTemplate - is used to store information related to resource action template information.

type ResourceConfigurationStruct

type ResourceConfigurationStruct struct {
	ComponentName    string                 `json:"component_name,omitempty"`
	Cluster          int                    `json:"cluster,omitempty"`
	Description      string                 `json:"description,omitempty"`
	Name             string                 `json:"name,omitempty"`
	ResourceID       string                 `json:"resource_id,omitempty"`
	Status           string                 `json:"status,omitempty"`
	RequestID        string                 `json:"request_id,omitempty"`
	RequestState     string                 `json:"request_state,omitempty"`
	ResourceType     string                 `json:"resource_type,omitempty"`
	Configuration    map[string]interface{} `json:"configuration,omitempty"`
	ResourceState    map[string]interface{} `json:"resource_state,omitempty"`
	DateCreated      string                 `json:"last_created,omitempty"`
	LastUpdated      string                 `json:"last_updated,omitempty"`
	ParentResourceID string                 `json:"parent_resource_id,omitempty"`
	IPAddress        string                 `json:"ip_address,omitempty"`
}

ResourceConfigurationStruct - structure representing the resource_configuration

type ResourceContent

type ResourceContent struct {
	ID              string          `json:"id,omitempty"`
	Name            string          `json:"name,omitempty"`
	ResourceTypeRef ResourceTypeRef `json:"resourceTypeRef,omitempty"`
	Status          string          `json:"status,omitempty"`
	RequestID       string          `json:"requestId,omitempty"`
	RequestState    string          `json:"requestState,omitempty"`
	Operations      []Operation     `json:"operations,omitempty"`
	ResourceData    ResourceDataMap `json:"resourceData,omitempty"`
}

ResourceContent - Detailed view of the resource provisioned and the operation allowed

type ResourceDataEntry

type ResourceDataEntry struct {
	Key   string                 `json:"key,omitempty"`
	Value map[string]interface{} `json:"value,omitempty"`
}

ResourceDataEntry - the property key and value of a resource

type ResourceDataMap

type ResourceDataMap struct {
	Entries []ResourceDataEntry `json:"entries,omitempty"`
}

ResourceDataMap - properties of a provisioned resource

type ResourceTypeRef

type ResourceTypeRef struct {
	ID    string `json:"id,omitempty"`
	Label string `json:"label,omitempty"`
}

ResourceTypeRef - type of resource (deployment, or machine, etc)

type Resources

type Resources struct {
	Links   []interface{}     `json:"links,omitempty"`
	Content []ResourceContent `json:"content,omitempty"`
}

Resources - Retrieves the resources that were provisioned as a result of a given request. Also returns the actions allowed on the resources and their templates

Jump to

Keyboard shortcuts

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