Module std¶
License: Apache 2.0
Version: 2.0.0
Author: Inmanta <code@inmanta.com>
This module requires compiler version 2020.1 or higher
Upstream project: https://github.com/inmanta/std.git
Typedefs¶
-
typedef
std::alfanum
¶ Base type
string
Type constraint
(std::validate_type('pydantic.constr',self,Dict()) == true)
-
typedef
std::any_http_url
¶ Base type
string
Type constraint
(std::validate_type('pydantic.AnyHttpUrl',self) == true)
-
typedef
std::any_url
¶ Base type
string
Type constraint
(std::validate_type('pydantic.AnyUrl',self) == true)
-
typedef
std::ascii_word
¶ Base type
string
Type constraint
(std::validate_type('pydantic.constr',self,Dict()) == true)
-
typedef
std::base64
¶ Base type
string
Type constraint
(std::is_base64_encoded(self) == true)
-
typedef
std::config_agent
¶ Base type
string
Type constraint
(self != 'internal')
-
typedef
std::date
¶ Base type
string
Type constraint
(std::validate_type('datetime.date',self) == true)
-
typedef
std::datetime
¶ Base type
string
Type constraint
(std::validate_type('datetime.datetime',self) == true)
-
typedef
std::email_str
¶ Base type
string
Type constraint
(std::validate_type('pydantic.EmailStr',self) == true)
-
typedef
std::hoststring
¶ Base type
string
Type constraint
/^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/
-
typedef
std::http_url
¶ Base type
string
Type constraint
(std::validate_type('pydantic.HttpUrl',self) == true)
-
typedef
std::ipv4_address
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv4Address',self) == true)
-
typedef
std::ipv4_interface
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv4Interface',self) == true)
-
typedef
std::ipv4_network
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv4Network',self) == true)
-
typedef
std::ipv6_address
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv6Address',self) == true)
-
typedef
std::ipv6_interface
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv6Interface',self) == true)
-
typedef
std::ipv6_network
¶ Base type
string
Type constraint
(std::validate_type('ipaddress.IPv6Network',self) == true)
-
typedef
std::ipv_any_address
¶ Base type
string
Type constraint
(std::validate_type('pydantic.IPvAnyAddress',self) == true)
-
typedef
std::ipv_any_interface
¶ Base type
string
Type constraint
(std::validate_type('pydantic.IPvAnyInterface',self) == true)
-
typedef
std::ipv_any_network
¶ Base type
string
Type constraint
(std::validate_type('pydantic.IPvAnyNetwork',self) == true)
-
typedef
std::name_email
¶ Base type
string
Type constraint
(std::validate_type('pydantic.NameEmail',self) == true)
-
typedef
std::negative_float
¶ Base type
number
Type constraint
(std::validate_type('pydantic.NegativeFloat',self) == true)
-
typedef
std::negative_int
¶ Base type
int
Type constraint
(std::validate_type('pydantic.NegativeInt',self) == true)
-
typedef
std::package_state
¶ Base type
string
Type constraint
(((self == 'installed') or (self == 'removed')) or (self == 'latest'))
-
typedef
std::positive_float
¶ Base type
number
Type constraint
(std::validate_type('pydantic.PositiveFloat',self) == true)
-
typedef
std::positive_int
¶ Base type
int
Type constraint
(std::validate_type('pydantic.PositiveInt',self) == true)
-
typedef
std::printable_ascii
¶ Base type
string
Type constraint
(std::validate_type('pydantic.constr',self,Dict()) == true)
-
typedef
std::service_state
¶ Base type
string
Type constraint
((self == 'running') or (self == 'stopped'))
-
typedef
std::time
¶ Base type
string
Type constraint
(std::validate_type('datetime.time',self) == true)
-
typedef
std::uuid
¶ Base type
string
Type constraint
(std::validate_type('uuid.UUID',self) == true)
Entities¶
-
entity
std::AgentConfig
¶ Parents:
std::PurgeableResource
Control agent settings. Currently these settings are only applied to autostarted agents
-
attribute bool?
autostart
¶ When this flag is set to true, the resource will be exported and set the agent map on the orchestrator. When false (or not set), this instance is ignore but can be used to generate agent configuration files.
-
attribute std::config_agent
agentname
¶ The name of the agent to which this config applies.
-
attribute string
agent
='internal'¶ If a resource is exported, agent manages the resource.
-
attribute string
uri
='local:'¶ The uri that indicates how the agent should execute. Currently the following uri are supported: * “” An empty string. This is the same as running it locally * local: Manage resource locally * ssh://[user@]hostname[:port] Login using ssh. When user is left out, root is assumed. For port, the system default is used. * host The actual hostname or ip to use. Altough this is not a valid host in uri form it is supported. * A query string can be used to set the properties: * python: The python interpreter to use. The default value is python * retries: The number of retries before giving up. The default number of retries 10 * retry_wait: The time to wait between retries for the remote target to become available. The default wait is 30s. Example: ssh://centos@centos-machine/?python=python3 (This would connect to a the centos machine and use python3 as it’s interpreter)
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
attribute bool?
-
entity
std::ConfigFile
¶ Parents:
std::File
A file with often used defaults for configuration files.
-
attribute number
mode
=644¶
-
attribute string
owner
='root'¶
-
attribute string
group
='root'¶
The following implements statements select implementations for this entity:
std::reload
,std::fileHost
constrainttrue
-
attribute number
-
entity
std::Content
¶ Parents:
std::Entity
A content block as a prefix or suffix to a file. This blocks are only merged with the content at export time. This is an advanced pattern that can be used to speed up the compilation in very specific use cases.
-
attribute string?
sorting_key
=null¶ The key to use to sort the content blocks in the same list. When this attribute is not set value is used as sorting key.
-
attribute string
value
¶ The value to prepend or append
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
attribute string?
-
entity
std::DefaultDirectory
¶ Parents:
std::Directory
A directory that is world readable. It is also writable for its owner root.
-
attribute number
mode
=755¶
-
attribute string
owner
='root'¶
-
attribute string
group
='root'¶
The following implements statements select implementations for this entity:
std::reload
,std::dirHost
constrainttrue
-
attribute number
-
entity
std::Directory
¶ Parents:
std::Reload
,std::PurgeableResource
A directory on the filesystem
-
attribute string
path
¶
-
attribute number
mode
¶
-
attribute string
owner
¶
-
attribute string
group
¶
-
attribute bool
purge_on_delete
=false¶
-
relation std::Host
host
[1]¶ other end:
std::Host.directories [0:*]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::reload
,std::dirHost
constrainttrue
-
attribute string
-
entity
std::Entity
¶ The entity all other entities inherit from.
-
relation std::Entity
requires
[0:*]¶ other end:
std::Entity.provides [0:*]
-
relation std::Entity
provides
[0:*]¶ other end:
std::Entity.requires [0:*]
The following implementations are defined for this entity:
-
relation std::Entity
-
entity
std::File
¶ Parents:
std::Reload
,std::PurgeableResource
This represents a file on the filesystem
-
attribute string
path
¶ The path of the file
-
attribute number
mode
¶ The permissions of the file
-
attribute string
owner
¶ The owner of the file
-
attribute string
group
¶ The group of the file
-
attribute string
content
¶ The file contents
-
attribute bool
purge_on_delete
=false¶
-
attribute bool
send_event
¶
-
attribute string
content_seperator
='\n'¶
-
relation std::Content
prefix_content
[0:*]¶
-
relation std::Content
suffix_content
[0:*]¶
-
relation std::Host
host
[1]¶ other end:
std::Host.files [0:*]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::reload
,std::fileHost
constrainttrue
-
attribute string
-
entity
std::Host
¶ Parents:
std::ManagedDevice
A host models a server of computer in the managed infrastructure
-
relation apt::Repository
repository
[0:*]¶ other end:
apt::Repository.host [1]
-
relation std::File
files
[0:*]¶ other end:
std::File.host [1]
-
relation std::Service
services
[0:*]¶ other end:
std::Service.host [1]
-
relation std::Package
packages
[0:*]¶ other end:
std::Package.host [1]
-
relation std::Directory
directories
[0:*]¶ other end:
std::Directory.host [1]
-
relation std::Symlink
symlinks
[0:*]¶ other end:
std::Symlink.host [1]
-
relation std::OS
os
[1]¶ Each host has an OS defined. This values is mostly used to select implementation in the where clause of an implement statement. The
familyof()
plugin can be used for this.
-
relation std::HostConfig
host_config
[1]¶ other end:
std::HostConfig.host [1]
-
relation std::HostGroup
host_groups
[0:*]¶ other end:
std::HostGroup.hosts [0:*]
-
relation net::Interface
ifaces
[0:*]¶ Host ethernet interface are always placed inside a host
other end:
net::Interface.host [1]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::hostDefaults
constrainttrue
-
relation apt::Repository
-
entity
std::HostConfig
¶ Parents:
std::Entity
This represents generic configuration for a host. This entity is used by other modules to include their host specific configuration. This should be instantiated in the implementation of std::Host or subclasses. This host specific configuration cannot be included by just implementing std::Host because possibly subclasses of std::Host are instantiated and implementations are not inherited.
-
relation std::Host
host
[1]¶ other end:
std::Host.host_config [1]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::none
constrainttrue
redhat::scl::epel7
constraint(std::familyof(host.os,'rhel') and (host.os.version >= 7))
redhat::network::config
constraintstd::familyof(host.os,'redhat')
ip::agentConfig
constraint(host.ip is defined and host.remote_agent)
redhat::epel::epel7
constraint(std::familyof(host.os,'rhel') and (host.os.version >= 7))
-
relation std::Host
-
entity
std::HostGroup
¶ Parents:
std::Entity
This entity represents a group of hosts. For example a cluster of machines.
-
attribute string
name
¶
-
relation std::Host
hosts
[0:*]¶ other end:
std::Host.host_groups [0:*]
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
attribute string
-
entity
std::ManagedDevice
¶ Parents:
std::Entity
This interface represents all devices that can be managed
-
attribute std::hoststring
name
¶
-
attribute std::hoststring
-
entity
std::ManagedResource
¶ Parents:
std::Resource
A base class for a resource that can be ignored/unmanaged by Inmanta.
-
attribute bool
managed
=true¶ This determines whether this resource is managed by Inmanta or not.
-
attribute bool
-
entity
std::MutableBool
¶ Parents:
std::Entity
Wrapper for boolean values, used to pass a boolean out of an if statement.
- Example
attr_a = std::MutableBool() if some_condition: attr_a.value = True else: attr_a.value = Null end
-
attribute bool?
value
¶
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
entity
std::MutableNumber
¶ Parents:
std::Entity
Wrapper for number values, used to pass a number out of an if statement or to use relations to create a mutuable set of numbers.
- Example
attr_a = std::MutableNumber() if some_condition: attr_a.value = 3 else: attr_a.value = 4 end
- Example
entity Test: end Test.string_list [0:] -- std::MutableNumber a = Test() a.string_list += std::MutableNumber(value=3) a.string_list += std::MutableNumber(value=7)
-
attribute number?
value
¶
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
entity
std::MutableString
¶ Parents:
std::Entity
Wrapper for string values. It can be used to pass a string out of an if statement, or to use relations to create a mutuable set of strings.
- Example
attr_a = std::MutableString() if some_condition: attr_a.value = "a" else: attr_a.value = "b" end
- Example
entity Test: end Test.string_list [0:] -- std::MutableString a = Test() a.string_list += std::MutableString(value="value1") a.string_list += std::MutableString(value="value2")
-
attribute string?
value
¶
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
entity
std::OS
¶ Parents:
std::Entity
Defines an operating system
-
attribute string
name
¶ The name of the operating system or family of operating systems
-
attribute number
version
=0¶ A specific version
-
attribute string?
python_cmd
='python'¶ Specifies what command should be used to launch the python interpreter on the other end
-
relation std::OS
member
[0:*]¶ other end:
std::OS.family [0:1]
-
relation std::OS
family
[0:1]¶ other end:
std::OS.member [0:*]
The following implements statements select implementations for this entity:
std::none
constrainttrue
-
attribute string
-
entity
std::Package
¶ Parents:
std::Reload
A software package installed on a managed device.
-
attribute string
name
¶ The name of the package to manage
-
attribute std::package_state
state
¶ The state of the package. Valid values are ‘installed’, ‘removed’ or ‘latest’. latest will upgrade the package when an update is available.
-
relation std::Host
host
[1]¶ other end:
std::Host.packages [0:*]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::reload
,std::pkgHost
constrainttrue
-
attribute string
-
entity
std::PurgeableResource
¶ Parents:
std::Resource
A base class for a resource that can be purged and can be purged by Inmanta whenever the resource is no longer managed.
-
attribute bool
purged
=false¶ Set whether this resource should exist or not.
-
attribute bool
purge_on_delete
=true¶ Purge the resource when it is deleted from the configuration model. When this attribute is true, the server will include a resource with purged=true when this resource is no longer included in the configuration model.
-
attribute bool
-
entity
std::Reload
¶ Parents:
std::Resource
An entity to make the (old) reload mechanism compatible with the event mechanism
-
attribute bool
reload
=false¶ If a service requires this file, reload or restart the service when this file changes.
-
attribute bool
send_event
¶
The following implementations are defined for this entity:
-
attribute bool
-
entity
std::Resource
¶ Parents:
std::Entity
A base entity for resources that can be exported. This type add specific attributes that are common for most handlers. It is not required to inherit from this entity at the moment but highly recommended for documentation purposes.
-
attribute bool
send_event
=false¶ This controls wether a resource should send its deploy state to the resources in its provides.
-
attribute bool
-
entity
std::Service
¶ Parents:
std::Reload
Manage a service on a host.
-
attribute string
name
¶ The name of the service to manage
-
attribute std::service_state
state
¶ The desired state of the service. Valid values are ‘running’ or ‘stopped’
-
attribute bool
onboot
¶ Should the service start on boot.
-
relation std::Host
host
[1]¶ other end:
std::Host.services [0:*]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::reload
,std::serviceHost
constrainttrue
-
attribute string
-
entity
std::Symlink
¶ Parents:
std::Reload
,std::PurgeableResource
A symbolic link on the filesystem
-
attribute string
source
¶
-
attribute string
target
¶
-
attribute bool
purge_on_delete
=false¶
-
attribute bool
send_event
¶
-
relation std::Host
host
[1]¶ other end:
std::Host.symlinks [0:*]
The following implementations are defined for this entity:
The following implements statements select implementations for this entity:
std::reload
,std::symHost
constrainttrue
-
attribute string
Implementations¶
-
implementation
std::dirHost
¶
-
implementation
std::fileHost
¶
-
implementation
std::hostDefaults
¶
-
implementation
std::none
¶ An empty implementation that can be used as a safe default.
-
implementation
std::pkgHost
¶
-
implementation
std::reload
¶
-
implementation
std::serviceHost
¶
-
implementation
std::symHost
¶
Plugins¶
-
std.
assert
(expression: bool, message: string=)¶ Raise assertion error if expression is false
-
std.
at
(objects: list, index: number) → any¶ Get the item at index
-
std.
attr
(obj: any, attr: string) → any¶
-
std.
capitalize
(string: string) → string¶ Capitalize the given string
-
std.
contains
(dct: dict, key: string) → bool¶ Check if key exists in dct.
-
std.
count
(item_list: list) → number¶ Returns the number of elements in this list
-
std.
dict_get
(dct: dict, key: string) → string¶ Get an element from the dict. Raises an exception when the key is not found in the dict
-
std.
environment
() → string¶ Return the environment id
-
std.
environment_name
() → string¶ Return the name of the environment (as defined on the server)
-
std.
environment_server
() → string¶ Return the address of the management server
-
std.
equals
(arg1: any, arg2: any, desc: string = None)¶ Compare arg1 and arg2
-
std.
familyof
(member: std::OS, family: string) → bool¶ Determine if member is a member of the given operating system family
-
std.
file
(path: string) → string¶ Return the textual contents of the given file
-
std.
filter
(values: list, not_item: std::Entity) → list¶ Filter not_item from values
-
std.
flatten
(item_list: list) → list¶ Flatten this list
-
std.
generate_password
(pw_id: string, length: number = 20) → string¶ Generate a new random password and store it in the data directory of the project. On next invocations the stored password will be used.
- Parameters
pw_id – The id of the password to identify it.
length – The length of the password, default length is 20
-
std.
get_env
(name: string, default_value: string = None) → string¶
-
std.
get_env_int
(name: string, default_value: number = None) → number¶
-
std.
getattr
(entity: std::Entity, attribute_name: string, default_value: any=None, no_unknown: bool=True) → any¶ Return the value of the given attribute. If the attribute does not exist, return the default value.
- Attr no_unknown
When this argument is set to true, this method will return the default value when the attribute is unknown.
-
std.
getfact
(resource: any, fact_name: string, default_value: any = None) → any¶ Retrieve a fact of the given resource
-
std.
inlineif
(conditional: bool, a: any, b: any) → any¶ An inline if
-
std.
invert
(value: bool) → bool¶ Invert a boolean value
-
std.
is_base64_encoded
(s: string) → bool¶ Check whether the given string is base64 encoded.
-
std.
is_instance
(obj: any, cls: string) → bool¶
-
std.
is_set
(obj: any, attribute: string) → bool¶
-
std.
is_unknown
(value: any) → bool¶
-
std.
isset
(value: any) → bool¶ Returns true if a value has been set
-
std.
item
(objects: list, index: number) → list¶ Return a list that selects the item at index from each of the sublists
-
std.
key_sort
(items: list, key: any) → list¶ Sort an array of object on key
-
std.
length
(value: string) → number¶ Return the length of the string
-
std.
list_files
(path: string) → list¶ List files in a directory
-
std.
objid
(value: any) → string¶
-
std.
password
(pw_id: string) → string¶ Retrieve the given password from a password file. It raises an exception when a password is not found
- Parameters
pw_id – The id of the password to identify it.
-
std.
print
(message: any)¶ Print the given message to stdout
-
std.
replace
(string: string, old: string, new: string) → string¶
-
std.
select
(objects: list, attr: string) → list¶ Return a list with the select attributes
-
std.
sequence
(i: number, start: number = 0, offset: number = 0) → list¶ Return a sequence of i numbers, starting from zero or start if supplied.
-
std.
server_ca
() → string¶
-
std.
server_port
() → number¶
-
std.
server_ssl
() → bool¶
-
std.
server_token
(client_types: string[]=['agent']) → string¶
-
std.
source
(path: string) → string¶ Return the textual contents of the given file
-
std.
split
(string_list: string, delim: string) → list¶ Split the given string into a list
- Parameters
string_list – The list to split into parts
delim – The delimeter to split the text by
-
std.
template
(path: string)¶ Execute the template in path in the current context. This function will generate a new statement that has dependencies on the used variables.
-
std.
timestamp
(dummy: any = None) → number¶ Return an integer with the current unix timestamp
- Parameters
any – A dummy argument to be able to use this function as a filter
-
std.
to_number
(value: any) → number¶ Convert a value to a number
-
std.
type
(obj: any) → any¶
-
std.
unique
(item_list: list) → bool¶ Returns true if all items in this sequence are unique
-
std.
unique_file
(prefix: string, seed: string, suffix: string, length: number = 20) → string¶
-
std.
validate_type
(fq_type_name: string, value: any, validation_parameters: dict = None) → bool¶ Check whether value satisfies the constraints of type fq_type_name. When the given type (fq_type_name) requires validation_parameters, they can be provided using the optional validation_parameters argument.
The following types require validation_parameters:
- pydantic.condecimal:
gt: Decimal = None ge: Decimal = None lt: Decimal = None le: Decimal = None max_digits: int = None decimal_places: int = None multiple_of: Decimal = None
- pydantic.confloat and pydantic.conint:
gt: float = None ge: float = None lt: float = None le: float = None multiple_of: float = None,
- pydantic.constr:
min_length: int = None max_length: int = None curtail_length: int = None (Only verify the regex on the first curtail_length characters) regex: str = None (The regex is verified via Pattern.match())
- pydantic.stricturl:
min_length: int = 1 max_length: int = 2 ** 16 tld_required: bool = True allowed_schemes: Optional[Set[str]] = None
Example usage:
Define a vlan_id type which represent a valid vlan ID (0-4,095):
typedef vlan_id as number matching std::validate_type(“pydantic.conint”, self, {“ge”: 0, “le”: 4095})
Resources¶
-
class
std.resources.
AgentConfig
¶ A resource that can modify the agentmap for autostarted agents
Resource for entity
std::AgentConfig
Id attribute
agentname
Agent name
agent
Handlers
std.resources.AgentConfigHandler
-
class
std.resources.
Directory
¶ A directory on a filesystem
Resource for entity
std::Directory
Id attribute
path
Agent name
host.name
Handlers
std.resources.DirectoryHandler
-
class
std.resources.
File
¶ A file on a filesystem
Resource for entity
std::File
Id attribute
path
Agent name
host.name
Handlers
std.resources.PosixFileProvider
-
class
std.resources.
Package
¶ A software package installed on an operating system.
Resource for entity
std::Package
Id attribute
name
Agent name
host.name
Handlers
apt.AptPackage
,std.resources.YumPackage
-
class
std.resources.
Service
¶ This class represents a service on a system.
Resource for entity
std::Service
Id attribute
name
Agent name
host.name
Handlers
std.resources.SystemdService
,std.resources.ServiceService
,ubuntu.UbuntuService
-
class
std.resources.
Symlink
¶ A symbolic link on the filesystem
Resource for entity
std::Symlink
Id attribute
target
Agent name
host.name
Handlers
std.resources.SymlinkProvider
Handlers¶
-
class
std.resources.
YumPackage
¶ A Package handler that uses yum
Handler name
yum
Handler for entity
std::Package
-
class
std.resources.
PosixFileProvider
¶ This handler can deploy files on a unix system
Handler name
posix_file
Handler for entity
std::File
-
class
std.resources.
SystemdService
¶ A handler for services on systems that use systemd
Handler name
systemd
Handler for entity
std::Service
-
class
std.resources.
ServiceService
¶ A handler for services on systems that use service
Handler name
redhat_service
Handler for entity
std::Service
-
class
std.resources.
DirectoryHandler
¶ A handler for creating directories
TODO: add recursive operations
Handler name
posix_directory
Handler for entity
std::Directory
-
class
std.resources.
SymlinkProvider
¶ This handler can deploy symlinks on unix systems
Handler name
posix_symlink
Handler for entity
std::Symlink
-
class
std.resources.
AgentConfigHandler
¶ Handler name
agentrest
Handler for entity
std::AgentConfig