Class: Fog::OracleCloud::Java::Real

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



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

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



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

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

#create_instance(service_name, cloudStorageContainer, cloudStorageUser, cloudStoragePassword, dbaName, dbaPassword, dbServiceName, shape, version, vmPublicKey, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/oraclecloud/requests/java/create_instance.rb', line 6

def create_instance(service_name, cloudStorageContainer, cloudStorageUser, cloudStoragePassword, dbaName, dbaPassword, dbServiceName, shape, version, vmPublicKey, options={})
  if !cloudStorageContainer.start_with?("/Storage-") then
    # They haven't provided a well formed container name, add their details in

    name = "/Storage-#{@identity_domain}/#{@username}/#{cloudStorageContainer}"
  end   
  body_data     = {
    'serviceName'             => service_name,
    'cloudStorageContainer'   => cloudStorageContainer,
    'cloudStorageUser'        => cloudStorageUser,
    'cloudStoragePassword'    => cloudStoragePassword,
    'parameters'              => parameters,
    'level'                   => options[:level],
    'subscriptionType'        => options[:subscriptionType],
    'description'             => options[:description],
    'provisionOTD'            => options[:provisionOTD],
    'sampleAppDeploymentRequests' => options[:sampleAppDeploymentRequests]
  }
  body_data = body_data.reject {|key, value| value.nil?}
  request(
    :method   => 'POST',
    :expects  => 202,
    :path     => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}",
    :body     => Fog::JSON.encode(body_data),
    :headers  => {
      'Content-Type'=>'application/vnd.com.oracle.oracloud.provisioning.Service+json'
    }
  )
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
22
23
# File 'lib/fog/oraclecloud/requests/java/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]
  }

  body_data = body_data.reject {|key, value| value.nil?}
  request(
    :method   => 'PUT',
    :expects  => 202,
    :path     => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}",
    :body     => Fog::JSON.encode(body_data),
    :headers  => {
      'Content-Type'=>'application/vnd.com.oracle.oracloud.provisioning.Service+json'
    }
  )
end

#get_instance(service_name) ⇒ Object



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

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

#list_instancesObject



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

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

#list_servers(service_name) ⇒ Object



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

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

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fog/oraclecloud/java.rb', line 34

def request(params, parse_json = true, &block)
          begin
            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::Java::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