Merge "Add PostgreSQL database"

This commit is contained in:
Jenkins 2014-12-18 17:49:56 +00:00 committed by Gerrit Code Review
commit b4ceecdce9
12 changed files with 337 additions and 0 deletions

View File

@ -0,0 +1,125 @@
Namespaces:
=: io.murano.databases
std: io.murano
res: io.murano.resources
sys: io.murano.system
Name: PostgreSql
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 PostgreSql')
- $securityGroupIngress:
- ToPort: 5432
FromPort: 5432
IpProtocol: tcp
External: true
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
- $.instance.deploy()
- $resources: new(sys:Resources)
# Deploy PostgreSql
- $._environment.reporter.report($this, 'Instance is created. Deploying PostgreSql')
- $template: $resources.yaml('DeployPostgreSql.template')
- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'PostgreSql 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 PostgreSQL
- $resources: new(sys:Resources)
- $template: $resources.yaml('CreatePostgreSqlDatabase.template').bind(dict(
database => $database
))
- $.instance.agent.call($template, $resources)
- $._environment.reporter.report($this, 'Database is created')
createUser:
Arguments:
- username:
Contract: $.string().notNull()
- password:
Contract: $.string().notNull()
Body:
- $.deploy()
- $._environment.reporter.report($this, format('Creating {0} user.', $username))
# Creating Database on PostgreSQL
- $resources: new(sys:Resources)
- $template: $resources.yaml('CreatePostgreSqlUser.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 PostgresQL database
- $resources: new(sys:Resources)
- $template: $resources.yaml('AssignUserPostgreSql.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('psql://{0}@{1}:{2}', $username, $password, $host)

View File

@ -0,0 +1,20 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Assign user to PostgreSql 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: assignPostgreSqlUser.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -0,0 +1,19 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Create PostgreSql database
Parameters:
database: $database
Body: |
return createDatabase(args.database).stdout
Scripts:
createDatabase:
Type: Application
Version: 1.0.0
EntryPoint: createPostgreSqlDatabase.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -0,0 +1,20 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Create PostgreSql 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: createPostgreSqlUser.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -0,0 +1,19 @@
FormatVersion: 2.0.0
Version: 1.0.0
Name: Deploy PostgreSql
Parameters:
appName: $appName
Body: |
return deploy(args.appName).stdout
Scripts:
deploy:
Type: Application
Version: 1.0.0
EntryPoint: deployPostgreSql.sh
Files: []
Options:
captureStdout: true
captureStderr: true

View File

@ -0,0 +1,5 @@
#!/bin/bash
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $1 to $2"
tee --append /etc/postgresql/*/main/pg_hba.conf <<< "host $1 $2 all md5"
sudo /etc/init.d/postgresql restart

View File

@ -0,0 +1,3 @@
#!/bin/bash
sudo -u postgres psql -c "CREATE DATABASE $1"

View File

@ -0,0 +1,3 @@
#!/bin/bash
sudo -u postgres psql -c "CREATE USER $1 WITH PASSWORD '$2'"

View File

@ -0,0 +1,8 @@
#!/bin/bash
sudo apt-get update
sudo apt-get -y -q install postgresql
tee --append /etc/postgresql/*/main/postgresql.conf <<< "listen_addresses = '*'"
sudo iptables -I INPUT 1 -p tcp -m tcp --dport 5432 -j ACCEPT -m comment --comment "by murano, PostgreSQL"
sudo /etc/init.d/postgresql restart

View File

@ -0,0 +1,102 @@
Version: 2
Application:
?:
type: io.murano.databases.PostgreSql
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: PostgreDB
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: 69 KiB

View File

@ -0,0 +1,13 @@
Format: 1.0
Type: Application
FullName: io.murano.databases.PostgreSql
Name: PostgreSQL
Description: |
PostgreSQL is a powerful, open source object-relational database system.
It has more than 15 years of active development and a proven architecture
that has earned it a strong reputation for reliability, data integrity,
and correctness.
Author: 'Mirantis, Inc'
Tags: [Database, Postgre, SQL, RDBMS]
Classes:
io.murano.databases.PostgreSql: PostgreSql.yaml