azure

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: GPL-3.0 Imports: 53 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// BatchAPIVersion defines API version of batch service.
	BatchAPIVersion = "2016-07-01.3.1"
	// RoadieAzureArchiveName is an archive name of roarie-azure command.
	RoadieAzureArchiveName = "roadie-azure_linux_amd64.tar.gz"
	// RoadieAzureVersion is the version of the job manager program.
	RoadieAzureVersion = "v0.3.5"
)
View Source
const (
	// DefaultOSPublisherName is the default publisher name of the default OS image.
	DefaultOSPublisherName = "Canonical"
	// DefaultOSOffer is the default offer of the default OS image.
	DefaultOSOffer = "UbuntuServer"
	// DefaultOSSkus is the default skus of the default OS image.
	DefaultOSSkus = "17.04"
	// DefaultOSVersion is the default version of the default version.
	DefaultOSVersion = "latest"
	// DefaultLocation is the default location.
	DefaultLocation = "westus"

	// DefaultSleepTime is the default sleeping time to wait creating or deleting
	// objects.
	DefaultSleepTime = 30 * time.Second

	// ComputeServiceDefaultMachineType defines the default machine type.
	ComputeServiceDefaultMachineType = "Standard_A2"
	// ComputeServiceCustomScriptExtension defines the name of custom script
	// extention.
	ComputeServiceCustomScriptExtension = "CustomScriptForLinux"

	// BinContainer is the name of the container where binary programs will be stored.
	BinContainer = "bin"
	// SourceContainer is the name of the container where source files will be stored.
	SourceContainer = "source"
	// DataContainer is the name of the container where data files will be stored.
	DataContainer = "data"
	// StartupContainer is the name of the container where startup files will be stored.
	StartupContainer = "startup"
	// ResultContainer is the name of the container where result files will be stored.
	ResultContainer = "result"
	// LogContainer is the name of the container where logs will be stored.
	LogContainer = "log"

	// QueuePrefix is a prefix a job which is working for a queue must has.
	QueuePrefix = "queue-"
	// TaskPrefix is a prefix a task which is working for a queue must has.
	TaskPrefix = "task-"
)
View Source
const (
	// ComputeAPIVersion defines API version of compute service.
	ComputeAPIVersion = "2016-04-30-preview"
)
View Source
const (
	// DefaultAccessPolicyExpiryTime defines a default expiry time.
	DefaultAccessPolicyExpiryTime = 30 * 24 * time.Hour
)
View Source
const (
	// ResourceAPIVersion defines API version of resource service.
	ResourceAPIVersion = "2016-09-01"
)
View Source
const (
	// StartupTemplate is the asset name of the startup template.
	StartupTemplate = "assets/azure_startup.sh"
)
View Source
const (
	// SubscriptionsAPIVersion defines API version of sbscriptions service.
	SubscriptionsAPIVersion = "2016-06-01"
)

Variables

View Source
var (
	// RoadieAzureURL is a template of URL where the job manager program is published.
	RoadieAzureURL = fmt.Sprintf("https://github.com/jkawamoto/roadie-azure/releases/download/%v/%v", RoadieAzureVersion, RoadieAzureArchiveName)
)

Functions

func CreateResourceGroupIfNotExist

func CreateResourceGroupIfNotExist(ctx context.Context, cfg *Config, logger *log.Logger) (err error)

CreateResourceGroupIfNotExist checks a given named resource group exists in a given subscription and location. If not exists, this function creates a new resource group.

func Locations

func Locations(ctx context.Context, token *adal.Token, subscriptionID string) (regions []cloud.Region, err error)

Locations gets list of locations in a given subscription.

func NewAPIError

func NewAPIError(err error) error

NewAPIError creates an error which is raised from an API call.

func StartupScript

func StartupScript(cfg *Config, task *script.Script) (res string, err error)

StartupScript creates a base64 encoded string representing a starup script.

Types

type AuthorizedTransporter

type AuthorizedTransporter struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

AuthorizedTransporter is a transporter which adds authentication information to each request before transporting it.

func NewAuthorizedTransporter

func NewAuthorizedTransporter(transport http.RoundTripper, account string, key []byte) *AuthorizedTransporter

NewAuthorizedTransporter creates a new authorized transporter with a given account name and shared key.

func (*AuthorizedTransporter) RoundTrip

func (t *AuthorizedTransporter) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip computes a shared key from a given request and add Authorization header to the request.

type BatchService

type BatchService struct {
	Config    *Config
	Logger    *log.Logger
	SleepTime time.Duration
	// contains filtered or unexported fields
}

BatchService provides an interface for Azure's batch service.

func NewBatchService

func NewBatchService(ctx context.Context, cfg *Config, logger *log.Logger) (service *BatchService, err error)

NewBatchService creates a new batch service interface assosiated with a given config; to authorize a authentication token is required.

func (*BatchService) AvailableMachineTypes

func (s *BatchService) AvailableMachineTypes(ctx context.Context) (types []cloud.MachineType, err error)

AvailableMachineTypes returns a list of supported machine types. Batch supports all Azure VM sizes except STANDARD_A0 and those with premium storage (STANDARD_GS, STANDARD_DS, and STANDARD_DSV2 series).

func (*BatchService) AvailableOSImages

func (s *BatchService) AvailableOSImages(ctx context.Context) (images []string, err error)

AvailableOSImages returns a list of available OS images.

func (*BatchService) CreateJob

func (s *BatchService) CreateJob(ctx context.Context, name string) (err error)

CreateJob creates a job which has a given name.

func (*BatchService) CreateTask

func (s *BatchService) CreateTask(ctx context.Context, job string, task *script.Script) (err error)

CreateTask adds a given task to a given named job.

func (*BatchService) DeleteJob

func (s *BatchService) DeleteJob(ctx context.Context, name string) (err error)

DeleteJob deletes a given named job.

func (*BatchService) DeleteTask

func (s *BatchService) DeleteTask(ctx context.Context, job, task string) (err error)

DeleteTask deletes a given named task from a given named job.

func (*BatchService) DisableJob

func (s *BatchService) DisableJob(ctx context.Context, name string) (err error)

DisableJob stops a given named job.

func (*BatchService) EnableJob

func (s *BatchService) EnableJob(ctx context.Context, name string) (err error)

EnableJob starts a given named job which was stopped.

func (*BatchService) GetJobInfo

func (s *BatchService) GetJobInfo(ctx context.Context, job string) (info *models.CloudJob, err error)

GetJobInfo retrives the information of the given named job.

func (*BatchService) GetPoolInfo

func (s *BatchService) GetPoolInfo(ctx context.Context, name string) (info *models.CloudPool, err error)

GetPoolInfo retrieves information of a given named pool.

func (*BatchService) Jobs

func (s *BatchService) Jobs(ctx context.Context) (set JobSet, err error)

Jobs retrieves a set of jobs defined in the batch account specified in the configuration.

func (*BatchService) Nodes

func (s *BatchService) Nodes(ctx context.Context, pool string) (nodes []*models.ComputeNode, err error)

Nodes retrieves information of compute nodes in a given named pool.

func (*BatchService) Tasks

func (s *BatchService) Tasks(ctx context.Context, job string) (set TaskSet, err error)

Tasks retrieves tasks in a given named job.

func (*BatchService) UpdatePoolSize

func (s *BatchService) UpdatePoolSize(ctx context.Context, name string, size int32) (err error)

UpdatePoolSize requests updating the size of the given named pool to size. Note that: resizing pool size is an asynchronous operation.

type ComputeService

type ComputeService struct {
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

ComputeService provides an interface for Azure's compute service.

func NewComputeService

func NewComputeService(ctx context.Context, cfg *Config, logger *log.Logger) (s *ComputeService, err error)

NewComputeService creates a new compute service interface assosiated with a given configuration.

func (*ComputeService) AvailableMachineTypes

func (s *ComputeService) AvailableMachineTypes(ctx context.Context) (types []cloud.MachineType, err error)

AvailableMachineTypes returns a list of available machine types.

func (*ComputeService) AvailableRegions

func (s *ComputeService) AvailableRegions(ctx context.Context) (regions []cloud.Region, err error)

AvailableRegions returns a list of available regions.

func (*ComputeService) ImageID

func (s *ComputeService) ImageID(ctx context.Context, publisherName, offer, skus, version string) (id string, err error)

ImageID retrieves an image ID.

func (*ComputeService) ImageOffers

func (s *ComputeService) ImageOffers(ctx context.Context, publisher string) (offers []Entry, err error)

ImageOffers retrieves a set of offers provided by a given publisher.

func (*ComputeService) ImagePublishers

func (s *ComputeService) ImagePublishers(ctx context.Context) (publishers []Entry, err error)

ImagePublishers retrieves a set of image publishers.

func (*ComputeService) ImageSkus

func (s *ComputeService) ImageSkus(ctx context.Context, publisherName, offer string) (skus []Entry, err error)

ImageSkus retrieves a set of skus provded by a given publisher and offer.

func (*ComputeService) ImageVersions

func (s *ComputeService) ImageVersions(ctx context.Context, publisherName, offer, skus string) (versions []Entry, err error)

ImageVersions retrieves a set of versions provided by a given publisher, offer, and skus.

type Config

type Config struct {
	TenantID       string `yaml:"tenant_id,omitempty"`
	SubscriptionID string `yaml:"subscription_id,omitempty"`
	Location       string `yaml:"location,omitempty"`
	ProjectID      string `yaml:"project_id,omitempty"`
	AccountName    string `yaml:"-"`
	MachineType    string `yaml:"machine_type,omitempty"`
	OS             OSInformation
	Token          adal.Token
}

Config defines configuration to access Azure's API.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config with default values.

func NewConfigFromFile

func NewConfigFromFile(filename string) (cfg *Config, err error)

NewConfigFromFile creates a new Config from a file.

func (*Config) String

func (cfg *Config) String() (str string, err error)

String returns a string representing this configuration.

func (*Config) UnmarshalYAML

func (cfg *Config) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

UnmarshalYAML unmarshals this configuration from a YAML document.

func (*Config) Valid

func (cfg *Config) Valid() bool

Valid returns true if this config has values in required fields; otherwise return false. The required fields are - TenantID - SubscriptionID - ProjectID

func (*Config) WriteFile

func (cfg *Config) WriteFile(filename string) (err error)

WriteFile writes this configuration to a file.

type Entry

type Entry struct {
	ID   string
	Name string
}

Entry is an entry of lists.

type InstanceManager

type InstanceManager struct {
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

InstanceManager implements cloud.InstanceManager interface to run a script on Azure.

func NewInstanceManager

func NewInstanceManager(ctx context.Context, cfg *Config, logger *log.Logger) (m *InstanceManager, err error)

NewInstanceManager creates a new instance manager.

func (*InstanceManager) AvailableMachineTypes

func (m *InstanceManager) AvailableMachineTypes(ctx context.Context) (types []cloud.MachineType, err error)

AvailableMachineTypes returns a list of available machine types.

func (*InstanceManager) AvailableRegions

func (m *InstanceManager) AvailableRegions(ctx context.Context) (regions []cloud.Region, err error)

AvailableRegions returns a list of available regions.

func (*InstanceManager) CreateInstance

func (m *InstanceManager) CreateInstance(ctx context.Context, task *script.Script) (err error)

CreateInstance creates an instance which has a given name.

func (*InstanceManager) DeleteInstance

func (m *InstanceManager) DeleteInstance(ctx context.Context, name string) error

DeleteInstance deletes the given named instance.

func (*InstanceManager) Instances

func (m *InstanceManager) Instances(ctx context.Context, handler cloud.InstanceHandler) (err error)

Instances returns a list of running instances

type JobSet

type JobSet map[string]*models.CloudJob

JobSet represents a set of jobs.

type LogManager

type LogManager struct {
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

LogManager defines a service interface for obtaining log entries.

func NewLogManager

func NewLogManager(ctx context.Context, cfg *Config, logger *log.Logger) (m *LogManager, err error)

NewLogManager creates a new log manger for Azure.

func (*LogManager) Delete

func (m *LogManager) Delete(ctx context.Context, instanceName string) (err error)

Delete instance log.

func (*LogManager) Get

func (m *LogManager) Get(ctx context.Context, instanceName string, from time.Time, handler cloud.LogHandler) (err error)

Get retrievs log entries.

func (*LogManager) GetQueueLog

func (m *LogManager) GetQueueLog(ctx context.Context, queue string, handler cloud.LogHandler) (err error)

GetQueueLog retrieves log of a given queue.

func (*LogManager) GetTaskLog

func (m *LogManager) GetTaskLog(ctx context.Context, queue, task string, handler cloud.LogHandler) (err error)

GetTaskLog retrieves log of a given task.

type MinimalJSONProducer

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

MinimalJSONProducer is a provider which marshals message bodies as a JSON object and remove null values from it.

func NewMinimalJSONProducer

func NewMinimalJSONProducer() *MinimalJSONProducer

NewMinimalJSONProducer creates a new MinimalJSONProducer.

func (*MinimalJSONProducer) Produce

func (p *MinimalJSONProducer) Produce(out io.Writer, msg interface{}) (err error)

Produce creates a message body from a given request message.

type OSInformation

type OSInformation struct {
	PublisherName string `yaml:"publisher_name,omitempty"`
	Offer         string `yaml:"offer,omitempty"`
	Skus          string `yaml:"skus,omitempty"`
	Version       string `yaml:"version,omitempty"`
}

OSInformation defines OS information of creating instances.

func (*OSInformation) UnmarshalYAML

func (info *OSInformation) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

UnmarshalYAML unmarshals configuration form a YAML document.

type Provider

type Provider struct {
	Config *Config
	Logger *log.Logger
}

Provider provides information of the service provider for Azure.

func NewProvider

func NewProvider(ctx context.Context, cfg *Config, logger *log.Logger, forceAuth bool) (provider *Provider, err error)

NewProvider creates a new provider for Azure service.

func (*Provider) InstanceManager

func (p *Provider) InstanceManager(ctx context.Context) (cloud.InstanceManager, error)

InstanceManager returns an instance manager interface.

func (*Provider) LogManager

func (p *Provider) LogManager(ctx context.Context) (cloud.LogManager, error)

LogManager returns a log manager interface.

func (*Provider) QueueManager

func (p *Provider) QueueManager(ctx context.Context) (cloud.QueueManager, error)

QueueManager returns a queue manager interface.

func (*Provider) ResourceManager

func (p *Provider) ResourceManager(ctx context.Context) (cloud.ResourceManager, error)

ResourceManager returns a resource manager interface.

func (*Provider) StorageManager

func (p *Provider) StorageManager(ctx context.Context) (cloud.StorageManager, error)

StorageManager returns a storage manager interface.

type QueueManager

type QueueManager struct {
	Config *Config
	Logger *log.Logger
	// contains filtered or unexported fields
}

QueueManager implements cloud.QueueManager interface to run a script on Azure.

func NewQueueManager

func NewQueueManager(ctx context.Context, cfg *Config, logger *log.Logger) (m *QueueManager, err error)

NewQueueManager creates a new queue manager.

func (*QueueManager) CreateWorkers

func (m *QueueManager) CreateWorkers(ctx context.Context, queue string, n int, handler cloud.QueueManagerNameHandler) (err error)

CreateWorkers creates worker instances working for a given named queue.

func (*QueueManager) DeleteQueue

func (m *QueueManager) DeleteQueue(ctx context.Context, queue string) (err error)

DeleteQueue deletes a given named queue.

func (*QueueManager) DeleteTask

func (m *QueueManager) DeleteTask(ctx context.Context, queue, task string) (err error)

DeleteTask deletes a given named task in a given named queue.

func (*QueueManager) Enqueue

func (m *QueueManager) Enqueue(ctx context.Context, queue string, task *script.Script) (err error)

Enqueue a new task to a given named queue.

func (*QueueManager) Queues

func (m *QueueManager) Queues(ctx context.Context, handler cloud.QueueStatusHandler) (err error)

Queues retrieves existing queue names.

func (*QueueManager) Restart

func (m *QueueManager) Restart(ctx context.Context, queue string) error

Restart executing tasks in a given names queue.

func (*QueueManager) Stop

func (m *QueueManager) Stop(ctx context.Context, queue string) error

Stop executing tasks in a given named queue.

func (*QueueManager) Tasks

func (m *QueueManager) Tasks(ctx context.Context, queue string, handler cloud.QueueManagerTaskHandler) (err error)

Tasks retrieves tasks in a given names queue.

func (*QueueManager) Workers

func (m *QueueManager) Workers(ctx context.Context, queue string, handler cloud.QueueManagerNameHandler) (err error)

Workers retrieves worker instance names for a given queue.

type ResourceGroupSet

type ResourceGroupSet map[string]*models.ResourceGroup

ResourceGroupSet is a map of which key represents a name of a resource group and the associated value represents a resource group object.

type ResourceManager

type ResourceManager struct {
	Config *Config
	Logger *log.Logger
}

ResourceManager implements cloud.ResourceManager.

func NewResourceManager

func NewResourceManager(cfg *Config, logger *log.Logger) *ResourceManager

NewResourceManager creates a new ResourceManager.

func (*ResourceManager) GetMachineType

func (m *ResourceManager) GetMachineType() string

GetMachineType returns a machine type the current project uses by default.

func (*ResourceManager) GetProjectID

func (m *ResourceManager) GetProjectID() string

GetProjectID returns an ID of the current project.

func (*ResourceManager) GetRegion

func (m *ResourceManager) GetRegion() string

GetRegion returns a region name the current project working on.

func (*ResourceManager) MachineTypes

func (m *ResourceManager) MachineTypes(ctx context.Context) ([]cloud.MachineType, error)

MachineTypes returns a set of available machine types.

func (*ResourceManager) Regions

func (m *ResourceManager) Regions(ctx context.Context) ([]cloud.Region, error)

Regions returns a set of available regions.

func (*ResourceManager) SetMachineType

func (m *ResourceManager) SetMachineType(t string)

SetMachineType sets a machine type as the default one.

func (*ResourceManager) SetProjectID

func (m *ResourceManager) SetProjectID(id string)

SetProjectID sets an ID to the current project.

func (*ResourceManager) SetRegion

func (m *ResourceManager) SetRegion(region string)

SetRegion sets a region to the current project.

type ResourceService

type ResourceService struct {
	Config    *Config
	Logger    *log.Logger
	SleepTime time.Duration
	// contains filtered or unexported fields
}

ResourceService provides an interface for Azure's resource management service.

func NewResourceService

func NewResourceService(cfg *Config, logger *log.Logger) *ResourceService

NewResourceService creates a resource service associated with a given subscription.

func (*ResourceService) CheckExistence

func (s *ResourceService) CheckExistence(ctx context.Context, name string) bool

CheckExistence checkes a given named resource group exists.

func (*ResourceService) CreateResourceGroup

func (s *ResourceService) CreateResourceGroup(ctx context.Context, name string) (err error)

CreateResourceGroup creates a resource group which has a given name in a given location. The created resource group will belong to the subscription specified whtn this resource service was created.

func (*ResourceService) DeleteResourceGroup

func (s *ResourceService) DeleteResourceGroup(ctx context.Context, name string) (err error)

DeleteResourceGroup deletes a given named resource group.

func (*ResourceService) ResourceGroups

func (s *ResourceService) ResourceGroups(ctx context.Context) (groups ResourceGroupSet, err error)

ResourceGroups retrieves a set of resource groups belonging to the subscrption specified when this resource service was created.

type StorageService

type StorageService struct {
	// Client of blob storage service
	Client storage.BlobStorageClient
	// Configuration
	Config *Config
	// Logger
	Logger *log.Logger
	// AccessPolicyExpiryTime defines the expiry time for accessing containers.
	AccessPolicyExpiryTime time.Duration
}

StorageService provides an interface for Azure's storage management service.

func NewStorageService

func NewStorageService(ctx context.Context, cfg *Config, logger *log.Logger) (s *StorageService, err error)

NewStorageService creates an interface of the storage service which has a given name and belongs to given subscription and location. If log.Logger logger is given, verbose mode is on and logging information will be written to the logger.

func (*StorageService) Delete

func (s *StorageService) Delete(ctx context.Context, loc *url.URL) (err error)

Delete a file in a given location.

func (*StorageService) Download

func (s *StorageService) Download(ctx context.Context, loc *url.URL, out io.Writer) (err error)

Download a file associated from a given location and write it to a given writer.

func (*StorageService) GetFileInfo

func (s *StorageService) GetFileInfo(ctx context.Context, loc *url.URL) (info *cloud.FileInfo, err error)

GetFileInfo gets information of file in a given location.

func (*StorageService) GetMetadata

func (s *StorageService) GetMetadata(ctx context.Context, container, filename string) (metadata map[string]string, err error)

GetMetadata retrives metadata of a given named file.

func (*StorageService) List

func (s *StorageService) List(ctx context.Context, loc *url.URL, handler cloud.FileInfoHandler) (err error)

List up files matching a given prefix. It takes a handler; information of found files are sent to it.

func (*StorageService) Upload

func (s *StorageService) Upload(ctx context.Context, loc *url.URL, in io.Reader) (err error)

Upload a given stream to a given location.

func (*StorageService) UploadWithMetadata

func (s *StorageService) UploadWithMetadata(
	ctx context.Context, container, filename string, in io.Reader, props *storage.BlobProperties, metadata storage.BlobMetadata) (err error)

UploadWithMetadata a given stream in a given container as a file named a given file name.

type TaskSet

type TaskSet map[string]*models.CloudTask

TaskSet represents a set of tasks.

Jump to

Keyboard shortcuts

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