resource

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2016 License: BSD-2-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFunctionNamespace = "stdlib"

DefaultFunctionNamespace is the Lua table where functions are being registered to, when using the default namespace.

View Source
const DefaultResourceNamespace = "resource"

DefaultResourceNamespace is the Lua table where resources are being registered to, when using the default namespace.

View Source
const VSphereNamespace = "vsphere"

VSphereNamespace is the table name in Lua where vSphere resources are being registered to.

Variables

View Source
var DefaultConfig = &Config{
	Logger: log.New(os.Stdout, "", log.LstdFlags),
}

DefaultConfig is the default configuration used by the resources

View Source
var ErrInSync = errors.New("Resource is in sync")

ErrInSync error is returned when a resource is in the desired state

View Source
var ErrInvalidName = errors.New("Invalid resource name")

ErrInvalidName error is returned when a resource name is invalid

View Source
var ErrInvalidType = errors.New("Invalid resource type")

ErrInvalidType error is returned when a resource type is invalid

View Source
var ErrNoEndpoint = errors.New("No endpoint provided")

ErrNoEndpoint error is returned when no VMware vSphere API endpoint is provided.

View Source
var ErrNoPackageProviderFound = errors.New("No suitable package provider found")

ErrNoPackageProviderFound is returned when no suitable provider is found

View Source
var ErrNoPassword = errors.New("No password provided")

ErrNoPassword error is returned when no password is provided for establishing a connection to the remote VMware vSphere API endpoint.

View Source
var ErrNoSystemd = errors.New("No systemd support found")

ErrNoSystemd error is returned when the system is detected to have no support for systemd.

View Source
var ErrNoUsername = errors.New("No username provided")

ErrNoUsername error is returned when no username is provided for establishing a connection to the remote VMware vSphere API endpoint.

View Source
var ErrNotImplemented = errors.New("Not implemented")

ErrNotImplemented error is returned when a resource does not implement specific functionality, e.g. the resource is not applicable for a refresh.

View Source
var ErrNotVC = errors.New("Not a VMware vCenter endpoint")

ErrNotVC error is returned when the remote endpoint is not a vCenter system.

View Source
var ErrResourceAbsent = errors.New("Resource is absent")

ErrResourceAbsent error is returned by properties in situations where setting up a property makes no sense if the resource is absent, e.g. setting up file permissions makes no sense if the file resource is in absent state.

Functions

func Logf added in v0.5.0

func Logf(format string, a ...interface{})

Logf writes an event to the default logger.

func LuaRegisterBuiltin added in v0.3.0

func LuaRegisterBuiltin(L *lua.LState)

LuaRegisterBuiltin registers resource providers and functions in Lua.

func RegisterFunction added in v0.5.0

func RegisterFunction(items ...FunctionItem)

RegisterFunction registers a function to the registry.

func RegisterProvider added in v0.3.0

func RegisterProvider(items ...ProviderItem)

RegisterProvider registers a provider to the registry.

Types

type Base added in v0.4.0

type Base struct {
	// Type of the resource
	Type string `luar:"-"`

	// Name of the resource
	Name string `luar:"-"`

	// Desired state of the resource
	State string `luar:"state"`

	// Require contains the resource dependencies
	Require []string `luar:"require"`

	// PresentStatesList contains the list of states, for which the
	// resource is considered to be present
	PresentStatesList []string `luar:"-"`

	// AbsentStates contains the list of states, for which the
	// resource is considered to be absent
	AbsentStatesList []string `luar:"-"`

	// Concurrent flag indicates whether multiple instances of the
	// same resource type can be processed concurrently.
	Concurrent bool `luar:"-"`

	// PropertyList contains the resource properties.
	PropertyList []Property `luar:"-"`

	// Subscribe is map whose keys are resource ids that the
	// current resource monitors for changes and the values are
	// functions that will be executed if the monitored
	// resource state has changed.
	// Subscribing to changes in other resources also automatically
	// creates an edge in the dependency graph pointing from the
	// current resource to the one that is being monitored, so that the
	// monitored resource is evaluated and processed first.
	Subscribe map[string]*lua.LFunction `luar:"subscribe"`
}

Base is the base resource type for all resources The purpose of this type is to be embedded into other resources Partially implements the Resource interface

func (*Base) AbsentStates added in v0.4.0

func (b *Base) AbsentStates() []string

AbsentStates returns the list of states, for which the resource is considered to be absent

func (*Base) Close added in v0.5.0

func (b *Base) Close() error

Close is used to perform cleanup tasks after the resource has been processed.

func (*Base) Dependencies added in v0.4.0

func (b *Base) Dependencies() []string

Dependencies returns the list of resource dependencies.

func (*Base) ID added in v0.4.0

func (b *Base) ID() string

ID returns the unique resource id

func (*Base) Initialize added in v0.5.0

func (b *Base) Initialize() error

Initialize initializes the resource prior the actual processing, e.g. establishing connection to a remote API endpoint.

func (*Base) IsConcurrent added in v0.4.0

func (b *Base) IsConcurrent() bool

IsConcurrent returns a boolean indicating whether multiple instances of the same resource type can be processed concurrently.

func (*Base) PresentStates added in v0.4.0

func (b *Base) PresentStates() []string

PresentStates returns the list of states, for which the resource is considered to be present

func (*Base) Properties added in v0.5.0

func (b *Base) Properties() []Property

Properties returns the list of properties for the resource.

func (*Base) SubscribedTo added in v0.5.0

func (b *Base) SubscribedTo() TriggerMap

SubscribedTo returns a map of resources for which the resource is subscribed for changes to.

func (*Base) Validate added in v0.4.0

func (b *Base) Validate() error

Validate validates the resource

type BaseFile added in v0.5.0

type BaseFile struct {
	Base

	// Path to the file. Defaults to the resource name.
	Path string `luar:"-"`

	// Permission bits to set on the file.
	// For regular files defaults to 0644.
	// For directories defaults to 0755.
	Mode os.FileMode `luar:"mode"`

	// Owner of the file. Defaults to the currently running user.
	Owner string `luar:"owner"`

	// Group of the file.
	// Defaults to the group of the currently running user.
	Group string `luar:"group"`
}

BaseFile type is the base type which is embedded by File, Directory and Link resources.

type BasePackage added in v0.3.0

type BasePackage struct {
	Base

	// Name of the package to manage. Defaults to the resource name.
	Package string `luar:"-"`

	// Version of the package.
	Version string `luar:"version"`
	// contains filtered or unexported fields
}

BasePackage is the base resource type for package management It's purpose is to be embedded into other package resource providers.

func (*BasePackage) Create added in v0.3.0

func (bp *BasePackage) Create() error

Create installs the package

func (*BasePackage) Delete added in v0.3.0

func (bp *BasePackage) Delete() error

Delete deletes the package

func (*BasePackage) Evaluate added in v0.3.0

func (bp *BasePackage) Evaluate() (State, error)

Evaluate evaluates the state of the package

func (*BasePackage) Update added in v0.3.0

func (bp *BasePackage) Update() error

Update updates the package

type BaseVSphere added in v0.5.0

type BaseVSphere struct {
	Base

	// Username to use when connecting to the vSphere endpoint.
	// Defaults to an empty string.
	Username string `luar:"username"`

	// Password to use when connecting to the vSphere endpoint.
	// Defaults to an empty string.
	Password string `luar:"password"`

	// Endpoint to the VMware vSphere API. Defaults to an empty string.
	Endpoint string `luar:"endpoint"`

	// Path to use when creating the object managed by the resource.
	// Defaults to "/".
	Path string `luar:"path"`

	// If set to true then allow connecting to vSphere API endpoints with
	// self-signed certificates. Defaults to false.
	Insecure bool `luar:"insecure"`
	// contains filtered or unexported fields
}

BaseVSphere type is the base type for all vSphere related resources.

func (*BaseVSphere) Close added in v0.5.0

func (bv *BaseVSphere) Close() error

Close closes the connection to the remote vSphere API endpoint.

func (*BaseVSphere) ID added in v0.5.0

func (bv *BaseVSphere) ID() string

ID returns the unique resource id for the resource

func (*BaseVSphere) Initialize added in v0.5.0

func (bv *BaseVSphere) Initialize() error

Initialize establishes a connection to the remote vSphere API endpoint.

func (*BaseVSphere) Validate added in v0.5.0

func (bv *BaseVSphere) Validate() error

Validate validates the resource.

type Cluster added in v0.5.0

type Cluster struct {
	BaseVSphere

	// Config contains the cluster configuration settings.
	Config *ClusterConfig `luar:"config"`
}

Cluster type is a resource which manages clusters in a VMware vSphere environment.

Example:

cluster = vsphere.cluster.new("my-cluster")
cluster.endpoint = "https://vc01.example.org/sdk"
cluster.username = "root"
cluster.password = "myp4ssw0rd"
cluster.insecure = true
cluster.state = "present"
cluster.path = "/MyDatacenter/host"
cluster.config = {
  enable_drs = true,
  drs_behavior = "fullyAutomated",
  enable_ha = true
}

func (*Cluster) Create added in v0.5.0

func (c *Cluster) Create() error

Create creates a new cluster.

func (*Cluster) Delete added in v0.5.0

func (c *Cluster) Delete() error

Delete removes the cluster.

func (*Cluster) Evaluate added in v0.5.0

func (c *Cluster) Evaluate() (State, error)

Evaluate evalutes the state of the cluster.

type ClusterConfig added in v0.5.0

type ClusterConfig struct {
	// DrsBehavior specifies the cluster-wide default DRS behavior for
	// virtual machines.
	// Valid values are "fullyAutomated", "manual" and "partiallyAutomated".
	// Refer to the official VMware vSphere API documentation for explanation on
	// each of these settings. Defaults to "fullyAutomated".
	DrsBehavior types.DrsBehavior `luar:"drs_behavior"`

	// EnableDrs flag specifies whether or not to enable the DRS service.
	// Defaults to false.
	EnableDrs bool `luar:"enable_drs"`

	// EnableHA flag specifies whether or not to enable the HA service.
	// Defaults to false.
	EnableHA bool `luar:"enable_ha"`
}

ClusterConfig type represents configuration settings of a vSphere cluster.

type ClusterHost added in v0.5.0

type ClusterHost struct {
	BaseVSphere

	// EsxiUsername is the username used to connect to the
	// remote ESXi host. Defaults to an empty string.
	EsxiUsername string `luar:"esxi_username"`

	// EsxiPassword is the password used to connect to the
	// remote ESXi host. Defaults to an empty string.
	EsxiPassword string `luar:"esxi_password"`

	// SSL thumbprint of the host. Defaults to an empty string.
	SslThumbprint string `luar:"ssl_thumbprint"`

	// Force flag specifies whether or not to forcefully add the
	// host to the cluster, possibly disconnecting it from any other
	// connected vCenter servers. Defaults to false.
	Force bool `luar:"force"`

	// Port to connect to on the remote ESXi host. Defaults to 443.
	Port int32 `luar:"port"`

	// License to attach to the host. Defaults to an empty string.
	License string `luar:"license"`
}

ClusterHost type is a resource which manages hosts in a VMware vSphere cluster.

Example:

host = vsphere.cluster_host.new("esxi01.example.org")
host.endpoint = "https://vc01.example.org/sdk"
host.username = "root"
host.password = "myp4ssw0rd"
host.state = "present"
host.path = "/MyDatacenter/host/MyCluster"
host.esxi_username = "root"
host.esxi_password = "esxip4ssw0rd"

func (*ClusterHost) Create added in v0.5.0

func (ch *ClusterHost) Create() error

Create adds the host to the cluster.

func (*ClusterHost) Delete added in v0.5.0

func (ch *ClusterHost) Delete() error

Delete disconnects the host and then removes it.

func (*ClusterHost) Evaluate added in v0.5.0

func (ch *ClusterHost) Evaluate() (State, error)

Evaluate evaluates the state of the host in the cluster.

type Collection added in v0.3.0

type Collection map[string]Resource

Collection type is a map which keys are the resource ids and their values are the actual resources

func CreateCollection added in v0.3.0

func CreateCollection(resources []Resource) (Collection, error)

CreateCollection creates a map from

func (Collection) DependencyGraph added in v0.3.0

func (c Collection) DependencyGraph() (*graph.Graph, error)

DependencyGraph builds a dependency graph for the collection

type Config

type Config struct {
	// The site repo which contains module and data files
	SiteRepo string

	// Logger used by the resources to log events
	Logger *log.Logger
}

Config type contains various settings used by the resources

type Datacenter added in v0.5.0

type Datacenter struct {
	BaseVSphere
}

Datacenter type is a resource which manages datacenters in a VMware vSphere environment.

Example:

dc = vsphere.datacenter.new("my-datacenter")
dc.endpoint = "https://vc01.example.org/sdk"
dc.username = "root"
dc.password = "myp4ssw0rd"
dc.insecure = true
dc.state = "present"
dc.path = "/SomePath"

func (*Datacenter) Create added in v0.5.0

func (d *Datacenter) Create() error

Create creates a new datacenter.

func (*Datacenter) Delete added in v0.5.0

func (d *Datacenter) Delete() error

Delete removes the datacenter.

func (*Datacenter) Evaluate added in v0.5.0

func (d *Datacenter) Evaluate() (State, error)

Evaluate evaluates the state of the datacenter.

type DatastoreNfs added in v0.5.0

type DatastoreNfs struct {
	BaseVSphere

	// Hosts is the list of ESXi hosts on which to manage the NFS datastore.
	Hosts []string `luar:"hosts"`

	// NfsServer is the remote NFS server to use when mounting the datastore.
	NfsServer string `luar:"nfs_server"`

	// NfsType specifies the type of the NFS volume.
	// Valid values are "NFS" for v3 and "NFS41" for v4.1.
	// Defaults to "NFS".
	NfsType string `luar:"nfs_type"`

	// NfsPath is the remote path of the NFS mount point.
	NfsPath string `luar:"nfs_path"`

	// Mode is the access mode for the datastore.
	// Valid values are "readOnly" and "readWrite".
	// Defaults to "readWrite".
	Mode string `luar:"mode"`
	// contains filtered or unexported fields
}

DatastoreNfs type is a resource which manages NFS datastores on ESXi hosts.

Example:

datastore = vsphere.datastore_nfs.new("vm-storage01")
datastore.endpoint = "https://vc01.example.org/sdk"
datastore.username = "root"
datastore.password = "myp4ssw0rd"
datastore.state = "present"
datastore.path = "/MyDatacenter/datastore"
datastore.hosts = {
   "/MyDatacenter/host/MyCluster/esxi01.example.org",
   "/MyDatacenter/host/MyCluster/esxi02.example.org",
}
datastore.nfs_server = "nfs01.example.org"
datastore.nfs_type = "NFS",
datastore.nfs_path = "/exported/file/system",
datastore.mode = "readWrite"

func (*DatastoreNfs) Create added in v0.5.0

func (ds *DatastoreNfs) Create() error

Create mounts the NFS datastore on the ESXi hosts.

func (*DatastoreNfs) Delete added in v0.5.0

func (ds *DatastoreNfs) Delete() error

Delete unmounts the NFS datastore from the ESXi hosts.

func (*DatastoreNfs) Evaluate added in v0.5.0

func (ds *DatastoreNfs) Evaluate() (State, error)

Evaluate evaluates the state of the datastore.

func (*DatastoreNfs) Validate added in v0.5.0

func (ds *DatastoreNfs) Validate() error

Validate validates the datastore resource.

type Directory added in v0.5.0

type Directory struct {
	BaseFile

	// Parents flag specifies whether or not to create/delete
	// parent directories. Defaults to false.
	Parents bool `luar:"parents"`
}

Directory resource manages directories.

Example:

bar = resource.directory.new("/tmp/bar")
bar.state = "present"
bar.mode = tonumber("0700", 8)
bar.owner = "root"
bar.group = "wheel"

func (*Directory) Create added in v0.5.0

func (d *Directory) Create() error

Create creates the directory.

func (*Directory) Delete added in v0.5.0

func (d *Directory) Delete() error

Delete removes the directory.

func (*Directory) Evaluate added in v0.5.0

func (d *Directory) Evaluate() (State, error)

Evaluate evaluates the state of the directory.

type File added in v0.3.0

type File struct {
	BaseFile

	// Content of file to set.
	Content []byte `luar:"content"`

	// Source file to use for the file content.
	Source string `luar:"source"`
}

File resource manages files.

Example:

foo = resource.file.new("/tmp/foo")
foo.state = "present"
foo.mode = tonumber("0600", 8)
foo.owner = "root"
foo.group = "wheel"
foo.content = "content of file foo"

func (*File) Create added in v0.3.0

func (f *File) Create() error

Create creates the file managed by the resource.

func (*File) Delete added in v0.3.0

func (f *File) Delete() error

Delete deletes the file managed by the resource.

func (*File) Evaluate added in v0.3.0

func (f *File) Evaluate() (State, error)

Evaluate evaluates the state of the file resource.

func (*File) Initialize added in v0.5.0

func (f *File) Initialize() error

Initialize initializes the file resource.

func (*File) Validate added in v0.4.0

func (f *File) Validate() error

Validate validates the file resource.

type FunctionItem added in v0.5.0

type FunctionItem struct {
	// Name of the function to register in Lua
	Name string

	// Namespace is the Lua table where the function will be registered to
	Namespace string

	// Function to execute when called from Lua
	Function interface{}
}

FunctionItem type represents a single item from the function registry.

type Host added in v0.5.0

type Host struct {
	BaseVSphere

	// LockdownMode flag specifies whether to enable or
	// disable lockdown mode of the host.
	// This feature is available only on ESXi 6.0 or above.
	// Valid values that can be set are "lockdownDisabled",
	// "lockdownNormal" and "lockdownStrict". Refer to the
	// official VMware vSphere API reference for more details and
	// explanation of each setting. Defaults to an empty string.
	LockdownMode types.HostLockdownMode `luar:"lockdown_mode"`

	// Dns configuration settings for the host.
	Dns *HostDnsConfig `luar:"dns"`
}

Host type is a resource which manages settings of the ESXi hosts in a VMware vSphere environment.

Example:

host = vsphere.host.new("esxi01.example.org")
host.endpoint = "https://vc01.example.org/sdk"
host.username = "root"
host.password = "myp4ssw0rd"
host.path = "/MyDatacenter/host/MyCluster"
host.state = "present"
host.lockdown_mode = "lockdownNormal"
host.dns = {
   servers = { "1.2.3.4", "2.3.4.5" },
   domain = "example.org",
   hostname = "esxi01",
   search = { "example.org" },
}

func (*Host) Create added in v0.5.0

func (h *Host) Create() error

Create is a no-op. Adding hosts to the VMware vCenter server is done by using the ClusterHost resource type.

func (*Host) Delete added in v0.5.0

func (h *Host) Delete() error

Delete disconnects the host and then removes it.

func (*Host) Evaluate added in v0.5.0

func (h *Host) Evaluate() (State, error)

type HostDnsConfig added in v0.5.0

type HostDnsConfig struct {
	// DHCP flag is used to indicate whether or not DHCP is used to
	// determine DNS settings.
	DHCP bool `luar:"dhcp"`

	// Servers is the list of DNS servers to use.
	Servers []string `luar:"servers"`

	// Domain name portion of the DNS name.
	Domain string `luar:"domain"`

	// Hostname portion of the DNS name.
	Hostname string `luar:"hostname"`

	// Search list for hostname lookup.
	Search []string `luar:"search"`
}

HostDnsConfig type provides information about the DNS settings used by the ESXi host.

type Link struct {
	BaseFile

	// Source file points to the file the link will be set to.
	Source string `luar:"source"`

	// Hard flag specifies whether or not to create a hard link to the file.
	// Defaults to false.
	Hard bool `luar:"hard"`
}

Link resource manages links between files.

Example:

baz = resource.link.new("/tmp/baz")
baz.state = "present"
baz.source = "/tmp/qux"

func (*Link) Create added in v0.5.0

func (l *Link) Create() error

Create creates the link.

func (*Link) Delete added in v0.5.0

func (l *Link) Delete() error

Delete removes the link.

func (*Link) Evaluate added in v0.5.0

func (l *Link) Evaluate() (State, error)

Evaluate evaluates the state of the link.

func (*Link) Validate added in v0.5.0

func (l *Link) Validate() error

Validate validates the link resource.

type Pacman added in v0.3.0

type Pacman struct {
	BasePackage
}

Pacman type represents the resource for package management on Arch Linux systems.

Example:

pkg = resource.pacman.new("tmux")
pkg.state = "installed"

type PkgNG added in v0.5.0

type PkgNG struct {
	BasePackage
}

PkgNG type represents the resource for package management on FreeBSD 9.2+ and DragonflyBSD 4.3+ systems.

Pkg is not automatically bootstrapped - resource will fail, if pkg is not installed.

Example:

pkg = resource.pkgng.new("mc")
pkg.state = "installed"

type Property added in v0.5.0

type Property interface {
	// Name returns the property name
	Name() string

	// Set sets the property to it's desired state.
	Set() error

	// IsSynced returns a boolean indicating whether the
	// resource property is in sync or not.
	IsSynced() (bool, error)
}

Property type represents a resource property, which can be evaluated and set if outdated.

type PropertyIsSyncedFunc added in v0.5.0

type PropertyIsSyncedFunc func() (bool, error)

PropertyIsSyncedFunc is the type of the function that is called when determining whether a resource property is in the desired state.

func (PropertyIsSyncedFunc) IsSynced added in v0.5.0

func (f PropertyIsSyncedFunc) IsSynced() (bool, error)

IsSynced returns a boolean indicating whether the resource property is in the desired state.

type PropertySetFunc added in v0.5.0

type PropertySetFunc func() error

PropertySetFunc is the type of the function that is called when setting a resource property to it's desired state.

func (PropertySetFunc) Set added in v0.5.0

func (f PropertySetFunc) Set() error

Set sets the property to it's desired state.

type Provider

type Provider func(name string) (Resource, error)

Provider type is the type which creates new resources

type ProviderItem added in v0.5.0

type ProviderItem struct {
	// Type name of the provider
	Type string

	// Provider is the actual resource provider
	Provider Provider

	// Namespace represents the Lua table that the
	// provider will be registered in
	Namespace string
}

ProviderItem type represents a single item from the provider registry.

type Resource

type Resource interface {
	// ID returns the unique identifier of the resource
	ID() string

	// Initialize is used to perform any initialization prior the
	// actual resource processing, e.g. establish connection to a
	// remote API endpoint.
	Initialize() error

	// Close performs any cleanup tasks after a resource has been processed.
	Close() error

	// Validate validates the resource
	Validate() error

	// Dependencies returns the list of resource dependencies.
	// Each item in the slice is a string representing the
	// resource id for each dependency.
	Dependencies() []string

	// PresentStates returns the list of states, for which the
	// resource is considered to be present
	PresentStates() []string

	// AbsentStates returns the list of states, for which the
	// resource is considered to be absent
	AbsentStates() []string

	// IsConcurrent returns a boolean, which indicates whether
	// multiple instances of the same resource type can be
	// processed concurrently.
	IsConcurrent() bool

	// Evaluates the resource
	Evaluate() (State, error)

	// Creates the resource
	Create() error

	// Deletes the resource
	Delete() error

	// Properties returns the list of properties for the resource.
	Properties() []Property

	// SubscribedTo returns a map of the resource ids for which the
	// current resource subscribes for changes to. The keys of the
	// map are resource ids and their values are the functions to be
	// executed if the resource state changes.
	SubscribedTo() TriggerMap
}

Resource is the interface type for resources.

func NewCluster added in v0.5.0

func NewCluster(name string) (Resource, error)

NewCluster creates a new resource for managing clusters in a VMware vSphere environment.

func NewClusterHost added in v0.5.0

func NewClusterHost(name string) (Resource, error)

NewClusterHost creates a new resource for managing hosts in a VMware vSphere cluster.

func NewDatacenter added in v0.5.0

func NewDatacenter(name string) (Resource, error)

NewDatacenter creates a new resource for managing datacenters in a VMware vSphere environment.

func NewDatastoreNfs added in v0.5.0

func NewDatastoreNfs(name string) (Resource, error)

NewDatastoreNfs creates a new resource for managing NFS datastores on ESXi hosts.

func NewDirectory added in v0.5.0

func NewDirectory(name string) (Resource, error)

NewDirectory creates a resource for managing directories.

func NewFile added in v0.3.0

func NewFile(name string) (Resource, error)

NewFile creates a resource for managing regular files.

func NewHost added in v0.5.0

func NewHost(name string) (Resource, error)

NewHost creates a new resource for managing ESXi host settings.

func NewLink(name string) (Resource, error)

NewLink creates a new resource for managing links between files.

func NewPackage added in v0.3.0

func NewPackage(name string) (Resource, error)

NewPackage creates a new resource for managing packages. This provider tries to determine the most appropriate package provider for you, so it is more like a meta-provider.

Example:

pkg = resource.package.new("tmux")
pkg.state = "installed"

func NewPacman added in v0.3.0

func NewPacman(name string) (Resource, error)

NewPacman creates a new resource for managing packages using the pacman package manager on an Arch Linux system

func NewPkgNG added in v0.5.0

func NewPkgNG(name string) (Resource, error)

NewPkgNG creates a new resource for managing packages.

func NewService added in v0.3.0

func NewService(name string) (Resource, error)

NewService creates a new resource for managing services using systemd on a GNU/Linux system

func NewShell added in v0.3.0

func NewShell(name string) (Resource, error)

NewShell creates a new resource for executing shell commands

func NewVirtualMachine added in v0.5.0

func NewVirtualMachine(name string) (Resource, error)

NewVirtualMachine creates a new resource for managing virtual machines in a vSphere environment.

func NewYum added in v0.3.0

func NewYum(name string) (Resource, error)

NewYum creates a new resource for managing packages using the yum package manager on RHEL and CentOS systems

type ResourceProperty added in v0.5.0

type ResourceProperty struct {
	PropertySetFunc
	PropertyIsSyncedFunc

	// PropertyName is the name of the property.
	PropertyName string
}

ResourceProperty type implements the Property interface.

func (*ResourceProperty) Name added in v0.5.0

func (rp *ResourceProperty) Name() string

Name returns the property name.

type Service added in v0.3.0

type Service struct {
	Base

	// Enable specifies whether to enable or disable the
	// service during boot-time. Defaults to true.
	Enable bool `luar:"enable"`
	// contains filtered or unexported fields
}

Service type is a resource which manages services on a GNU/Linux system running with systemd.

Example:

svc = resource.service.new("nginx")
svc.state = "running"
svc.enable = true

func (*Service) Close added in v0.5.0

func (s *Service) Close() error

Close closes the connection to the systemd D-BUS API

func (*Service) Create added in v0.3.0

func (s *Service) Create() error

Create starts the service.

func (*Service) Delete added in v0.3.0

func (s *Service) Delete() error

Delete stops the service.

func (*Service) Evaluate added in v0.3.0

func (s *Service) Evaluate() (State, error)

Evaluate evaluates the state of the resource

func (*Service) Initialize added in v0.5.0

func (s *Service) Initialize() error

Initialize initializes the service resource by establishing a connection the systemd D-BUS API

type Shell added in v0.3.0

type Shell struct {
	Base

	// Command to be executed. Defaults to the resource name.
	Command string `luar:"command"`

	// File to be checked for existence before executing the command.
	Creates string `luar:"creates"`

	// Mute flag indicates whether output from the command should be
	// dislayed or suppressed
	Mute bool `luar:"mute"`
}

Shell type is a resource which executes shell commands.

The command that is to be executed should be idempotent. If the command that is to be executed is not idempotent on it's own, in order to achieve idempotency of the resource you should set the "creates" field to a filename that can be checked for existence.

Example:

sh = resource.shell.new("touch /tmp/foo")
sh.creates = "/tmp/foo"

Same example as the above one, but written in a different way.

Example:

sh = resource.shell.new("creates the /tmp/foo file")
sh.command = "/usr/bin/touch /tmp/foo"
sh.creates = "/tmp/foo"

func (*Shell) Create added in v0.3.0

func (s *Shell) Create() error

Create executes the shell command

func (*Shell) Delete added in v0.3.0

func (s *Shell) Delete() error

Delete is a no-op

func (*Shell) Evaluate added in v0.3.0

func (s *Shell) Evaluate() (State, error)

Evaluate evaluates the state of the resource

func (*Shell) Update added in v0.3.0

func (s *Shell) Update() error

Update is a no-op

type State

type State struct {
	// Current state of the resource
	Current string

	// Wanted state of the resource
	Want string

	// Outdated indicates that a property of the resource is out of date
	Outdated bool
}

State type represents the current and wanted states of a resource

type TriggerMap added in v0.5.0

type TriggerMap map[string]*lua.LFunction

TriggerMap type is a map type which keys are resource ids for which a resource subscribes for changes to. The keys of the map are Lua functions that would be executed when the resource state has changed.

type VirtualMachine added in v0.5.0

type VirtualMachine struct {
	BaseVSphere

	// Hardware is the virtual machine hardware configuration.
	Hardware *VirtualMachineHardware `luar:"hardware"`

	// ExtraConfig is the extra configuration of the virtual mahine.
	ExtraConfig *VirtualMachineExtraConfig `luar:"extra_config"`

	// TemplateConfig specifies configuration settings to use
	// when creating the virtual machine from a template.
	TemplateConfig *VirtualMachineTemplateConfig `luar:"template_config"`

	// GuestID is the short guest operating system identifier.
	// Defaults to otherGuest.
	GuestID string `luar:"guest_id"`

	// Annotation of the virtual machine.
	Annotation string `luar:"annotation"`

	// MaxMksConnections is the maximum number of
	// mouse-keyboard-screen connections allowed to the
	// virtual machine. Defaults to 8.
	MaxMksConnections int32 `luar:"max_mks"`

	// Host is the target host to place the virtual machine on.
	// Can be empty if the selected resource pool is a
	// vSphere cluster with DRS enabled in fully automated mode.
	Host string `luar:"host"`

	// Pool is the target resource pool to place the virtual
	// machine on.
	Pool string `luar:"pool"`

	// Datastore is the datastore where the virtual machine
	// disk will be placed.
	//
	// TODO: Update this property, so that multiple disks
	// can be specified, each with their own datastore path.
	Datastore string `luar:"datastore"`

	// PowerState specifies the power state of the virtual machine.
	// Valid vSphere power states are "poweredOff", "poweredOn" and
	// "suspended".
	PowerState types.VirtualMachinePowerState `luar:"power_state"`

	// WaitForIP specifies whether to wait the virtual machine
	// to get an IP address after a powerOn operation.
	// Defaults to false.
	WaitForIP bool `luar:"wait_for_ip"`
}

VirtualMachine type is a resource which manages Virtual Machines in a VMware vSphere environment.

Example:

vm = vsphere.vm.new("my-test-vm")
vm.endpoint = "https://vc01.example.org/sdk"
vm.username = "root"
vm.password = "myp4ssw0rd"
vm.state = "present"
vm.path = "/MyDatacenter/vm"
vm.pool = "/MyDatacenter/host/MyCluster"
vm.datastore = "/MyDatacenter/datastore/vm-storage"
vm.host = "/MyDatacenter/host/MyCluster/esxi01.example.org"
vm.hardware = {
  cpu = 1,
  cores = 1,
  memory = 1024,
  version = "vmx-08",
}
vm.guest_id = "otherGuest"
vm.annotation = "my brand new virtual machine"
vm.max_mks = 10
vm.extra_config = {
  cpu_hotadd = true,
  cpu_hotremove = true,
  memory_hotadd = true
}
vm.power_state = "poweredOn"
vm.wait_for_ip = true

Example:

vm = vsphere.vm.new("my-cloned-vm")
vm.endpoint = "https://vc01.example.org/sdk"
vm.username = "root"
vm.password = "myp4ssw0rd"
vm.state = "present"
vm.path = "/MyDatacenter/vm"
vm.pool = "/MyDatacenter/host/MyCluster"
vm.datastore = "/MyDatacenter/datastore/vm-storage"
vm.template_config = {
  use = "/Templates/my-vm-template",
  power_on = true,
  mark_as_template = false,
}

Example:

vm = vsphere.vm.new("vm-to-be-deleted")
vm.endpoint = "https://vc01.example.org/sdk"
vm.username = "root"
vm.password = "myp4ssw0rd"
vm.state = "absent"
vm.path = "/MyDatacenter/vm"

func (*VirtualMachine) Create added in v0.5.0

func (vm *VirtualMachine) Create() error

Create creates the virtual machine.

func (*VirtualMachine) Delete added in v0.5.0

func (vm *VirtualMachine) Delete() error

Delete removes the virtual machine.

func (*VirtualMachine) Evaluate added in v0.5.0

func (vm *VirtualMachine) Evaluate() (State, error)

Evaluate evaluates the state of the virtual machine.

func (*VirtualMachine) Validate added in v0.5.0

func (vm *VirtualMachine) Validate() error

Validate validates the virtual machine resource.

type VirtualMachineExtraConfig added in v0.5.0

type VirtualMachineExtraConfig struct {
	// CpuHotAdd flag specifies whether or not to enable the
	// cpu hot-add feature for the virtual machine.
	// Defaults to false.
	CpuHotAdd bool `luar:"cpu_hotadd"`

	// CpuHotRemove flag specifies whether or not to enable the
	// cpu hot-remove feature for the virtual machine.
	// Defaults to false.
	CpuHotRemove bool `luar:"cpu_hotremove"`

	// MemoryHotAdd flag specifies whether or not to enable the
	// memory hot-add feature for the virtual machine.
	// Defaults to false.
	MemoryHotAdd bool `luar:"memory_hotadd"`
}

VirtualMachineExtraConfig type represents extra configuration of the vSphere virtual machine.

type VirtualMachineHardware added in v0.5.0

type VirtualMachineHardware struct {
	// Cpu is the number of CPUs of the Virtual Machine.
	Cpu int32 `luar:"cpu"`

	// Cores is the number of cores per socket.
	Cores int32 `luar:"cores"`

	// Memory is the size of memory.
	Memory int64 `luar:"memory"`

	// Version is the hardware version of the virtual machine.
	Version string `luar:"version"`
}

VirtualMachineHardware type represents the hardware configuration of a vSphere virtual machine.

type VirtualMachineTemplateConfig added in v0.5.0

type VirtualMachineTemplateConfig struct {
	// Use specifies the source template to use when creating the
	// virtual machine.
	Use string `luar:"use"`

	// PowerOn specifies whether to power on the virtual machine
	// after cloning it from the template.
	PowerOn bool `luar:"power_on"`

	// MarkAsTemplate flag specifies whether the virtual machine will be
	// marked as template after creation.
	MarkAsTemplate bool `luar:"mark_as_template"`
}

VirtualMachineTemplateConfig type represents configuration settings of the virtual machine when using a template for creating the virtual machine.

type Yum added in v0.3.0

type Yum struct {
	BasePackage
}

Yum type represents the resource for package management on RHEL and CentOS systems.

Example:

pkg = resource.yum.new("emacs")
pkg.state = "installed"

Jump to

Keyboard shortcuts

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