Merge "Add MySQL database application"
This commit is contained in:
commit
8e5db66fe5
|
@ -0,0 +1,124 @@
|
|||
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)
|
|
@ -0,0 +1,20 @@
|
|||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Assign user to MySql database
|
||||
|
||||
Parameters:
|
||||
database: $database
|
||||
username: $username
|
||||
|
||||
Body: |
|
||||
return assignUser('{0} {1}'.format(args.database, args.username)).stdout
|
||||
|
||||
Scripts:
|
||||
assignUser:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: assignMySqlUser.sh
|
||||
Files: []
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
|
@ -0,0 +1,19 @@
|
|||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Create MySql database
|
||||
|
||||
Parameters:
|
||||
database: $database
|
||||
|
||||
Body: |
|
||||
return createDatabase(args.database).stdout
|
||||
|
||||
Scripts:
|
||||
createDatabase:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: createMySqlDatabase.sh
|
||||
Files: []
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
|
@ -0,0 +1,20 @@
|
|||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Create MySql user
|
||||
|
||||
Parameters:
|
||||
username: $username
|
||||
password: $password
|
||||
|
||||
Body: |
|
||||
return createUser('{0} {1}'.format(args.username, args.password)).stdout
|
||||
|
||||
Scripts:
|
||||
createUser:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: createMySqlUser.sh
|
||||
Files: []
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
|
@ -0,0 +1,19 @@
|
|||
FormatVersion: 2.0.0
|
||||
Version: 1.0.0
|
||||
Name: Deploy MySql
|
||||
|
||||
Parameters:
|
||||
appName: $appName
|
||||
|
||||
Body: |
|
||||
return deploy(args.appName).stdout
|
||||
|
||||
Scripts:
|
||||
deploy:
|
||||
Type: Application
|
||||
Version: 1.0.0
|
||||
EntryPoint: deployMySql.sh
|
||||
Files: []
|
||||
Options:
|
||||
captureStdout: true
|
||||
captureStderr: true
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql --user=root --password=root -e "GRANT ALL PRIVILEGES ON $1.* TO '$2'@'localhost' WITH GRANT OPTION"
|
||||
mysql --user=root --password=root -e "GRANT ALL PRIVILEGES ON $1.* TO '$2'@'%' WITH GRANT OPTION"
|
||||
mysql --user=root --password=root -e "FLUSH PRIVILEGES"
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql --user=root --password=root -e "CREATE DATABASE $1"
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
mysql --user=root --password=root -e "CREATE USER '$1'@'localhost' IDENTIFIED BY '$2'"
|
||||
mysql --user=root --password=root -e "CREATE USER '$1'@'%' IDENTIFIED BY '$2'"
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
|
||||
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
|
||||
|
||||
sudo apt-get -y -q install mysql-server
|
||||
sed -e "s/^bind-address*/#bind-address/" -i /etc/mysql/my.cnf
|
||||
service mysql restart
|
||||
|
||||
sudo iptables -I INPUT 1 -p tcp -m tcp --dport 3306 -j ACCEPT -m comment --comment "by murano, MySQL"
|
|
@ -0,0 +1,105 @@
|
|||
Version: 2
|
||||
|
||||
Application:
|
||||
?:
|
||||
type: io.murano.databases.MySql
|
||||
name: $.appConfiguration.name
|
||||
database: $.initDatabaseConfiguration.database
|
||||
username: $.initDatabaseConfiguration.username
|
||||
password: $.initDatabaseConfiguration.password
|
||||
instance:
|
||||
?:
|
||||
type: io.murano.resources.LinuxMuranoInstance
|
||||
name: generateHostname($.appConfiguration.unitNamingPattern, 1)
|
||||
flavor: $.instanceConfiguration.flavor
|
||||
image: $.instanceConfiguration.osImage
|
||||
keyname: $.instanceConfiguration.keyPair
|
||||
assignFloatingIp: $.appConfiguration.assignFloatingIP
|
||||
|
||||
Forms:
|
||||
- appConfiguration:
|
||||
fields:
|
||||
- name: name
|
||||
type: string
|
||||
label: Application Name
|
||||
initial: MySqlDB
|
||||
description: >-
|
||||
Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and
|
||||
underline are allowed
|
||||
- name: assignFloatingIP
|
||||
type: boolean
|
||||
label: Assign Floating IP
|
||||
description: >-
|
||||
Select to true to assign floating IP automatically
|
||||
initial: false
|
||||
required: false
|
||||
- name: unitNamingPattern
|
||||
type: string
|
||||
required: false
|
||||
hidden: true
|
||||
widgetMedia:
|
||||
js: ['muranodashboard/js/support_placeholder.js']
|
||||
css: {all: ['muranodashboard/css/support_placeholder.css']}
|
||||
|
||||
- initDatabaseConfiguration:
|
||||
fields:
|
||||
- name: title
|
||||
type: string
|
||||
required: false
|
||||
hidden: true
|
||||
descriptionTitle: Database Configuration
|
||||
description: Specify the properties of the database which will be created at MySql Server
|
||||
- name: database
|
||||
type: string
|
||||
required: false
|
||||
label: Database name
|
||||
description: >-
|
||||
Please, provide database name that is going to be created
|
||||
- name: username
|
||||
type: string
|
||||
required: false
|
||||
label: Username
|
||||
description: >-
|
||||
Please, provide username that is going to be used to connect to the database
|
||||
- name: password
|
||||
type: password
|
||||
required: false
|
||||
label: Password
|
||||
descriptionTitle: Password
|
||||
description: >-
|
||||
Please, provide password that is going to be used to connect to the database
|
||||
|
||||
- instanceConfiguration:
|
||||
fields:
|
||||
- name: title
|
||||
type: string
|
||||
required: false
|
||||
hidden: true
|
||||
description: Specify some instance parameters on which 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 the application would be installed.
|
||||
required: false
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
|
@ -0,0 +1,12 @@
|
|||
Format: 1.0
|
||||
Type: Application
|
||||
FullName: io.murano.databases.MySql
|
||||
Name: MySQL
|
||||
Description: |
|
||||
MySql is a relational database management system (RDBMS), and ships with
|
||||
no GUI tools to administer MySQL databases or manage data contained within
|
||||
the databases.
|
||||
Author: 'Mirantis, Inc'
|
||||
Tags: [Database, MySql, SQL, RDBMS]
|
||||
Classes:
|
||||
io.murano.databases.MySql: MySql.yaml
|
Loading…
Reference in New Issue