diff --git a/OraclePDBConnector/package/Classes/OraclePDB.murano b/OraclePDBConnector/package/Classes/OraclePDB.murano new file mode 100644 index 00000000..a9aabdb9 --- /dev/null +++ b/OraclePDBConnector/package/Classes/OraclePDB.murano @@ -0,0 +1,145 @@ +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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: + =: com.oracle.db.muranoPdb + std: io.murano + sys: io.murano.system +Name: OraclePDB +Extends: 'io.murano.databases.SqlDatabase' +Properties: + name: + Contract: $.string().notNull() + username: + Contract: $.string() + Usage: Out + database: + Contract: $.string() + Usage: Out + password: + Contract: $.string() + Usage: Out + agent_queue: + Contract: $.string().notNull() + Default: 'static-agent-002-tasks' + Usage: In + agent: + Contract: $.class(sys:StaticAgent) + Usage: InOut + listener: + Contract: $.string() + Default: '1.1.1.1' + Usage: InOut + createDB: + Contract: $.bool() + Default: false + Usage: InOut + + +Methods: + initialize: + Body: + - $._environment: $.find(std:Environment).require() + + deploy: + Body: + - If: not $.getAttr(deployed, false) + Then: + - $._environment.reporter.report($this, 'Oracle PDB') + - $.createAgent() + - $.getListener() + - $._environment.reporter.report($this, 'Listener {0}'.format($.listener)) + - If: $.createDB + Then: + - $.createDatabase(database => $.database) + - $.createUser(username => $.username, password => $.password, database => $.database) + - $connection_string: $.getConnectionString(username => $.username, password => $.password) + - $._environment.reporter.report($this, 'Connection String {0}'.format($connection_string)) + - $.setAttr(deployed, true) + + createAgent: + Body: + - $queue: $._environment.agentListener.queueName() + - $.agent: new(sys:StaticAgent, env => $._environment, + input_queue => $.agent_queue, + response_queue => $queue ) + + createDatabase: + Arguments: + database: + Contract: $.string().notNull() + Body: + - $._environment.reporter.report($this, 'Creating a DB') + - $resources: new(sys:Resources) + - $command: $resources.yaml('CreatePDB.template').bind(dict( + database => $database + )) + - $.agent.call($command, $resources) + + getListener: + Body: + - $resources: new(sys:Resources) + - $command: $resources.yaml('GetListener.template') + - $.listener: $.agent.call($command, $resources) + + createUser: + Arguments: + username: + Contract: $.string().notNull() + password: + Contract: $.string().notNull() + database: + Contract: $.string().notNull() + Body: + - $.user: $username + - $.password: $password + - $resources: new(sys:Resources) + - $command: $resources.yaml('CreateUser.template').bind(dict( + database => $database, + username => $username, + password => $password + )) + - $.agent.call($command, $resources) + + assignUser: + Arguments: + username: + Contract: $.string().notNull() + database: + Contract: $.string().notNull() + Body: + - $._environment.reporter.report($this, 'Assigning a user to the DB') + - $resources: new(sys:Resources) + - $command: $resources.yaml('AssignUser.template').bind(dict( + time => 'now' + )) + - $.agent.call($command, $resources) + + getConnectionString: + Arguments: + username: + Contract: $.string().notNull() + password: + Contract: $.string().notNull() + Body: + - $._environment.reporter.report($this, 'Generating a connection string for the PDB') + - Return: format('{0}/{1}@//{2}/{3}',$.username, $.password, $.listener, $.database) + + demo: + Usage: Action + Body: + - $.createDatabase(database => 'demo') + - $.createUser(database => 'demo', + username => 'test', + password => 'DemoTest01') diff --git a/OraclePDBConnector/package/License.txt b/OraclePDBConnector/package/License.txt new file mode 100644 index 00000000..443018c5 --- /dev/null +++ b/OraclePDBConnector/package/License.txt @@ -0,0 +1,13 @@ +Copyright 2015 Oracle and/or its affiliates. All rights reserved. + +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. diff --git a/OraclePDBConnector/package/Resources/CreatePDB.template b/OraclePDBConnector/package/Resources/CreatePDB.template new file mode 100644 index 00000000..d3e993dd --- /dev/null +++ b/OraclePDBConnector/package/Resources/CreatePDB.template @@ -0,0 +1,36 @@ +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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 Pluggable Database + +Parameters: + database: $database + +Body: | + return create('"{0}" '.format(args.database)).stdout + +Scripts: + create: + Type: Application + Version: 1.0.0 + EntryPoint: pdb_create.sh + Files: + - + + Options: + captureStdout: true + captureStderr: true diff --git a/OraclePDBConnector/package/Resources/CreateUser.template b/OraclePDBConnector/package/Resources/CreateUser.template new file mode 100644 index 00000000..224ba946 --- /dev/null +++ b/OraclePDBConnector/package/Resources/CreateUser.template @@ -0,0 +1,38 @@ +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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 Database User + +Parameters: + database: $database + username: $username + password: $password + +Body: | + return create('"{0}" "{1}" "{2}"'.format(args.database, args.username, args.password)).stdout + +Scripts: + create: + Type: Application + Version: 1.0.0 + EntryPoint: pdb_create_user.sh + Files: + - + + Options: + captureStdout: true + captureStderr: true diff --git a/OraclePDBConnector/package/Resources/GetListener.template b/OraclePDBConnector/package/Resources/GetListener.template new file mode 100644 index 00000000..6a3f0ae9 --- /dev/null +++ b/OraclePDBConnector/package/Resources/GetListener.template @@ -0,0 +1,35 @@ +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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: Check Oracle Listener + +Parameters: + appName: $appName + +Body: | + return get_listener(args.appName).stdout + +Scripts: + get_listener: + Type: Application + Version: 1.0.0 + EntryPoint: get_listener.sh + Files: + - + Options: + captureStdout: true + captureStderr: true diff --git a/OraclePDBConnector/package/Resources/scripts/get_listener.sh b/OraclePDBConnector/package/Resources/scripts/get_listener.sh new file mode 100644 index 00000000..37c168a8 --- /dev/null +++ b/OraclePDBConnector/package/Resources/scripts/get_listener.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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. +# +. ./ora_env.sh + +# lsnrctl is the proper way to get the host and port numbers. +# Get the descriptions but only the tcp and tcps descriptions +ip_addrs=`lsnrctl status | grep 'DESCRIPTION.*PROTOCOL=tcp' | sed 's|.*HOST=\([^)]*\))(PORT=\([^)]*\).*|\1:\2|g'` +for addr in $ip_addrs +do + tnsping $addr >> /dev/null + if [ $? -eq 0 ] + then + echo "$addr" + break + else + echo "No Listener" + fi +done diff --git a/OraclePDBConnector/package/Resources/scripts/ora_env.sh b/OraclePDBConnector/package/Resources/scripts/ora_env.sh new file mode 100644 index 00000000..ca38a7ab --- /dev/null +++ b/OraclePDBConnector/package/Resources/scripts/ora_env.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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. +# +. /etc/oraenv/ora_env.sh +. /etc/oraenv/orapwd +export LD_LIBRARY_PATH=$ORACLE_HOME/lib +export PATH=$ORACLE_HOME/perl/bin:$PATH +export PATH=$ORACLE_HOME/bin:$PATH +# Find site_perl +site_perl=( $(/usr/bin/ls -r $ORACLE_HOME/perl/lib/site_perl) ) + +if [[ $(/usr/bin/uname -p) == 'sparc' ]]; then + export PERL5LIB=$ORACLE_HOME/perl/lib/site_perl/${site_perl[0]}/sun4-solaris-64int:$ORACLE_HOME/perl/lib +else + export PERL5LIB=$ORACLE_HOME/perl/lib/site_perl/${site_perl[0]}/i86pc-solaris-thread-multi-64:$ORACLE_HOME/perl/lib +fi +export PDBSEED=$ORADATA/pdbseed diff --git a/OraclePDBConnector/package/Resources/scripts/pdb_create.sh b/OraclePDBConnector/package/Resources/scripts/pdb_create.sh new file mode 100644 index 00000000..a01bcab5 --- /dev/null +++ b/OraclePDBConnector/package/Resources/scripts/pdb_create.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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. +# +# Export env variables +. ./ora_env.sh + +sql_file="$ORACLE_USER_HOME/pdb_create_$$.sql" + +# Create pluggable database +# Open the pluggable database for read-write +cat > $sql_file << EOF +CONNECT / as sysdba; +SET LINESIZE 100; +SET PAGESIZE 50; +CREATE PLUGGABLE DATABASE $1 ADMIN USER $ADMIN_USER IDENTIFIED BY $ADMIN_PWD roles=(CONNECT,DBA) FILE_NAME_CONVERT = ('$PDBSEED', '$ORADATA/$1'); +ALTER PLUGGABLE DATABASE $1 OPEN; +EXIT; +EOF +chown oracle:oracle $sql_file +# Execute the sql statements +su - oracle -c ". ~/ora_env.sh && sqlplus /nolog @$sql_file $1" +# remove the sql_file +rm -f $sql_file diff --git a/OraclePDBConnector/package/Resources/scripts/pdb_create_user.sh b/OraclePDBConnector/package/Resources/scripts/pdb_create_user.sh new file mode 100644 index 00000000..90d6037f --- /dev/null +++ b/OraclePDBConnector/package/Resources/scripts/pdb_create_user.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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. +# +. ./ora_env.sh + +sql_file="$ORACLE_USER_HOME/pdb_create_user_$$.sql" + +# get the address to attach to +lsnr=$($ORACLE_USER_HOME/get_listener.sh) +err=$? +if [[ $err -ne 0 ]] +then + echo $lsnr; + exit $err +fi + +# create user +# grant all privileges +# TODO: privileges to be set based on what the ADMIN user is requesting +# from the client. + +cat > $sql_file << EOF +CONNECT $SYSTEM_USER/$SYSTEM_USER_PWD@//$lsnr/$1; +SET LINESIZE 100; +SET PAGESIZE 50; +CREATE USER $2 IDENTIFIED BY "$3"; +GRANT ALL PRIVILEGES to $2; +EXIT +EOF + +chown oracle:oracle $sql_file +# Run this perl script so that the user information is +# updated properly on all the system meta files. +perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -l $ORACLE_USER_HOME -b pupbld -u $SYSTEM_USER/$SYSTEM_USER_PWD $ORACLE_HOME/sqlplus/admin/pupbld.sql; + +# Execute the sql +su - oracle -c " . ~/ora_env.sh && sqlplus /nolog @$sql_file" + +# construct the connection string. +# echo the CONN string +# conn string is /@//:/ + +# echo "$2/$3@//$lnsr/$1" +echo "Connection host and port $lsnr" +rm -f $sql_file diff --git a/OraclePDBConnector/package/UI/ui.yaml b/OraclePDBConnector/package/UI/ui.yaml new file mode 100644 index 00000000..8e5ea906 --- /dev/null +++ b/OraclePDBConnector/package/UI/ui.yaml @@ -0,0 +1,79 @@ +Version: 2 + +Application: + ?: + type: com.oracle.db.muranoPdb.OraclePDB + name: $.appConfiguration.name + database: $.initDatabaseConfiguration.database + username: $.initDatabaseConfiguration.username + password: $.initDatabaseConfiguration.password + createDB: $.initDatabaseConfiguration.createDB + +Forms: + - appConfiguration: + fields: + - name: license + type: string + label: License + required: false + hidden: true + initial: 'Oracle-PDB' + description: >- + All Files in this package are copyright 2015 Oracle and/or its + affiliates. All rights reserved. + + 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. + + - name: name + type: string + label: Application Name + initial: 'Oracle-PDB' + description: >- + Enter a desired name for the application. Just A-Z, a-z, 0-9, dash and + underline are allowed + + - 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 Oracle Server + - name: database + type: string + required: true + label: Database name + description: >- + Please, provide database name that is going to be created + - name: username + type: string + required: true + label: Username + description: >- + Please, provide username that is going to be used to connect to the database + - name: password + type: password + required: true + label: Password + descriptionTitle: Password + description: >- + Please, provide password that is going to be used to connect to the database + - name: createDB + type: boolean + initial: false + required: false + label: Create Database on Deploy + description: >- + Enable checkbox to create a database during an environment deployment diff --git a/OraclePDBConnector/package/logo.png b/OraclePDBConnector/package/logo.png new file mode 100644 index 00000000..3adcf321 Binary files /dev/null and b/OraclePDBConnector/package/logo.png differ diff --git a/OraclePDBConnector/package/manifest.yaml b/OraclePDBConnector/package/manifest.yaml new file mode 100644 index 00000000..f217d121 --- /dev/null +++ b/OraclePDBConnector/package/manifest.yaml @@ -0,0 +1,28 @@ +# +# Copyright 2015 Oracle and/or its affiliates. All rights reserved. +# +# 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. +# +Format: 1.0 +Type: Application +FullName: com.oracle.db.muranoPdb.OraclePDB +Name: Oracle PDB Connector +Description: | + Oracle PDB Connector is a Murano application that provides OpenStack cloud users with means for self-service provisioning of Oracle Database 12c and Oracle Multitenant Pluggable DataBases (PDBs). This is an unsupported technology preview release not intended for use in production environments. + +Author: 'Oracle' +Tags: [oracle] +Classes: + com.oracle.db.muranoPdb.OraclePDB: OraclePDB.murano +Require: + io.murano.databases: diff --git a/OraclePDBConnector/readme.rst b/OraclePDBConnector/readme.rst new file mode 100644 index 00000000..f00e6102 --- /dev/null +++ b/OraclePDBConnector/readme.rst @@ -0,0 +1,75 @@ +==================== +Oracle PDB Connector +==================== + +Description +----------- + +Oracle PDB Connector is a Murano application that provides OpenStack cloud +users with means for self-service provisioning of Oracle Database 12c and +Oracle Multitenant Pluggable DataBases (PDBs). + +This is an unsupported technology preview release not intended for use in +production environments. It is supported on the Juno and Kilo OpenStack +releases. + +Instructions +------------ + +1. You must first install and configure Oracle Database 12c with the Oracle + Multitenant option on Oracle Solaris 11.2. + + Create a file ``/etc/oraenv/ora_env.sh`` with read/write permissions for + the ``oracle`` user, and set the following environment variables (with + values appropriate for your installation):: + + + + ORACLE_BASE=/path/to/oracle # The base directory of Oracle database + # installation + ORACLE_HOME=$ORACLE_BASE/ # oracle home + ORACLE_SID= # Oracle System Identifier + ORADATA=/path/to/data # Oracle application directory + # e.g. /u01/app/oracle/oradata + ORACLE_USER_HOME=/home/oracle # Home directory of user oracle + + Now create a file ``/etc/oraenv/orapwd``, also with read/write permissions + for the ``oracle`` user, and add the names and passwords for the admin and + system users:: + + ADMIN_USER= + SYSTEM_USER= + ADMIN_PWD= + SYSTEM_USER_PWD= + +2. You will also need the latest Murano agent. + + - Download the latest tarball of murano-agent and its dependent packages + on the node where Oracle 12c is running. + + - Install each of the package by doing the following:: + + # tar -zxvf .tar.gz + # cd + # ./setup.py build + # ./setup.py install + + - The executable ``muranoagent`` will be made available in ``/usr/bin``. + + - Set up the agent by copying the sample configuration file to + ``/etc/murano/agent.conf``. + + - Edit ``/etc/murano/agent.conf`` and set ``enable_dynamic_result_queue`` + to ``True`` in the ``DEFAULT`` section. Set ``input_queue`` with queue + information from the murano engine. + + - Start the agent:: + + # /usr/bin/muranoagent --config-file /etc/murano.conf + +3. Install the latest version of the plugin required by this application, + available from PyPI:: + + # pip install murano.plugins.static-agent + + After the plugin is installed, restart the murano engine.