class Fog::OracleCloud::Java::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/oraclecloud/java.rb, line 33
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

Public Instance Methods

auth_header() click to toggle source
# File lib/fog/oraclecloud/java.rb, line 51
def auth_header
        auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
end
create_access_rule(service_name, params) click to toggle source
# File lib/fog/oraclecloud/requests/java/create_access_rule.rb, line 6
def create_access_rule(service_name, params)
  request(
    :method   => 'POST',
    :expects  => 202,
    :path     => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/jaas/instances/#{service_name}/accessrules",
    :body     => Fog::JSON.encode(params)
  )
end
create_instance(config, options) click to toggle source
# File lib/fog/oraclecloud/requests/java/create_instance.rb, line 6
def create_instance(config, options)
  
  if !config[:cloudStorageContainer].start_with?("/Storage-")
    config[:cloudStorageContainer] = "/Storage-#{@identity_domain}/#{config[:cloudStorageContainer]}"
  end

  config[: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].include?(key)}
  config[:parameters].reject! { |key,value| value.nil?}
  config.reject! { |key,value| value.nil?}
  # Currently only support weblogic
  config[:parameters][:type] = "weblogic"

  body_data = config

  request(
    :method   => 'POST',
    :expects  => 202,
    :path     => "/paas/service/dbcs/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_access_rule(service_name, rule_name) click to toggle source
# File lib/fog/oraclecloud/requests/java/delete_access_rule.rb, line 6
def delete_access_rule(service_name, rule_name)
  body_data = {
    'operation'=> 'delete'
  }

  request(
    :method   => 'PUT',
    :expects  => 202,
    :path     => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/jaas/instances/#{service_name}/accessrules/#{rule_name}",
    :body     => Fog::JSON.encode(body_data)
  )
end
delete_instance(service_name, dba_name, dba_password, options={}) click to toggle source
# 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
enable_access_rule(service_name, rule_name) click to toggle source
# File lib/fog/oraclecloud/requests/java/enable_access_rule.rb, line 6
def enable_access_rule(service_name, rule_name)
  body_data = {
    'operation'=> 'update',
    'status' => 'enabled'
  }

  request(
    :method   => 'PUT',
    :expects  => 200,
    :path     => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/jaas/instances/#{service_name}/accessrules/#{rule_name}",
    :body     => Fog::JSON.encode(body_data)
  )
end
get_instance(service_name) click to toggle source
# 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
get_server(service_name, server_name) click to toggle source
# File lib/fog/oraclecloud/requests/java/get_server.rb, line 6
def get_server(service_name, server_name)
                                response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/servers/#{server_name}"
  )
  response
end
list_access_rules(service_name) click to toggle source
# File lib/fog/oraclecloud/requests/java/list_access_rules.rb, line 5
def list_access_rules(service_name)
  response = request(
    :expects  => 200,
    :method   => 'GET',
    :path     => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/jaas/instances/#{service_name}/accessrules"
  )
  response
end
list_instances() click to toggle source
# 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) click to toggle source
# 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
password() click to toggle source
# File lib/fog/oraclecloud/java.rb, line 46
def password
  @password
end
request(params, parse_json = true, &block) click to toggle source
# File lib/fog/oraclecloud/java.rb, line 55
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::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
scale_a_node(service_name, server_name, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/java/scale_a_node.rb, line 6
def scale_a_node(service_name, server_name, options={})

  path = "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/#{server_name}"
  body_data     = {
    'shape'             => options[:shape],
    'additionalStorage' => options[:additionalStorage],
    'ignoreManagedServerHeapError' =>  options[:ignoreManagedServerHeapError],
    'scalingVolume'             => options[:scalingVolume]
  }
  body_data = body_data.reject {|key, value| value.nil?}

              response = request(
    :expects  => 202,
    :method   => 'PUT',
    :path     => path,
    :body     => Fog::JSON.encode(body_data)
  )
  response
end
scale_in_a_cluster(service_name, server_name) click to toggle source
# File lib/fog/oraclecloud/requests/java/scale_in_a_cluster.rb, line 6
def scale_in_a_cluster(service_name, server_name)

  path = "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/servers/#{server_name}"

          response = request(
    :expects  => 202,
    :method   => 'DELETE',
    :path     => path
  )
  response
end
scale_out_a_cluster(service_name, cluster_name, create_cluster_if_missing) click to toggle source
# File lib/fog/oraclecloud/requests/java/scale_out_a_cluster.rb, line 6
def scale_out_a_cluster(service_name, cluster_name, create_cluster_if_missing)

  path = "/paas/service/jcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/servers/#{cluster_name}"
  if create_cluster_if_missing then
    path = "#{path}?createClusterIfMissing=true"
  end

              response = request(
    :expects  => 202,
    :method   => 'POST',
    :path     => path
  )
  response
end
username() click to toggle source
# File lib/fog/oraclecloud/java.rb, line 42
def username
  @username
end