From c6685520456adc18f7288980997cfd47c1f07d26 Mon Sep 17 00:00:00 2001 From: Nikolay Mahotkin Date: Wed, 23 Mar 2016 15:20:16 +0300 Subject: [PATCH] Changing architecture of LBaaS packages * LBaaS library is separate package now, it includes: - deploy method (implements all needed deployment workflow for LBaaS) - install LBaaS method - configure LBaaS method (for optional configuration) - start LBaaS method - get credentials method (for service broker) * Now it is possible to create package extending LBaaS library by overriding just 3 methods: - installLoadBalancer - installLBaaS - getOptionalConfig (for detailed configuration) * Minor changes for liberty compatibility: - "Require" key in manifest - using ".init" method instead of "initialize" TODO: - include LBaaS API python package in murano LBaaS package Change-Id: I6fe3e98c6876d3e57c5cca7f826ef0f8932f77bb --- .../LBaaS-interface/Classes/LoadBalancer.yaml | 145 ++++++++++++++++++ .../Resources/DeployLBaaS.template | 0 .../Resources/SetConfigValue.template | 27 ++++ .../Resources/StartLBaaS.template | 16 ++ .../Resources/scripts/deployLBaaS.sh | 8 - .../Resources/scripts/setConfigValue.sh | 8 + .../Resources/scripts/startLBaaS.sh | 6 + murano-apps/LBaaS-interface/manifest.yaml | 22 +++ .../haproxy-based-lbaas/Classes/HAProxy.yaml | 31 +--- .../Classes/LoadBalancer.yaml | 87 ----------- murano-apps/haproxy-based-lbaas/UI/ui.yaml | 13 +- murano-apps/haproxy-based-lbaas/manifest.yaml | 5 +- 12 files changed, 234 insertions(+), 134 deletions(-) create mode 100644 murano-apps/LBaaS-interface/Classes/LoadBalancer.yaml rename murano-apps/{haproxy-based-lbaas => LBaaS-interface}/Resources/DeployLBaaS.template (100%) create mode 100644 murano-apps/LBaaS-interface/Resources/SetConfigValue.template create mode 100644 murano-apps/LBaaS-interface/Resources/StartLBaaS.template rename murano-apps/{haproxy-based-lbaas => LBaaS-interface}/Resources/scripts/deployLBaaS.sh (89%) create mode 100644 murano-apps/LBaaS-interface/Resources/scripts/setConfigValue.sh create mode 100644 murano-apps/LBaaS-interface/Resources/scripts/startLBaaS.sh create mode 100644 murano-apps/LBaaS-interface/manifest.yaml delete mode 100644 murano-apps/haproxy-based-lbaas/Classes/LoadBalancer.yaml diff --git a/murano-apps/LBaaS-interface/Classes/LoadBalancer.yaml b/murano-apps/LBaaS-interface/Classes/LoadBalancer.yaml new file mode 100644 index 0000000..d2ffd6c --- /dev/null +++ b/murano-apps/LBaaS-interface/Classes/LoadBalancer.yaml @@ -0,0 +1,145 @@ +# 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: + =: io.murano.apps.lbaas + std: io.murano + res: io.murano.resources + sys: io.murano.system + + +Name: LBaaS + +Extends: std:Application + +Properties: + + name: + Contract: $.string().notNull() + + instance: + Contract: $.class(res:Instance).notNull() + + implementation: + Contract: $.string() + Default: null + + environment: + Contract: $.class(std:Environment) + Usage: Runtime + + url: + Contract: $.string() + Usage: Out + +Methods: + .init: + Body: + - $.environment: $.find(std:Environment).require() + + deploy: + Body: + - If: $.getAttr(deployed, false) + Then: + Return: 0 + + - $.environment.reporter.report($this, 'Creating security groups...') + - $securityGroupIngress: + - ToPort: 65535 + FromPort: 1 + IpProtocol: tcp + External: true + - $.environment.securityGroupManager.addGroupIngress($securityGroupIngress) + - $.environment.reporter.report($this, 'Creating instance for LBaaS...') + - $.instance.deploy() + - $.environment.reporter.report($this, 'Instance is created.') + - $resources: new(sys:Resources) + - $.installLoadBalancer() + - $lbaas: $.installLBaaS($.implementation) + - $.configureLBaaS() + - $.startLBaaS() + - If: $.instance.assignFloatingIp + Then: + - $host: $.instance.floatingIpAddress + Else: + - $host: $.instance.ipAddresses[0] + - $.url: format("http://{0}:{1}{2}", $host, $lbaas.port, $lbaas.path) + - $.environment.reporter.report($this, format("LBaaS is available at {0}", $.url)) + - $.setAttr(deployed, true) + + getCredentials: + Usage: Action + Body: + - Return: + credentials: + uri: $.url + + getOptionalConfig: + # Returns a list of dicts containing 'section', 'key' and 'value' keys. + Body: + - Return: [] + + setConfigValue: + Arguments: + - section: + Contract: $.string().notNull() + - key: + Contract: $.string().notNull() + - value: + Contract: $.string().notNull() + Body: + - $.environment.reporter.report( + $this, + 'Setting value [{0}] {1} = {2}'.format($section, $key, $value) + ) + - $resources: new(sys:Resources) + - $template: $resources.yaml('SetConfigValue.template').bind(dict( + section => $section, + key => $key, + value => $value)) + - $.instance.agent.call($template, $resources) + + installLoadBalancer: + # Installs Load Balancer related stuff (e.g. system packages). + + installLBaaS: + # Installs LBaaS itself and its drivers on an instance. + Arguments: + - implementation: + Contract: $.string().notNull() + Body: + - $resources: new(sys:Resources) + - $template: $resources.yaml('DeployLBaaS.template').bind(dict( + impl => $.implementation + )) + - $.environment.reporter.report($this, 'Installing LBaaS...') + - $.instance.agent.call($template, $resources) + - $.setConfigValue('lbaas', 'impl', $.implementation) + - $.environment.reporter.report($this, 'LBaaS is installed.') + - Return: + port: 8993 + path: /v1 + + configureLBaaS: + Body: + - $.environment.reporter.report($this, 'Configuring LBaaS...') + # Call setConfigValue for each item in OptionalConfig. + - $.getOptionalConfig().select($this.setConfigValue($.section, $.key, $.value)) + - $.environment.reporter.report($this, 'Configured.') + + startLBaaS: + Body: + - $resources: new(sys:Resources) + - $template: $resources.yaml('StartLBaaS.template') + - $.environment.reporter.report($this, 'Starting LBaaS...') + - $.instance.agent.call($template, $resources) + - $.environment.reporter.report($this, 'LBaaS is started.') diff --git a/murano-apps/haproxy-based-lbaas/Resources/DeployLBaaS.template b/murano-apps/LBaaS-interface/Resources/DeployLBaaS.template similarity index 100% rename from murano-apps/haproxy-based-lbaas/Resources/DeployLBaaS.template rename to murano-apps/LBaaS-interface/Resources/DeployLBaaS.template diff --git a/murano-apps/LBaaS-interface/Resources/SetConfigValue.template b/murano-apps/LBaaS-interface/Resources/SetConfigValue.template new file mode 100644 index 0000000..c4dda85 --- /dev/null +++ b/murano-apps/LBaaS-interface/Resources/SetConfigValue.template @@ -0,0 +1,27 @@ +FormatVersion: 2.0.0 +Version: 1.0.0 +Name: Set Config Value + +Parameters: + section: $section + key: $key + value: $value + +Body: | + return SetConfigValue( + '{0} {1} {2}'.format( + args.section, + args.key, + args.value + ) + ).stdout + +Scripts: + SetConfigValue: + Type: Application + Version: 1.0.0 + EntryPoint: setConfigValue.sh + Files: [] + Options: + captureStdout: true + captureStderr: true diff --git a/murano-apps/LBaaS-interface/Resources/StartLBaaS.template b/murano-apps/LBaaS-interface/Resources/StartLBaaS.template new file mode 100644 index 0000000..7908b0a --- /dev/null +++ b/murano-apps/LBaaS-interface/Resources/StartLBaaS.template @@ -0,0 +1,16 @@ +FormatVersion: 2.0.0 +Version: 1.0.0 +Name: Start LBaaS + +Body: | + return LBaasStart().stdout + +Scripts: + LBaasStart: + Type: Application + Version: 1.0.0 + EntryPoint: startLBaaS.sh + Files: [] + Options: + captureStdout: true + captureStderr: true diff --git a/murano-apps/haproxy-based-lbaas/Resources/scripts/deployLBaaS.sh b/murano-apps/LBaaS-interface/Resources/scripts/deployLBaaS.sh similarity index 89% rename from murano-apps/haproxy-based-lbaas/Resources/scripts/deployLBaaS.sh rename to murano-apps/LBaaS-interface/Resources/scripts/deployLBaaS.sh index 05b66ec..3b5bb07 100644 --- a/murano-apps/haproxy-based-lbaas/Resources/scripts/deployLBaaS.sh +++ b/murano-apps/LBaaS-interface/Resources/scripts/deployLBaaS.sh @@ -29,9 +29,6 @@ sed -i 's/#verbose = false/verbose = true/g' etc/lbaas.conf sed -i 's/#default_log_levels/default_log_levels/g' etc/lbaas.conf sed -i 's/#log_file = /log_file = \/var\/log\/lbaas.log/g' etc/lbaas.conf -# Configure lbaas impl. -sed -i "s/#impl = haproxy/impl = $impl/g" etc/lbaas.conf - # Configure database connection. mysql --user=root --password=root -e "CREATE DATABASE lbaas;" mysql --user=root --password=root -e "GRANT ALL ON lbaas.* TO 'root'@'localhost';" @@ -49,8 +46,3 @@ sudo chown -R $USER:$USER /etc/lbaas sudo chown /var/log/lbaas.log mv etc/lbaas.conf /etc/lbaas/lbaas.conf - -cd ~ - -# Start lbaas. -lbaas-server --config-file /etc/lbaas/lbaas.conf >> lbaas.log 2>&1 & diff --git a/murano-apps/LBaaS-interface/Resources/scripts/setConfigValue.sh b/murano-apps/LBaaS-interface/Resources/scripts/setConfigValue.sh new file mode 100644 index 0000000..684092c --- /dev/null +++ b/murano-apps/LBaaS-interface/Resources/scripts/setConfigValue.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +section=$1 +key=$2 +value=$3 + +# Set value in lbaas config file. +sudo sed -i "/^\[$section\]$/,/^\[/ s/^#*$key.*=.*/$key = $value/" /etc/lbaas/lbaas.conf diff --git a/murano-apps/LBaaS-interface/Resources/scripts/startLBaaS.sh b/murano-apps/LBaaS-interface/Resources/scripts/startLBaaS.sh new file mode 100644 index 0000000..cacf4a1 --- /dev/null +++ b/murano-apps/LBaaS-interface/Resources/scripts/startLBaaS.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd ~ + +# Start lbaas. +lbaas-server --config-file /etc/lbaas/lbaas.conf >> lbaas.log 2>&1 & \ No newline at end of file diff --git a/murano-apps/LBaaS-interface/manifest.yaml b/murano-apps/LBaaS-interface/manifest.yaml new file mode 100644 index 0000000..99e79d8 --- /dev/null +++ b/murano-apps/LBaaS-interface/manifest.yaml @@ -0,0 +1,22 @@ +# 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: io.murano.apps.lbaas.LBaaS +Name: LBaaS library +Description: | + Load Balancing as a Service library. +Author: 'Mirantis, Inc' +Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy] +Classes: + io.murano.apps.lbaas.LBaaS: LoadBalancer.yaml diff --git a/murano-apps/haproxy-based-lbaas/Classes/HAProxy.yaml b/murano-apps/haproxy-based-lbaas/Classes/HAProxy.yaml index 68cdce8..0b9ae40 100644 --- a/murano-apps/haproxy-based-lbaas/Classes/HAProxy.yaml +++ b/murano-apps/haproxy-based-lbaas/Classes/HAProxy.yaml @@ -18,36 +18,17 @@ Namespaces: Name: HAProxy -Extends: LoadBalancer - -Properties: - - name: - Contract: $.string().notNull() - - implementation: - Contract: $.string() - Default: haproxy +Extends: LBaaS Methods: + .init: + Body: + - $.implementation: haproxy + installLoadBalancer: Body: - $resources: new(sys:Resources) - $template: $resources.yaml('DeployHAProxy.template') - - $.environment.reporter.report($this, 'Installing HAProxy') + - $.environment.reporter.report($this, 'Installing HAProxy...') - $.instance.agent.call($template, $resources) - $.environment.reporter.report($this, 'HAProxy is installed.') - - installLBaaS: - Body: - - $resources: new(sys:Resources) - - $template: $resources.yaml('DeployLBaaS.template').bind(dict( - impl => $.implementation - )) - - $.environment.reporter.report($this, 'Installing LBaaS...') - - $.instance.agent.call($template, $resources) - - $.environment.reporter.report($this, 'LBaaS is installed and started.') - - Return: - port: 8993 - path: /v1 - diff --git a/murano-apps/haproxy-based-lbaas/Classes/LoadBalancer.yaml b/murano-apps/haproxy-based-lbaas/Classes/LoadBalancer.yaml deleted file mode 100644 index d37c35a..0000000 --- a/murano-apps/haproxy-based-lbaas/Classes/LoadBalancer.yaml +++ /dev/null @@ -1,87 +0,0 @@ -# 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: - =: io.murano.apps.lbaas - std: io.murano - res: io.murano.resources - sys: io.murano.system - - -Name: LoadBalancer - -Extends: std:Application - -Properties: - - name: - Contract: $.string().notNull() - - instance: - Contract: $.class(res:Instance).notNull() - - implementation: - Contract: $.string() - Default: null - Usage: Runtime - - environment: - Contract: $.class(std:Environment) - Usage: Runtime - - url: - Contract: $.string() - Usage: Out - -Methods: - initialize: - Body: - - $.environment: $.find(std:Environment).require() - - deploy: - Body: - - If: $.getAttr(deployed, false) - Then: - Return: 0 - - - $.environment.reporter.report($this, 'Creating security groups...') - - $securityGroupIngress: - - ToPort: 65535 - FromPort: 1 - IpProtocol: tcp - External: true - - $.environment.securityGroupManager.addGroupIngress($securityGroupIngress) - - $.environment.reporter.report($this, 'Creating instance for load balancer...') - - $.instance.deploy() - - $.environment.reporter.report($this, 'Instance is created.') - - $resources: new(sys:Resources) - - $.installLoadBalancer() - - $lbaas: $.installLBaaS() - - If: $.instance.assignFloatingIp - Then: - - $host: $.instance.floatingIpAddress - Else: - - $host: $.instance.ipAddresses[0] - - $.url: format('http://{0}:{1}{2}', $host, $lbaas.port, $lbaas.path) - - $.environment.reporter.report($this, format('LBaaS is available at {0}', $.url)) - - $.setAttr(deployed, true) - - getCredentials: - Usage: Action - Body: - - Return: - credentials: - uri: $.url - - installLoadBalancer: - - installLBaaS: diff --git a/murano-apps/haproxy-based-lbaas/UI/ui.yaml b/murano-apps/haproxy-based-lbaas/UI/ui.yaml index 23b06b0..09b5b16 100644 --- a/murano-apps/haproxy-based-lbaas/UI/ui.yaml +++ b/murano-apps/haproxy-based-lbaas/UI/ui.yaml @@ -4,7 +4,6 @@ Application: ?: type: io.murano.apps.lbaas.HAProxy name: $.appConfiguration.name - implementation: $.appConfiguration.LBaasImpl instance: ?: type: io.murano.resources.LinuxMuranoInstance @@ -25,22 +24,12 @@ Forms: description: >- Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and underline are allowed - - name: LBaasImpl - label: Load Balancer implementation. - type: string - description: >- - Specify Load balancer implementation for this current LBaaS. Only 'haproxy' is available now. - initial: haproxy - regexpValidator: '^haproxy$' - errorMessages: - invalid: Only 'haproxy' is available now. - required: true - name: assignFloatingIP type: boolean label: Assign Floating IP description: >- Select to true to assign floating IP automatically - initial: false + initial: true required: false widgetMedia: css: {all: ['muranodashboard/css/checkbox.css']} diff --git a/murano-apps/haproxy-based-lbaas/manifest.yaml b/murano-apps/haproxy-based-lbaas/manifest.yaml index f224b6f..95ae92f 100644 --- a/murano-apps/haproxy-based-lbaas/manifest.yaml +++ b/murano-apps/haproxy-based-lbaas/manifest.yaml @@ -21,5 +21,6 @@ Description: | Author: 'Mirantis, Inc' Tags: [HTTP, TCP, Load Balancing as a Service, HAProxy] Classes: - io.murano.apps.lbaas.HAProxy: HAProxy.yaml - io.murano.apps.lbaas.LoadBalancer: LoadBalancer.yaml + io.murano.apps.lbaas.HAProxy: HAProxy.yaml +Require: + io.murano.apps.lbaas.LBaaS: