Initial commit for lbaas library

* adds lbaas interfaces
* adds HAProxy implementation

This commit makes refactoring for old python-based version
of LbaaS and makes LbaaS-interface library and haproxy-based-lbaas
packages deprecated.

Change-Id: I93e0fbb59959a04b11adaf8fb13e901f3dfa61a4
This commit is contained in:
Dmytro Dovbii 2016-04-22 20:55:05 +03:00
parent 41c4b991e6
commit f683ec34b3
21 changed files with 695 additions and 0 deletions

View File

@ -0,0 +1,146 @@
# 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')

View File

@ -0,0 +1,65 @@
# 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
Name: HAProxyPool
Extends: Pool
Properties:
algorithm:
Contract: $.string().check($ in ['roundrobin', 'leastconn', 'source'])
protocol:
Contract: $.string().check($ in ['http', 'tcp'])
listener:
Contract: $.class(HAProxyListener).notNull()
Methods:
addMember:
Arguments:
- host:
Contract: $.string().notNull()
- address:
Contract: $.string().notNull()
- port:
Contract: $.int().check($>0)
Body:
- $m:
host: $host
port: $port
address: $address
- If: not $m in $this.members
Then:
- $this.members: $this.members.append($m)
generateConfiguration:
Body:
- $serverString: $this.members.select(format(' server {0} {1}:{2}', $.host, $.address, $.port)).join('\n')
- $res: new(sys:Resources)
- $backEndConfig: $res.string('backEndConfig.template').replace(
dict('$name'=> name($this),
'$servers'=>$serverString,
'$mode'=>$this.listener.protocol,
'$balance'=>$this.algorithm))
- $frontEndConfig: $this.listener.generateConfiguration(name($this))
- Return: list($backEndConfig, $frontEndConfig).join('\n\n')

View File

@ -0,0 +1,4 @@
backend $name
mode $mode
balance $balance
$servers

View File

@ -0,0 +1,23 @@
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
contimeout 5000
clitimeout 50000
srvtimeout 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

View File

@ -0,0 +1,13 @@
sudo add-apt-repository ppa:vbernat/haproxy-1.5 -y
sudo apt-get update
sudo apt-get install -y haproxy
# Enabling HAProxy.
sudo sed -i 's/^ENABLED=.*/ENABLED=1/' /etc/default/haproxy
sudo chown -R $USER:$USER /etc/haproxy
# Starting HAProxy.
#sudo service haproxy restart

View File

@ -0,0 +1,4 @@
frontend $name
$binds
mode $mode
default_backend $default_backend

View File

@ -0,0 +1,4 @@
listen stats *:$port
stats enable
stats uri /
stats auth $user:$pass

View File

@ -0,0 +1,126 @@
# 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.
Version: 2.2
Templates:
customJoinNet:
- ?:
type: io.murano.resources.ExistingNeutronNetwork
internalNetworkName: $.instanceConfiguration.network[0]
internalSubnetworkName: $.instanceConfiguration.network[1]
Application:
?:
type: org.openstack.murano.lbaas.HAProxy
port: $.appConfiguration.port
user: $.appConfiguration.user
pass: $.appConfiguration.pass
instance:
?:
type: io.murano.resources.LinuxMuranoInstance
name: generateHostname($.instanceConfiguration.unitNamingPattern, 1)
flavor: $.instanceConfiguration.flavor
image: $.instanceConfiguration.osImage
keyname: $.instanceConfiguration.keyPair
availabilityZone: $.instanceConfiguration.availabilityZone
assignFloatingIp: $.appConfiguration.assignFloatingIP
networks:
useEnvironmentNetwork: $.instanceConfiguration.network[0]=null
useFlatNetwork: false
customNetworks: switch($.instanceConfiguration.network[0], $=null=>list(), $!=null=>$customJoinNet)
Forms:
- appConfiguration:
fields:
- name: license
type: string
description: Apache License, Version 2.0
hidden: true
required: false
- name: user
type: string
label: Username
description: >-
Specify the name for user, which will be use
to access ha-proxy stats page
- name: pass
type: password
label: User password
description: >-
Specify the password for user
- name: port
type: integer
label: Port
initial: 8080
description: >-
Specify provide the port where ha-proxy stats
will be available
- name: assignFloatingIP
type: boolean
label: Assign Floating IP
description: >-
Select to true to assign floating IP automatically
initial: false
required: false
- instanceConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
description: Specify some instance parameters on which the application would be created
- name: flavor
type: flavor
label: Instance flavor
description: >-
Select registered in Openstack flavor. Consider that application performance
depends on this parameter.
required: false
- name: osImage
type: image
imageType: linux
label: Instance image
description: >-
Select valid image for the application. Image should already be prepared and
registered in glance.
- name: keyPair
type: keypair
label: Key Pair
description: >-
Select the Key Pair to control access to instances. You can login to
instances using this KeyPair after the deployment of application.
required: false
- name: availabilityZone
type: azone
label: Availability zone
description: Select availability zone where application would be installed.
required: false
- name: network
type: network
label: Network
description: Select a network to join. 'Auto' corresponds to a default environment's network.
required: false
murano_networks: translate
- name: unitNamingPattern
type: string
label: Instance Naming Pattern
required: false
maxLength: 64
regexpValidator: '^[a-zA-z][-_\w]*$'
errorMessages:
invalid: Just letters, numbers, underscores and hyphens are allowed.
helpText: Just letters, numbers, underscores and hyphens are allowed.
description: >-
Specify a string, that will be used in instance hostname.
Just A-Z, a-z, 0-9, dash and underline are allowed.

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,28 @@
# 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.
Format: 1.0
Type: Application
FullName: org.openstack.murano.lbaas.HAProxy
Name: HAProxy based Load Balancer
Description: |
HAProxy is a free, very fast and reliable solution offering high
availability, load balancing, and proxying for TCP and HTTP-based
applications.
Author: 'Mirantis, Inc'
Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy]
Classes:
org.openstack.murano.lbaas.HAProxy: HAProxy.yaml
org.openstack.murano.lbaas.HAProxyPool: HAProxyPool.yaml
Require:
org.openstack.murano.lbaas:
org.openstack.murano.lbaas.HAProxyListener:

View File

@ -0,0 +1,37 @@
# 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
std: io.murano
sys: io.murano.system
Extends:
- Listener
- std:Application
Name: HAProxyListener
Methods:
generateConfiguration:
Arguments:
- backend:
Contract: $.string()
Body:
- $resources: new(sys:Resources)
- $bindString: format(' bind {0}:{1}', $this.address, $this.port)
- $frontEndConfig: $resources.string('frontEndConfig.template').replace(
dict('$name' => name($this),
'$binds' => $bindString,
'$mode' => $this.protocol,
'$default_backend' => $backend))
- Return: $frontEndConfig

View File

@ -0,0 +1,4 @@
frontend $name
$binds
mode $mode
default_backend $default_backend

View File

@ -0,0 +1,49 @@
# 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.
Version: 2.2
Application:
?:
type: org.openstack.murano.lbaas.HAProxyListener
address: $.appConfiguration.address
algorithm: $.appConfiguration.algorithm
port: $.appConfiguration.port
protocol: $.appConfiguration.protocol
loadBalancer: $.appConfiguration.loadBalancer
Forms:
- appConfiguration:
fields:
- name: title
type: string
required: false
hidden: true
description: Specify some instance parameters on which the application would be created
- name: address
type: string
initial: '*'
label: Listener address
required: false
- name: algorithm
type: string
label: Algorithm of balancing
initial: 'roundrobin'
- name: port
type: integer
label: Port
- name: protocol
type: string
label: Protocol
- name: loadBalancer
type: org.openstack.murano.lbaas.HAProxy
label: Load Balancer

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -0,0 +1,27 @@
# 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.
Format: 1.0
Type: Application
FullName: org.openstack.murano.lbaas.HAProxyListener
Name: HAProxy based Listener
Description: |
HAProxy is a free, very fast and reliable solution offering high
availability, load balancing, and proxying for TCP and HTTP-based
applications.
Author: 'Mirantis, Inc'
Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy]
Classes:
org.openstack.murano.lbaas.HAProxyListener: HAProxyListener.yaml
Require:
org.openstack.murano.lbaas:
org.openstack.murano.lbaas.HAProxy:

View File

@ -16,6 +16,7 @@ FullName: io.murano.apps.lbaas.LBaaS
Name: LBaaS library
Description: |
Load Balancing as a Service library.
Deprecated: use org.openstack.murano.lbaas package instead
Author: 'Mirantis, Inc'
Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy]
Classes:

View File

@ -0,0 +1,42 @@
# 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
std: io.murano
Name: Listener
Properties:
address:
Usage: InOut
Contract: $.string().notNull()
protocol:
Usage: InOut
Contract: $.string().notNull()
algorithm:
Usage: InOut
Contract: $.string().notNull()
port:
Usage: InOut
Contract: $.int().notNull()
loadBalancer:
Contract: $.class(LoadBalancer).notNull()
Methods:
updateListener:

View File

@ -0,0 +1,57 @@
# 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
std: io.murano
Name: LoadBalancer
Properties:
listeners:
Usage: InOut
Contract:
- $.class(Listener).notNull()
Methods:
.init:
Body:
- $._environment: $.find(std:Environment).require()
deploy:
addListener:
Arguments:
- listener:
Contract: $.class(Listener).notNull()
Body:
- If: len(list($this.listeners.where($.name = $listener.name))) = 0
Then:
- $.listeners.append($listener)
Else:
- $msg: 'Listener with provided name already exists'
- $._environment.reporter.report_error($this, $msg)
- Throw: ConflictNameException
Message: $msg
- Return: $.listeners
deleteListener:
Arguments:
- name:
Contract: $.string().notNull()
Body:
- $.listeners: $.listeners.where($.name != $name)
- Return: $.listeners
getEndpoint:

View File

@ -0,0 +1,39 @@
# 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
std: io.murano
Name: Pool
Properties:
listener:
Contract:
- $.class(Listener)
protocol:
Contract: $.string().notNull()
members:
Usage: InOut
Contract:
- host: $.string().notNull()
address: $.string().notNull()
port: $.int().check($>0)
Methods:
addMember:
deleteMember:

View File

@ -0,0 +1,25 @@
# 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.
Format: 1.0
Type: Library
FullName: org.openstack.murano.lbaas
Name: LbaaS Library
Description: |
LbaaS library prototype for Murano
Author: 'Mirantis, Inc'
Tags: [MuranoPL, LbaaS]
Classes:
org.openstack.murano.lbaas.Listener: Listener.yaml
org.openstack.murano.lbaas.LoadBalancer: LoadBalancer.yaml
org.openstack.murano.lbaas.Pool: Pool.yaml

View File

@ -18,6 +18,7 @@ Description: |
HAProxy is a free, very fast and reliable solution offering high
availability, load balancing, and proxying for TCP and HTTP-based
applications.
Deprecated: use org.openstack.murano.lbaas.HAProxy package instead
Author: 'Mirantis, Inc'
Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy]
Classes: