[PostgreSql] Use simple software configuration

Change-Id: Iffae3af4e2ddc609ce1643d4f4d055d699416558
Partially-Implements: bp refactor-apps-scripts
This commit is contained in:
Dmytro Dovbii 2016-04-01 15:33:45 +03:00
parent 3b51222b09
commit fc6ba24e1e
9 changed files with 24 additions and 152 deletions

View File

@ -15,6 +15,7 @@ Namespaces:
std: io.murano
res: io.murano.resources
sys: io.murano.system
conf: io.murano.configuration
Name: PostgreSql
@ -49,11 +50,10 @@ Methods:
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)
- $file: sys:Resources.string('deployPostgreSql.sh')
- conf:Linux.runCommand($.instance.agent, $file)
- $._environment.reporter.report($this, 'PostgreSql application is installed.')
- $.setAttr(deployed, true)
- $._environment.reporter.report($this, 'Creating database and user.')
@ -83,11 +83,10 @@ Methods:
- $.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)
- $replacement:
"%DATABASE%": $database
- $file: sys:Resources.string('createPostgreSqlDatabase.sh').replace($replacement)
- conf:Linux.runCommand($.instance.agent, $file)
- $._environment.reporter.report($this, 'Database is created')
createUser:
@ -100,12 +99,11 @@ Methods:
- $.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)
- $replacements:
"%USER%": $username
"%PASSWORD%": $password
- $file: sys:Resources.string('createPostgreSqlUser.sh').replace($replacements)
- conf:Linux.runCommand($.instance.agent, $file)
- $._environment.reporter.report($this, format('User {0} created', $username))
assignUser:
@ -117,13 +115,13 @@ Methods:
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)
# Assigning user to PostgreSQL database
- $replacements:
"%USER%": $username
"%DATABASE%": $database
- $file: sys:Resources.string('assignPostgreSqlUser.sh').replace($replacements)
- conf:Linux.runCommand($.instance.agent, $file)
- $._environment.reporter.report($this, format('User {0} assigned to database {1}.', $username, $database))
getConnectionString:
@ -137,5 +135,5 @@ Methods:
Then:
- $host: $.instance.floatingIpAddress
Else:
- $host: $.instance.ipAddresses[0]
- $host: $.instance.ipAddresses.first()
- Return: format('psql://{0}@{1}:{2}', $username, $password, $host)

View File

@ -1,32 +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.
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

@ -1,31 +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.
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

@ -1,32 +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.
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

@ -1,31 +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.
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

@ -11,6 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
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 -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"%DATABASE%\" to \"%USER%\""
tee --append /etc/postgresql/*/main/pg_hba.conf <<< "host %DATABASE% %USER% all md5"
sudo /etc/init.d/postgresql restart

View File

@ -11,4 +11,4 @@
# License for the specific language governing permissions and limitations
# under the License.
sudo -u postgres psql -c "CREATE DATABASE $1"
sudo -u postgres psql -c "CREATE DATABASE \"%DATABASE%\""

View File

@ -11,4 +11,4 @@
# License for the specific language governing permissions and limitations
# under the License.
sudo -u postgres psql -c "CREATE USER $1 WITH PASSWORD '$2'"
sudo -u postgres psql -c "CREATE USER \"%USER%\" WITH PASSWORD '%PASSWORD%'"