98ae90c675
* LICENSE file placed to every package * License information is shown during application creation * License added to every file Change-Id: I682f3d9a09d0c0b575206d79223c1822c4b94f27 Closes-Bug: #1446121
137 lines
4.7 KiB
YAML
137 lines
4.7 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:
|
|
=: io.murano.databases
|
|
std: io.murano
|
|
res: io.murano.resources
|
|
sys: io.murano.system
|
|
|
|
Name: MySql
|
|
|
|
Extends:
|
|
- SqlDatabase
|
|
|
|
Properties:
|
|
instance:
|
|
Contract: $.class(res:Instance).notNull()
|
|
name:
|
|
Contract: $.string().notNull()
|
|
database:
|
|
Contract: $.string()
|
|
username:
|
|
Contract: $.string()
|
|
password:
|
|
Contract: $.string()
|
|
|
|
Methods:
|
|
initialize:
|
|
Body:
|
|
- $._environment: $.find(std:Environment).require()
|
|
|
|
deploy:
|
|
Body:
|
|
- If: not $.getAttr(deployed, false)
|
|
Then:
|
|
- $._environment.reporter.report($this, 'Creating VM for MySql')
|
|
- $securityGroupIngress:
|
|
- ToPort: 3306
|
|
FromPort: 3306
|
|
IpProtocol: tcp
|
|
External: true
|
|
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
|
|
- $.instance.deploy()
|
|
- $resources: new(sys:Resources)
|
|
# Deploy MySql
|
|
- $._environment.reporter.report($this, 'Instance is created. Deploying MySql')
|
|
- $template: $resources.yaml('DeployMySql.template')
|
|
- $.instance.agent.call($template, $resources)
|
|
- $._environment.reporter.report($this, 'MySql application is installed.')
|
|
- $.setAttr(deployed, true)
|
|
- $._environment.reporter.report($this, 'Creating database and user.')
|
|
- If: $.database != '' and $.database != null
|
|
Then:
|
|
- $.createDatabase($.database)
|
|
- $._environment.reporter.report($this, format('Database {0} created.', $.database))
|
|
- If: $.username != '' and $.username != null
|
|
Then:
|
|
- $.createUser($.username, $.password)
|
|
- If: $.database != '' and $.database != null
|
|
Then:
|
|
- $.assignUser($.username, $.database)
|
|
- $._environment.reporter.report($this, format('User {0} created.', $.username))
|
|
|
|
createDatabase:
|
|
Arguments:
|
|
- database:
|
|
Contract: $.string().notNull()
|
|
Body:
|
|
- $.deploy()
|
|
- $._environment.reporter.report($this, format('Creating {0} database.', $database))
|
|
# Creating Database on MySQL
|
|
- $resources: new(sys:Resources)
|
|
- $template: $resources.yaml('CreateMySqlDatabase.template').bind(dict(
|
|
database => $database
|
|
))
|
|
- $.instance.agent.call($template, $resources)
|
|
- $._environment.reporter.report($this, format('Database {0} created.', $database))
|
|
|
|
createUser:
|
|
Arguments:
|
|
- username:
|
|
Contract: $.string().notNull()
|
|
- password:
|
|
Contract: $.string().notNull()
|
|
Body:
|
|
- $.deploy()
|
|
- $._environment.reporter.report($this, format('Creating {0} user.', $username))
|
|
# Creating user on MySQL
|
|
- $resources: new(sys:Resources)
|
|
- $template: $resources.yaml('CreateMySqlUser.template').bind(dict(
|
|
username => $username,
|
|
password => $password
|
|
))
|
|
- $.instance.agent.call($template, $resources)
|
|
- $._environment.reporter.report($this, format('User {0} created', $username))
|
|
|
|
assignUser:
|
|
Arguments:
|
|
- username:
|
|
Contract: $.string().notNull()
|
|
- database:
|
|
Contract: $.string().notNull()
|
|
Body:
|
|
- $.deploy()
|
|
- $._environment.reporter.report($this, format('Assigning user {0} to database {1}.', $username, $database))
|
|
# Assigning user to MySQL database
|
|
- $resources: new(sys:Resources)
|
|
- $template: $resources.yaml('AssignUserMySql.template').bind(dict(
|
|
username => $username,
|
|
database => $database
|
|
))
|
|
- $.instance.agent.call($template, $resources)
|
|
- $._environment.reporter.report($this, format('User {0} assigned to database {1}.', $username, $database))
|
|
|
|
getConnectionString:
|
|
Arguments:
|
|
- username:
|
|
Contract: $.string().notNull()
|
|
- password:
|
|
Contract: $.string().notNull()
|
|
Body:
|
|
- If: $.instance.assignFloatingIp
|
|
Then:
|
|
- $host: $.instance.floatingIpAddress
|
|
Else:
|
|
- $host: $.instance.ipAddresses[0]
|
|
- Return: format('mysql://{0}@{1}:{2}', $username, $password, $host)
|