ci-cd-pipeline-app-murano/murano-apps/CiCdUtils/package/Classes/net/Hosts.yaml

91 lines
2.2 KiB
YAML

Namespaces:
=: org.openstack.ci_cd_pipeline_murano_app.utils.net
std: io.murano
res: io.murano.resources
sys: io.murano.system
puppet: org.openstack.ci_cd_pipeline_murano_app.puppet
conf: io.murano.configuration
Name: Hosts
Properties:
# The list of entries to be added to /etc/hosts
hosts:
Contract: {}
Usage: InOut
Methods:
#
# Add new entry to be put into /etc/hosts
#
addHost:
Arguments:
- hostname:
Contract: $.string().notNull()
- ip:
Contract: $.string().notNull()
- aliases:
Contract:
- $.string()
Default: list()
Body:
- $this.hosts[$hostname]:
name: $hostname
ip: $ip
host_aliases: $aliases
#
# Ask instance it's hostname and add it by calling addHost
#
addHostByInstance:
Arguments:
- instance:
Contract: $.class(res:LinuxMuranoInstance).notNull()
- aliases:
Contract:
- $.string()
Default: list()
Body:
- $hostname: $this.getHostName($instance, true)
- $shortname: $this.getHostName($instance, false)
- $aliases: $aliases.append($shortname)
- $ip: $instance.ipAddresses[0]
- $this.addHost(hostname=>$hostname, ip=>$ip, aliases=>$aliases)
#
# Get the hostname which gives us OS
#
getHostName:
Arguments:
- instance:
Contract: $.class(res:LinuxMuranoInstance).notNull()
- fqdn:
Contract: $.bool().notNull()
Default: false
Body:
- $linux: new(conf:Linux)
- If: $fqdn
Then:
- Return: $linux.runCommand($instance.agent, 'hostname -f').stdout
- Return: $linux.runCommand($instance.agent, 'hostname -s').stdout
# Put all of the hosts to the particular instance
# All of the data will be added to the hiera
# and then puppet scenario will generate hosts entries
#
applyTo:
Arguments:
- instance:
Contract: $.class(puppet:PuppetInstance)
Body:
- $data:
hosts: $this.hosts
- $instance.putHieraData($data)
- $instance.syncHieraData()
- $resources: new(sys:Resources)
- $instance.executeInline("create_resources('host', hiera('hosts'))")