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

147 lines
4.1 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.murano.lbaas
res: io.murano.resources
conf: io.murano.configuration
sys: io.murano.system
std: io.murano
Name: HAProxy
Extends:
- std:Application
- LoadBalancer
Properties:
user:
Contract: $.string().notNull()
pass:
Contract: $.string().notNull()
port:
Contract: $.int().notNull()
instance:
Contract: $.class(res:LinuxMuranoInstance).notNull()
pools:
Usage: InOut
Contract:
$.string().notNull(): $.class(HAProxyPool).notNull()
Methods:
.init:
Body:
- $._linux: new(conf:Linux)
- $._resources: new(sys:Resources)
- $._environment: $.find(std:Environment).require()
- $._lbConfig: null
deploy:
Body:
- If: not $.getAttr(installed, false)
Then:
- $securityGroupIngress:
- ToPort: $this.port
FromPort: $this.port
IpProtocol: tcp
External: true
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
- $this.installLB()
- $.setAttr(installed, true)
- $this.syncSettings()
- $._environment.reporter.report($this, format('HA-proxy is available at {0}', $this.getEndpoint()))
createPool:
Arguments:
- name:
Contract: $.string().notNull()
- algorithm:
Contract: $.string().notNull()
- protocol:
Contract: $.string().notNull()
- listener:
Contract: $.class(HAProxyListener).notNull()
Body:
- $pool: new(HAProxyPool, $this, listener=>$listener, name=>$name, algorithm=>$algorithm, protocol=>$protocol)
- $this.pools[$name]: $pool
- Return: $pool
addHostToPool:
Arguments:
- poolName:
Contract: $.string().notNull()
- host:
Contract: $.string().notNull()
- ip:
Contract: $.string().notNull()
- port:
Contract: $.int().check($>0)
Body:
- $pool: $this.pools.get($poolName)
- $pool.addMember($host, $ip, $port)
- $this.pools[$poolName]: $pool
installLB:
Body:
- $this.instance.deploy()
- $command: $._resources.string('deploy_haproxy.sh')
- $this._environment.reporter.report($this, 'Installing HAProxy...')
- $this._linux.runCommand($this.instance.agent, $command)
- $this._environment.reporter.report($this, 'HAProxy is installed.')
restartLB:
Body:
$this._linux.runCommand($.instance.agent, 'sudo service haproxy restart')
syncSettings:
Body:
- $config: $this.generateConfiguration()
- $this._environment.reporter.report($this, 'Replacing HAProxy settings')
- $this._linux.putFile($.instance.agent, $config, '/etc/haproxy/haproxy.cfg')
- $this.restartLB()
generateConfiguration:
Body:
- $defaultConfig: $._getDefaults()
- $stats: $._getStatsConfig()
- If: len($this.pools) > 0
Then:
$balanceConfig: $this.pools.values().select($.generateConfiguration()).join('\n\n')
Else:
$balanceConfig: ''
- Return: list($defaultConfig, $balanceConfig, $stats).join('\n\n')
_getStatsConfig:
Body:
Return: $._resources.string('stats.cfg').replace(
dict('$user'=>$this.user,
'$pass'=>$this.pass,
'$port'=>$this.port))
getEndpoint:
Body:
- If: $this.instance.assignFloatingIp
Then:
- $host: $this.instance.floatingIpAddress
Else:
- $host: $this.instance.ipAddresses.first()
- Return: format("http://{0}:{1}", $host, $this.port)
_getDefaults:
Body:
Return: $._resources.string('base_config.cfg')