Sha256: c48beb180dbfb37598f1b00ff6286933cddef7e13f9808f8c95c710f9d7f2225

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

require 'fog/core/collection'

module Fog
  module OracleCloud
    class SOA
      class Instances < Fog::Collection

      	model Fog::OracleCloud::SOA::Instance

      	def all
          data = service.list_instances().body['services']
          load(data)
        end

        def get(id)
          new(service.get_instance(id).body) 
        end

        def create(attributes = {}, db_attributes = {})
          if attributes[:db_service_name].nil?
            # Attempt to create a database instance for them
            db_name = db_attributes[:service_name] || "#{attributes[:service_name]}-DB"
            db_attributes.merge!({
              :service_name => "#{attributes[:service_name]}-DB",
              :edition => 'EE',
              :ssh_key => attributes[:ssh_key],
              :shape => 'oc3',
              :version => '12.1.0.2',
              :admin_password => attributes[:admin_password],
              :backup_destination => 'BOTH'
            }) { |key, v1, v2| v1 }
            # Check it doesn't exist already
            begin
              db = Fog::OracleCloud[:database].instances.get(db_name)
            rescue Fog::OracleCloud::Database::NotFound => error
              # Doesn't exist, create it first
              db = Fog::OracleCloud[:database].instances.create(db_attributes)
              db.wait_for { ready? }
            end
            attributes.merge!({
              :dba_name => 'SYS',
              :dba_password => db_attributes[:admin_password],
              :db_service_name => db_name
            })
          end
          # Now provision SOA
          object = new(attributes)
          object.save
          object
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fog-oraclecloud-0.1.17 lib/fog/oraclecloud/models/soa/instances.rb
fog-oraclecloud-0.1.16 lib/fog/oraclecloud/models/soa/instances.rb
fog-oraclecloud-0.1.15 lib/fog/oraclecloud/models/soa/instances.rb
fog-oraclecloud-0.1.14 lib/fog/oraclecloud/models/soa/instances.rb
fog-oraclecloud-0.1.13 lib/fog/oraclecloud/models/soa/instances.rb