gru: github.com/dnaeon/gru/resource Index | Files

package resource

import "github.com/dnaeon/gru/resource"

Index

Package Files

collection.go file.go lua.go package.go property.go provider.go resource.go service_linux.go shell.go vsphere.go vsphere_cluster.go vsphere_cluster_host.go vsphere_datacenter.go vsphere_datastore.go vsphere_host.go vsphere_vm.go

Constants

const DefaultFunctionNamespace = "stdlib"

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

const DefaultResourceNamespace = "resource"

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

const VSphereNamespace = "vsphere"

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

Variables

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

DefaultConfig is the default configuration used by the resources

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

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

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

ErrInvalidName error is returned when a resource name is invalid

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

ErrInvalidType error is returned when a resource type is invalid

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

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

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

ErrNoPackageProviderFound is returned when no suitable provider is found

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.

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

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

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.

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.

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

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

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.

func Logf Uses

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

Logf writes an event to the default logger.

func LuaRegisterBuiltin Uses

func LuaRegisterBuiltin(L *lua.LState)

LuaRegisterBuiltin registers resource providers and functions in Lua.

func RegisterFunction Uses

func RegisterFunction(items ...FunctionItem)

RegisterFunction registers a function to the registry.

func RegisterProvider Uses

func RegisterProvider(items ...ProviderItem)

RegisterProvider registers a provider to the registry.

type Base Uses

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 Uses

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

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

func (*Base) Close Uses

func (b *Base) Close() error

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

func (*Base) Dependencies Uses

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

Dependencies returns the list of resource dependencies.

func (*Base) ID Uses

func (b *Base) ID() string

ID returns the unique resource id

func (*Base) Initialize Uses

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 Uses

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 Uses

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

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

func (*Base) Properties Uses

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

Properties returns the list of properties for the resource.

func (*Base) SubscribedTo Uses

func (b *Base) SubscribedTo() TriggerMap

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

func (*Base) Validate Uses

func (b *Base) Validate() error

Validate validates the resource

type BaseFile Uses

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 Uses

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 Uses

func (bp *BasePackage) Create() error

Create installs the package

func (*BasePackage) Delete Uses

func (bp *BasePackage) Delete() error

Delete deletes the package

func (*BasePackage) Evaluate Uses

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

Evaluate evaluates the state of the package

func (*BasePackage) Update Uses

func (bp *BasePackage) Update() error

Update updates the package

type BaseVSphere Uses

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 Uses

func (bv *BaseVSphere) Close() error

Close closes the connection to the remote vSphere API endpoint.

func (*BaseVSphere) ID Uses

func (bv *BaseVSphere) ID() string

ID returns the unique resource id for the resource

func (*BaseVSphere) Initialize Uses

func (bv *BaseVSphere) Initialize() error

Initialize establishes a connection to the remote vSphere API endpoint.

func (*BaseVSphere) Validate Uses

func (bv *BaseVSphere) Validate() error

Validate validates the resource.

type Cluster Uses

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 Uses

func (c *Cluster) Create() error

Create creates a new cluster.

func (*Cluster) Delete Uses

func (c *Cluster) Delete() error

Delete removes the cluster.

func (*Cluster) Evaluate Uses

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

Evaluate evalutes the state of the cluster.

type ClusterConfig Uses

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 Uses

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 Uses

func (ch *ClusterHost) Create() error

Create adds the host to the cluster.

func (*ClusterHost) Delete Uses

func (ch *ClusterHost) Delete() error

Delete disconnects the host and then removes it.

func (*ClusterHost) Evaluate Uses

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

Evaluate evaluates the state of the host in the cluster.

type Collection Uses

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 Uses

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

CreateCollection creates a map from

func (Collection) DependencyGraph Uses

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

DependencyGraph builds a dependency graph for the collection

type Config Uses

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 Uses

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 Uses

func (d *Datacenter) Create() error

Create creates a new datacenter.

func (*Datacenter) Delete Uses

func (d *Datacenter) Delete() error

Delete removes the datacenter.

func (*Datacenter) Evaluate Uses

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

Evaluate evaluates the state of the datacenter.

type DatastoreNfs Uses

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 Uses

func (ds *DatastoreNfs) Create() error

Create mounts the NFS datastore on the ESXi hosts.

func (*DatastoreNfs) Delete Uses

func (ds *DatastoreNfs) Delete() error

Delete unmounts the NFS datastore from the ESXi hosts.

func (*DatastoreNfs) Evaluate Uses

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

Evaluate evaluates the state of the datastore.

func (*DatastoreNfs) Validate Uses

func (ds *DatastoreNfs) Validate() error

Validate validates the datastore resource.

type Directory Uses

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 Uses

func (d *Directory) Create() error

Create creates the directory.

func (*Directory) Delete Uses

func (d *Directory) Delete() error

Delete removes the directory.

func (*Directory) Evaluate Uses

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

Evaluate evaluates the state of the directory.

type File Uses

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 Uses

func (f *File) Create() error

Create creates the file managed by the resource.

func (*File) Delete Uses

func (f *File) Delete() error

Delete deletes the file managed by the resource.

func (*File) Evaluate Uses

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

Evaluate evaluates the state of the file resource.

func (*File) Initialize Uses

func (f *File) Initialize() error

Initialize initializes the file resource.

func (*File) Validate Uses

func (f *File) Validate() error

Validate validates the file resource.

type FunctionItem Uses

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 Uses

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 Uses

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 Uses

func (h *Host) Delete() error

Delete disconnects the host and then removes it.

func (*Host) Evaluate Uses

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

Evaluate evaluate the state of the ESXi host.

type HostDnsConfig Uses

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 Uses

func (l *Link) Create() error

Create creates the link.

func (*Link) Delete Uses

func (l *Link) Delete() error

Delete removes the link.

func (*Link) Evaluate Uses

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

Evaluate evaluates the state of the link.

func (*Link) Validate Uses

func (l *Link) Validate() error

Validate validates the link resource.

type Pacman Uses

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 Uses

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 Uses

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 needed.

type Provider Uses

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

Provider type is the type which creates new resources

type ProviderItem Uses

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 Uses

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 Uses

func NewCluster(name string) (Resource, error)

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

func NewClusterHost Uses

func NewClusterHost(name string) (Resource, error)

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

func NewDatacenter Uses

func NewDatacenter(name string) (Resource, error)

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

func NewDatastoreNfs Uses

func NewDatastoreNfs(name string) (Resource, error)

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

func NewDirectory Uses

func NewDirectory(name string) (Resource, error)

NewDirectory creates a resource for managing directories.

func NewFile Uses

func NewFile(name string) (Resource, error)

NewFile creates a resource for managing regular files.

func NewHost Uses

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 Uses

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 Uses

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 Uses

func NewPkgNG(name string) (Resource, error)

NewPkgNG creates a new resource for managing packages.

func NewService Uses

func NewService(name string) (Resource, error)

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

func NewShell Uses

func NewShell(name string) (Resource, error)

NewShell creates a new resource for executing shell commands

func NewVirtualMachine Uses

func NewVirtualMachine(name string) (Resource, error)

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

func NewYum Uses

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 Uses

type ResourceProperty struct {
    // PropertySetFunc is the type of the function that is called when
    // setting a resource property to it's desired state.
    PropertySetFunc func() error

    // PropertyIsSyncedFunc is the type of the function that is called when
    // determining whether a resource property is in the desired state.
    PropertyIsSyncedFunc func() (bool, error)

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

ResourceProperty type implements the Property interface.

func (*ResourceProperty) IsSynced Uses

func (rp *ResourceProperty) IsSynced() (bool, error)

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

func (*ResourceProperty) Name Uses

func (rp *ResourceProperty) Name() string

Name returns the property name.

func (*ResourceProperty) Set Uses

func (rp *ResourceProperty) Set() error

Set sets the property to it's desired state.

type Service Uses

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 Uses

func (s *Service) Close() error

Close closes the connection to the systemd D-BUS API

func (*Service) Create Uses

func (s *Service) Create() error

Create starts the service.

func (*Service) Delete Uses

func (s *Service) Delete() error

Delete stops the service.

func (*Service) Evaluate Uses

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

Evaluate evaluates the state of the resource

func (*Service) Initialize Uses

func (s *Service) Initialize() error

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

type Shell Uses

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 Uses

func (s *Shell) Create() error

Create executes the shell command

func (*Shell) Delete Uses

func (s *Shell) Delete() error

Delete is a no-op

func (*Shell) Evaluate Uses

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

Evaluate evaluates the state of the resource

func (*Shell) Update Uses

func (s *Shell) Update() error

Update is a no-op

type State Uses

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

    // Wanted state of the resource
    Want string
}

State type represents the current and wanted states of a resource

type TriggerMap Uses

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 Uses

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 Uses

func (vm *VirtualMachine) Create() error

Create creates the virtual machine.

func (*VirtualMachine) Delete Uses

func (vm *VirtualMachine) Delete() error

Delete removes the virtual machine.

func (*VirtualMachine) Evaluate Uses

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

Evaluate evaluates the state of the virtual machine.

func (*VirtualMachine) Validate Uses

func (vm *VirtualMachine) Validate() error

Validate validates the virtual machine resource.

type VirtualMachineExtraConfig Uses

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 Uses

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 Uses

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 Uses

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"

Package resource imports 27 packages (graph) and is imported by 2 packages. Updated 2017-02-20. Refresh now. Tools for package owners.