diff --git a/io.murano.databases.PostgreSql/Classes/PostgreSql.yaml b/io.murano.databases.PostgreSql/Classes/PostgreSql.yaml new file mode 100644 index 00000000..a39eabfe --- /dev/null +++ b/io.murano.databases.PostgreSql/Classes/PostgreSql.yaml @@ -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) diff --git a/io.murano.databases.PostgreSql/Resources/AssignUserPostgreSql.template b/io.murano.databases.PostgreSql/Resources/AssignUserPostgreSql.template new file mode 100644 index 00000000..1f597c48 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/AssignUserPostgreSql.template @@ -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 diff --git a/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlDatabase.template b/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlDatabase.template new file mode 100644 index 00000000..45cb92b7 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlDatabase.template @@ -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 diff --git a/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlUser.template b/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlUser.template new file mode 100644 index 00000000..aa351a75 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/CreatePostgreSqlUser.template @@ -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 diff --git a/io.murano.databases.PostgreSql/Resources/DeployPostgreSql.template b/io.murano.databases.PostgreSql/Resources/DeployPostgreSql.template new file mode 100644 index 00000000..4b93f9a0 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/DeployPostgreSql.template @@ -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 diff --git a/io.murano.databases.PostgreSql/Resources/scripts/assignPostgreSqlUser.sh b/io.murano.databases.PostgreSql/Resources/scripts/assignPostgreSqlUser.sh new file mode 100644 index 00000000..35e0c249 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/scripts/assignPostgreSqlUser.sh @@ -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 diff --git a/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlDatabase.sh b/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlDatabase.sh new file mode 100644 index 00000000..80ef038f --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlDatabase.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo -u postgres psql -c "CREATE DATABASE $1" diff --git a/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlUser.sh b/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlUser.sh new file mode 100644 index 00000000..440799b9 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/scripts/createPostgreSqlUser.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo -u postgres psql -c "CREATE USER $1 WITH PASSWORD '$2'" diff --git a/io.murano.databases.PostgreSql/Resources/scripts/deployPostgreSql.sh b/io.murano.databases.PostgreSql/Resources/scripts/deployPostgreSql.sh new file mode 100644 index 00000000..a3d53d12 --- /dev/null +++ b/io.murano.databases.PostgreSql/Resources/scripts/deployPostgreSql.sh @@ -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 diff --git a/io.murano.databases.PostgreSql/UI/ui.yaml b/io.murano.databases.PostgreSql/UI/ui.yaml new file mode 100644 index 00000000..c3e7553b --- /dev/null +++ b/io.murano.databases.PostgreSql/UI/ui.yaml @@ -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 diff --git a/io.murano.databases.PostgreSql/logo.png b/io.murano.databases.PostgreSql/logo.png new file mode 100644 index 00000000..4eeae17c Binary files /dev/null and b/io.murano.databases.PostgreSql/logo.png differ diff --git a/io.murano.databases.PostgreSql/manifest.yaml b/io.murano.databases.PostgreSql/manifest.yaml new file mode 100644 index 00000000..e6ede498 --- /dev/null +++ b/io.murano.databases.PostgreSql/manifest.yaml @@ -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