Class: Fog::OracleCloud::SOA::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/oraclecloud/soa.rb,
lib/fog/oraclecloud/requests/soa/get_instance.rb,
lib/fog/oraclecloud/requests/soa/get_job_status.rb,
lib/fog/oraclecloud/requests/soa/list_instances.rb,
lib/fog/oraclecloud/requests/soa/create_instance.rb,
lib/fog/oraclecloud/requests/soa/delete_instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



20
21
22
23
24
25
26
27
28
# File 'lib/fog/oraclecloud/soa.rb', line 20

def initialize(options={})
@username = options[:oracle_username]
@password = options[:oracle_password]
@identity_domain   = options[:oracle_domain]
  region_url = options[:oracle_region] == 'emea' ? 'https://jcs.emea.oraclecloud.com' : 'https://jaas.oraclecloud.com'
  Excon.ssl_verify_peer = false

  @connection = Fog::XML::Connection.new(region_url)
end

Instance Method Details

#auth_headerObject



38
39
40
# File 'lib/fog/oraclecloud/soa.rb', line 38

def auth_header
 	auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
end

#create_instance(config, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/oraclecloud/requests/soa/create_instance.rb', line 5

def create_instance(config, options)  
  if !config[:cloudStorageContainer].start_with?("/Storage-")
    config[:cloudStorageContainer] = "/Storage-#{@identity_domain}/#{config[:cloudStorageContainer]}"
  end

  parameters = options.select{|key, value| [:adminPassword, :adminPort, :adminUserName, :backupVolumeSize, :clusterName, :contentPort, :dbaName, :dbaPassword, :dbServiceName, :deploymentChannelPort, :domainMode, :domainName, :domainPartitionCount, :domainVolumeSize, :edition, :ipReservations, :managedServerCount, :msInitialHeapMB, :msJvmArgs, :msMaxHeapMB, :msMaxPermMB, :msPermMb, :nodeManagerPassword, :nodeManagerPort, :nodeManagerUserName, :overwriteMsJvmArgs, :pdbName, :securedAdminPort, :securedContentPort, :shape, :VMsPublicKey, :version].include?(key)}
  parameters.reject! { |key,value| value.nil?}
  config.reject! { |key,value| value.nil?}
  # Currently only support weblogic
  parameters[:type] = "weblogic"
  config[:parameters] = [parameters]
  body_data = config

  request({
    :method   => 'POST',
    :expects  => 202,
    :path     => "/paas/service/soa/api/v1.1/instances/#{@identity_domain}",
    :body     => Fog::JSON.encode(body_data),
    :headers  => {
     'Content-Type'=>'application/json'
    }
  }, false)
end

#delete_instance(service_name, dba_name, dba_password, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/oraclecloud/requests/soa/delete_instance.rb', line 6

def delete_instance(service_name, dba_name, dba_password, options={})
  body_data = {
    'dbaName'     => dba_name,
    'dbaPassword' => dba_password,
    'forceDelete' => options[:force_delete],
    'skipBackupOnTerminate' => options[:skip_backup]
  }

  body_data = body_data.reject {|key, value| value.nil?}
  request(
    :method   => 'PUT',
    :expects  => 202,
    :path     => "/paas/service/soa/api/v1.1/instances/#{@identity_domain}/#{service_name}",
    :body     => Fog::JSON.encode(body_data)
  )
end

#get_instance(instance_id) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/fog/oraclecloud/requests/soa/get_instance.rb', line 6

def get_instance(instance_id)
 					response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "/paas/service/soa/api/v1.1/instances/#{@identity_domain}/#{instance_id}"
  )
  response
end

#get_job_status(type, job_id) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/fog/oraclecloud/requests/soa/get_job_status.rb', line 6

def get_job_status(type, job_id)
 					response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "/paas/service/soa/api/v1.1/instances/#{@identity_domain}/status/#{type}/job/#{job_id}"
  )
  response.body['message']
end

#list_instancesObject



5
6
7
8
9
10
11
12
# File 'lib/fog/oraclecloud/requests/soa/list_instances.rb', line 5

def list_instances
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "/paas/service/soa/api/v1.1/instances/#{@identity_domain}?outputLevel=verbose"
  )
  response
end

#passwordObject



34
35
36
# File 'lib/fog/oraclecloud/soa.rb', line 34

def password
  @password
end

#request(params, parse_json = true, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/oraclecloud/soa.rb', line 42

def request(params, parse_json = true, &block)
					begin
    Fog::Logger.debug("Sending #{params[:body].to_s} to #{params[:path]}")
						response = @connection.request(params.merge!({
							:headers  => {
'Authorization' => auth_header,
'X-ID-TENANT-NAME' => @identity_domain,
        'Content-Type' => 'application/json',
        'Accept'       => 'application/json'
							}.merge!(params[:headers] || {})
						}), &block)
					rescue Excon::Errors::HTTPStatusError => error
						raise case error
						when Excon::Errors::NotFound
							Fog::OracleCloud::SOA::NotFound.slurp(error)
						else
							error
						end
					end
					if !response.body.empty? && parse_json
						# The Oracle Cloud doesn't return the Content-Type header as application/json, rather as application/vnd.com.oracle.oracloud.provisioning.Pod+json
						# Should add check here to validate, but not sure if this might change in future
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#usernameObject



30
31
32
# File 'lib/fog/oraclecloud/soa.rb', line 30

def username
  @username
end