ci-cd-pipeline-app-murano/murano-apps/Puppet/package/Classes/PuppetInstance.yaml

188 lines
5.2 KiB
YAML

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
Namespaces:
=: org.openstack.ci_cd_pipeline_murano_app.puppet
res: io.murano.resources
std: io.murano
sys: io.murano.system
Name: PuppetInstance
Extends: res:LinuxMuranoInstance
Properties:
hiera:
Contract: $.class(Hiera)
Methods:
.init:
Body:
- $._environment: $.find(std:Environment).require()
- $.hiera: new(Hiera)
deploy:
Body:
- super($this, $.deploy())
# Deploy host only once
- If: $.getAttr(hostDeployed, false)
Then:
- Return:
- $.installPuppet()
- $.installHiera()
- $.hiera.syncronize($this)
- $.setAttr(hostDeployed, true)
installPuppet:
Body:
- $._environment.reporter.report($this,
'Install puppet on instance "{0}" with id {1}'.format(
$.name, $.openstackId))
- $resources: new(sys:Resources)
- $template: $resources.yaml('InstallPuppet.template')
- $.agent.call($template, $resources)
- $._environment.reporter.report($this,
'Puppet installed on instance {0}'.format($.openstackId))
installHiera:
Body:
- $._environment.reporter.report($this,
'Install Hiera on instance {0}'.format($.openstackId))
- $resources: new(sys:Resources)
- $template: $resources.yaml('InstallHiera.template')
- $.agent.call($template, $resources)
- $._environment.reporter.report($this,
'Hiera is installed on instance {0}'.format($.openstackId))
#
# Equals to
# puppet install '<module>'
#
installPuppetModule:
Arguments:
- module:
Contract: $.string().notNull()
Body:
- $._environment.reporter.report($this,
'Installing puppet module {0} on {1}'.format( $module, $.openstackId))
- $resources: new(sys:Resources)
- $template: $resources.yaml('InstallPuppetModule.template').bind(dict(
module => $module))
- $.agent.call($template, $resources)
- $._environment.reporter.report($this,
'Puppet module {0} installed on {1}'.format( $module, $.openstackId))
# Deprecated
# use PuppetInstance.putHieraData()
setHieraValue:
Arguments:
- key:
Contract: $.string().notNull()
- value:
Contract: $.string().notNull()
Body:
- $._environment.reporter.report($this,
'Put value {0} = {1}'.format($key, $value))
- $data: dict($key => $value)
- $.hiera.putData($data)
- $.hiera.syncronize($this)
getHieraValue:
Arguments:
- key:
Contract: $.string().notNull()
Body:
- $resources: new(sys:Resources)
- $template: $resources.yaml('GetHieraData.template').bind(dict(
key => $key))
- $value: $.agent.call($template, $resources)
- Return: $value
#
# Put the data contained in the buffer to the instance
#
syncHieraData:
Body:
- $.hiera.syncronize($this)
#
# This method just adds the data to the inner buffer.
# The values related to the keys which are already exists will be updated
#
putHieraData:
Arguments:
- data:
Contract: {}
- sync:
# if false then data is not to be sent to an instance immediately
Contract: $.bool().notNull()
Default: true
Body:
- $this.hiera.putData($data)
- If: $sync
Then:
- $this.hiera.syncronize($this)
#
# Apply puppet manifest to the particular instance
#
# Usage example:
# - $instance.executeInline("create_resources('host', hiera('hosts'))")
#
# The code above is equal to:
# puppet apply --execute "create_resources('host', hiera('hosts'))"
#
# Known issues:
# * do not use " inside the code parameter
#
executeInline:
Arguments:
- code:
Contract: $.string().notNull()
Body:
- $resources: new(sys:Resources)
- $template: $resources.yaml('PuppetExecuteInline.template').bind(dict(
code => $code
))
- Return: $.agent.call($template, $resources)
#
# Apply manifest
#
# Usage example:
# - $fileContent: $resources.string('example.pp')
# - $.instance1.applyManifest($fileContent)
#
# The code above is equal to:
# puppet apply example.pp
#
applyManifest:
Arguments:
- manifest:
Contract: $.string().notNull()
- timeout:
Contract: $.int().notNull()
Default: 600
Body:
- $resources: new(sys:Resources)
- $parameters:
manifestContent: base64encode($manifest)
- $template: $resources.yaml('ApplyManifest.template').bind($parameters)
- Return: $this.agent.call($template, $resources, $timeout)
runPuppetAgents:
Body:
- $this.clients.pselect( $.agentRun())