class Fog::Compute::OracleCloud::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/oraclecloud/compute.rb, line 196
def self.data 
  @data ||= {
    :instances => {},
    :sshkeys => {},
    :orchestrations => {},
    :ip_reservations => {},
    :ip_networks => {},
    :ip_associations => {},
    :storage_attachments => {},
    :security_lists => {},
    :security_ip_lists => {},
    :security_rules => {},
    :security_associations => {},
    :security_applications => {
      "/oracle/public/all" => {
        "protocol"=>"all",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/all",
        "icmptype"=>"",
        "value2"=>0,
        "value1"=>0,
        "dport"=>nil,
        "icmpcode"=>"",
        "id"=>"cacb38ff-ecbc-4bb5-9ce2-a30f57515719",
        "name"=>"/oracle/public/all",
      },
      "/oracle/public/cloudservice"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/cloudservice",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>5020,
        "dport"=>"5020",
        "icmpcode"=>"",
        "id"=>"1a74b578-88be-4f0f-87b9-a81e69a5cc8f",
        "name"=>"/oracle/public/cloudservice"
      },
      "/oracle/public/dns-tcp"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/dns-tcp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>53,
        "dport"=>"53",
        "icmpcode"=>"",
        "id"=>"e50b2a1c-4ac8-4219-9c33-7150fbf5918c",
        "name"=>"/oracle/public/dns-tcp"
      },
      "/oracle/public/dns-udp"=>{
        "protocol"=>"udp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/dns-udp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>53,
        "dport"=>"53",
        "icmpcode"=>"",
        "id"=>"f91fa982-c40c-4f1f-aa0b-58a28f94405a",
        "name"=>"/oracle/public/dns-udp"
      },
      "/oracle/public/http"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/http",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>80,
        "dport"=>"80",
        "icmpcode"=>"",
        "id"=>"65c55823-1899-4901-9eef-1aaa1a8a2048",
        "name"=>"/oracle/public/http"
      },
      "/oracle/public/https"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/https",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>443,
        "dport"=>"443",
        "icmpcode"=>"",
        "id"=>"8b1dae32-1432-4d67-9c90-4df06dfd446c",
        "name"=>"/oracle/public/https"
      },
      "/oracle/public/icmp"=>{
        "protocol"=>"icmp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/icmp",
        "icmptype"=>"",
        "value2"=>255,
        "value1"=>255,
        "dport"=>nil,
        "icmpcode"=>"",
        "id"=>"86259853-843b-4198-8655-776c70a51c42",
        "name"=>"/oracle/public/icmp"
      },
      "/oracle/public/ldap"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ldap",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>389,
        "dport"=>"389",
        "icmpcode"=>"",
        "id"=>"6964cc80-9a97-43ef-b436-2df594f0bc20",
        "name"=>"/oracle/public/ldap"
      },
      "/oracle/public/ldaps"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ldaps",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>636,
        "dport"=>"636",
        "icmpcode"=>"",
        "id"=>"36004553-f14c-4894-a2be-77844916bc47",
        "name"=>"/oracle/public/ldaps"
      },
      "/oracle/public/mail"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/mail",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>25,
        "dport"=>"25",
        "icmpcode"=>"",
        "id"=>"62dbdede-50df-4ce3-b1d8-3194b535c208",
        "name"=>"/oracle/public/mail"
      },
      "/oracle/public/mysql"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/mysql",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>3306,
        "dport"=>"3306",
        "icmpcode"=>"",
        "id"=>"5bbf54ed-cfde-4e85-9b9a-338500806550",
        "name"=>"/oracle/public/mysql"
      },
      "/oracle/public/nfs"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/nfs",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>2049,
        "dport"=>"2049",
        "icmpcode"=>"",
        "id"=>"7ba2f9e4-7846-487a-a6d1-236ad42a09d1",
        "name"=>"/oracle/public/nfs"
      },
      "/oracle/public/ntp-tcp"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ntp-tcp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>123,
        "dport"=>"123",
        "icmpcode"=>"",
        "id"=>"2796dc84-12c4-43d1-9737-929dbbbb3901",
        "name"=>"/oracle/public/ntp-tcp"
      },
      "/oracle/public/ntp-udp"=>{
        "protocol"=>"udp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ntp-udp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>123,
        "dport"=>"123",
        "icmpcode"=>"",
        "id"=>"69c16c96-6f0d-427b-9af6-e0709926c2c1",
        "name"=>"/oracle/public/ntp-udp"
      },
      "/oracle/public/ping-reply"=>{
        "protocol"=>"icmp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ping-reply",
        "icmptype"=>"reply",
        "value2"=>0,
        "value1"=>0,
        "dport"=>nil,
        "icmpcode"=>"",
        "id"=>"a3542c2e-fd2d-47de-aa74-9ad4e49e949c",
        "name"=>"/oracle/public/ping-reply"
      },
      "/oracle/public/pings"=>{
        "protocol"=>"icmp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/pings",
        "icmptype"=>"echo",
        "value2"=>0,
        "value1"=>8,
        "dport"=>nil,
        "icmpcode"=>"",
        "id"=>"0f5f4cdf-3ce3-4e35-8eb4-18014f865c66",
        "name"=>"/oracle/public/pings"
      },
      "/oracle/public/rdp"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/rdp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>3389,
        "dport"=>"3389",
        "icmpcode"=>"",
        "id"=>"6e926962-1f63-4c11-a284-9b8faabf25ac",
        "name"=>"/oracle/public/rdp"
      },
      "/oracle/public/rpcbind"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/rpcbind",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>111,
        "dport"=>"111",
        "icmpcode"=>"",
        "id"=>"5f0228de-a2f0-4324-a1a3-d360da71a710",
        "name"=>"/oracle/public/rpcbind"
      },
      "/oracle/public/rsync"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/rsync",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>873,
        "dport"=>"873",
        "icmpcode"=>"",
        "id"=>"56df210e-326f-43a5-8625-4388c79dc219",
        "name"=>"/oracle/public/rsync"
      },
      "/oracle/public/snmp-tcp"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/snmp-tcp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>161,
        "dport"=>"161",
        "icmpcode"=>"",
        "id"=>"e9c3278a-6001-48c8-a6d6-333942c2ff77",
        "name"=>"/oracle/public/snmp-tcp"
      },
      "/oracle/public/snmp-trap-tcp"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/snmp-trap-tcp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>162,
        "dport"=>"162",
        "icmpcode"=>"",
        "id"=>"986f0200-e7ff-445a-8961-7be4581e1dc3",
        "name"=>"/oracle/public/snmp-trap-tcp"
      },
      "/oracle/public/snmp-trap-udp"=>{
        "protocol"=>"udp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/snmp-trap-udp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>162,
        "dport"=>"162",
        "icmpcode"=>"",
        "id"=>"580979e4-4c4d-4828-96c0-ba80703539ae",
        "name"=>"/oracle/public/snmp-trap-udp"
      },
      "/oracle/public/snmp-udp"=>{
        "protocol"=>"udp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/snmp-udp",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>161,
        "dport"=>"161",
        "icmpcode"=>"",
        "id"=>"143be719-8a16-4a57-9386-192778557cb8",
        "name"=>"/oracle/public/snmp-udp"
      },
      "/oracle/public/squid"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/squid",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>3128,
        "dport"=>"3128",
        "icmpcode"=>"",
        "id"=>"0e0563e8-e4c1-46de-b151-882c911e1eff",
        "name"=>"/oracle/public/squid"
      },
      "/oracle/public/ssh"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/ssh",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>22,
        "dport"=>"22",
        "icmpcode"=>"",
        "id"=>"d19fbaa7-59cf-49e6-83ad-d6d9fc4454cd",
        "name"=>"/oracle/public/ssh"
      },
      "/oracle/public/tcp5900"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/tcp5900",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>5900,
        "dport"=>"5900",
        "icmpcode"=>"",
        "id"=>"eeed882e-1ce0-4256-8d87-47f7264b8191",
        "name"=>"/oracle/public/tcp5900"
      },
      "/oracle/public/telnet"=>{
        "protocol"=>"tcp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/telnet",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>23,
        "dport"=>"23",
        "icmpcode"=>"",
        "id"=>"146a98f8-5e7e-4e7e-86c8-6d34fab52318",
        "name"=>"/oracle/public/telnet"
      },
      "/oracle/public/udp443"=>{
        "protocol"=>"udp",
        "description"=>"",
        "uri"=>
         "#{@api_endpoint}/secapplication/oracle/public/udp443",
        "icmptype"=>"",
        "value2"=>-1,
        "value1"=>443,
        "dport"=>"443",
        "icmpcode"=>"",
        "id"=>"64b4369b-9d7f-4bc4-86dd-85ba77ea9a3f",
        "name"=>"/oracle/public/udp443"
      }
    },
    :image_lists => {
      "/oracle/public/Oracle_Linux_7" => {
        "name" => "/oracle/public/Oracle_Linux_7",
        "default" => 1,
        "description" => "Oracle Linux 7",
        "entries" =>[{
          "attributes" => {},
          "version" => 1,
          "machineimages" => ["/oracle/public/OracleLinux7"],
          "uri" => "https://@api_endpoint:443/imagelist/oracle/public/OracleLinux7"
        }]
      }
    },
    :deleted_at => {}
  }
end
new(options={}) click to toggle source
# File lib/fog/oraclecloud/compute.rb, line 189
def initialize(options={})
  @username = options[:oracle_username]
  @password = options[:oracle_password]
  @identity_domain   = options[:oracle_domain]
  @api_endpoint   = options[:oracle_compute_api]
end
reset() click to toggle source
# File lib/fog/oraclecloud/compute.rb, line 592
def self.reset
  @data = nil
end

Public Instance Methods

create_instance(name, shape, imagelist, label, sshkeys) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_instance.rb, line 32
def create_instance (name, shape, imagelist, label, sshkeys)
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  self.data[:instances][name] = {
    'name' => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'shape' => shape,
    'imagelist' => imagelist,
    'label' => label,
    'sshkeys' => sshkeys,
    'state' => 'running',
    'account' => "/Compute-#{@identity_domain}/default",
    'boot_order' => [],
    'disk_attach' => '',
    'domain' => "compute-#{@identity_domain}.oraclecloud.internal",
    'entry' => 1,
    'error_reason' => '',
    'hostname' => "mock.compute-#{@identity_domain}.oraclecloud.internal",
    'hypervisor' => {"mode"=>"hvm"},
    'image_format' => 'raw',
    'ip' => '127.0.0.1',
    'networking'=> {
      "eth0"=>{
        "model"=>"", 
        "seclists"=>["/Compute-#{@identity_domain}/default/default"], 
        "dns"=>["mock.compute-#{@identity_domain}.oraclecloud.internal."], 
        "vethernet"=>"/oracle/public/default",
        "nat"=>nil
      }
    },
    'placement_requirement' => ["/system/compute/placement/default", "/system/compute/allow_instances"],
    'platform' => 'linux', # Probably? Don't rely on this in mock
    'priority' => '/oracle/public/default',
    'quota' => "/Compute-#{@identity_domain}",
    'quota_reservation' => nil,
    'resolvers' => nil,
    'reverse_dns' => true,
    'site' => '',
    'storage_attachments' => [],
    'tags' => [],
    'uri'=>"#{@api_endpoint}/instance/Compute-#{@identity_domain}/#{@username}/#{name}",
    'vcable_id'=>"/Compute-#{@identity_domain}/#{@username}/#{SecureRandom.uuid}", # TODO: add random id
    'virtio'=>nil,
    'vnc'=>'127.0.0.1:5900'
  }
  response.status = 201
  response.body = {
    'instances' => [self.data[:instances][name]]
  }
  response
end
create_ip_association(params) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_ip_association.rb, line 21
def create_ip_association (params)
  response = Excon::Response.new
  name = SecureRandom.uuid

  self.data[:ip_associations][name] = {
    'name' => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'account' => "/Compute-#{@identity_domain}/#{@username}",
    'uri' => "#{@api_endpoint}ip/reservation/Compute-#{@identity_domain}/#{@username}/#{name}",
    'parentpool' => params[:parentpool],
    'vcable' => params[:vcable]
  }
  instance = self.data[:instances].detect { |i|i[1]['vcable_id'] = params[:vcable]}
  if instance.nil? then
    # TODO: Add error handling. And don't create ip association
  else
    # Update it's networking
    instance[1]['networking']['eth0']['nat']="#{params[:parentpool]}"
  end
  response.status = 201
  response.body = self.data[:ip_associations][name]
  response
end
create_ip_network(params) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_ip_network.rb, line 25
def create_ip_network (params)
  response = Excon::Response.new
  name = params[:name]
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  self.data[:ip_networks][name] = {
    'name' => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'uri' => "#{@api_endpoint}network/v1/ipnetwork/Compute-#{@identity_domain}/#{@username}/#{name}",
    'description' => nil,
    'tags' => nil,
    'ipAddressPrefix' => params[:ipAddressPrefix],
    'ipNetworkExchange' => params[:ipNetworkExchange],
    'publicNaptEnabledFlag' => false
  }
  response.status = 201
  response.body = self.data[:ip_networks][name]
  response
end
create_ip_reservation(params) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_ip_reservation.rb, line 25
def create_ip_reservation (params)
  response = Excon::Response.new
  name = params[:name]
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:ip_reservations][name] = {
    'name' => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'account' => "/Compute-#{@identity_domain}/#{@username}",
    'used' => false,
    'tags' => params[:tags] || [],
    'ip' => '123.123.123.56',
    'uri' => "#{@api_endpoint}ip/reservation/Compute-#{@identity_domain}/#{@username}/#{name}",
    'quota' => nil,
    'parentpool' => params[:parentpool],
    'permanent' => params[:permanent]
  }
  response.status = 201
  response.body = self.data[:ip_reservations][name]
  response
end
create_orchestration(name, oplans, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_orchestration.rb, line 46
def create_orchestration (name, oplans, options={})
  response = Excon::Response.new
  # Clean up names in case they haven't provided the fully resolved names
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''
  oplans.map do |oplan|
    oplan['objects'].map do |object|
      if oplan['obj_type'] == 'launchplan' then
        object['instances'].map do |instance|
          if !instance['name'].start_with?("/Compute-") then
            instance['name'] = "/Compute-#{@identity_domain}/#{@username}/#{instance['name']}"
          end
        end
      else
        if !object['name'].start_with?("/Compute-") then
          object['name'] = "/Compute-#{@identity_domain}/#{@username}/#{object['name']}"
        end
      end
    end
  end
  self.data[:orchestrations][name] = {
    'name'          => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'oplans'        => oplans,
    'relationships' => options[:relationships],
    'description'   => options[:description],
    'account'       => options[:account],
    'schedule'      => options[:schedule],
    'status'        => 'stopped',
    'uri'           => "#{@api_endpoint}orchestration/Compute-#{@identity_domain}/#{@username}/#{name}"
  }
  response.status = 201
  response.body = self.data[:orchestrations][name]
  response
end
create_security_application(name, protocol, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_security_application.rb, line 28
def create_security_application(name, protocol, options={})
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name'                => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'protcol'             => protocol,
    'uri'                 => "#{@api_endpoint}seclist/#{name}"
  }
  self.data[:security_applications][name] = data

  response.status = 201
  response.body = self.data[:security_applications][name]
  response
end
create_security_association(name, seclist, vcable) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_security_association.rb, line 27
def create_security_association(name, seclist, vcable)
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''
  seclist.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name'                => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'seclist'             => "/Compute-#{@identity_domain}/#{@username}/#{seclist}",
    'vcable'              => vcable,
    'uri'                 => "#{@api_endpoint}secassociation/#{name}"
  }
  self.data[:security_associations][name] = data

  response.status = 201
  response.body = self.data[:security_associations][name]
  response
end
create_security_ip_list(name, description, secipentries) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_security_ip_list.rb, line 28
def create_security_ip_list(name, description, secipentries)
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name'                => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'description'         => description,
    'secipentries'        => secipentries,
    'uri'                 => "#{@api_endpoint}seclist/#{name}"
  }
  self.data[:security_ip_lists][name] = data

  response.status = 201
  response.body = self.data[:security_ip_lists][name]
  response
end
create_security_list(name, description, policy, outbound_policy) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_security_list.rb, line 29
def create_security_list(name, description, policy, outbound_policy)
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name'                => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'description'         => description,
    'policy'              => policy,
    'outbound_cidr_policy'=> outbound_policy,
    'uri'                 => "#{@api_endpoint}seclist/#{name}"
  }
  self.data[:security_lists][name] = data

  response.status = 201
  response.body = self.data[:security_lists][name]
  response
end
create_security_rule(name, src_list, dst_list, application, action, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_security_rule.rb, line 28
def create_security_rule(name, src_list, dst_list, application, action, options={})
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name'                => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'src_list'            => src_list,
    'dst_list'            => dst_list,
    'application'         => application,
    'action'              => action,
    'description'         => options[:description],
    'disabled'            => options[:disabled],
    'uri'                 => "#{@api_endpoint}secrule/#{name}"
  }
  self.data[:security_rules][name] = data

  response.status = 201
  response.body = self.data[:security_rules][name]
  response
end
create_ssh_key(name, enabled, key) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_ssh_key.rb, line 27
def create_ssh_key (name, enabled, key)
  response = Excon::Response.new
  name.sub! "/Compute-#{@identity_domain}/#{@username}/", ''

  data = {
    'name' => "/Compute-#{@identity_domain}/#{@username}/#{name}",
    'enabled' => enabled,
    'key' => key,
    'uri' => "#{@api_endpoint}sshkey/#{name}"
  }
  self.data[:sshkeys][name] = data

  response.status = 201
  response.body = self.data[:sshkeys][name]
  response
end
create_storage_attachment(params) click to toggle source
# File lib/fog/oraclecloud/requests/compute/create_storage_attachment.rb, line 31
def create_storage_attachment (params)
  response = Excon::Response.new

  guid = SecureRandom.uuid
  name = "#{params[:instance_name]}/#{guid}"

  self.data[:storage_attachments][name] = {
    'index' => params[:index],
    'account' => nil,
    'storage_volume_name' => params[:storage_volume_name],
    'hypervisor' => nil,
    'uri' => "#{@api_endpoint}/storage/attachment/#{name}",
    'instance_name' => params[:instance_name],
    'state' => 'attaching',
    'readonly' => false,
    'name' => name
  }
  response.status = 201
  response.body = self.data[:storage_attachments][name]
  response
end
data() click to toggle source
# File lib/fog/oraclecloud/compute.rb, line 596
def data 
  self.class.data
end
delete_instance(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_instance.rb, line 22
def delete_instance(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:instances][clean_name]['state'] = 'stopping'
  self.data[:deleted_at][clean_name] = Time.now
  response.status = 204
  response
end
delete_ip_network(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_ip_network.rb, line 19
def delete_ip_network(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:ip_networks].delete(clean_name)
  response.status = 204
  response
end
delete_ip_reservation(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_ip_reservation.rb, line 19
def delete_ip_reservation(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:ip_reservations].delete(clean_name)
  response.status = 204
  response
end
delete_orchestration(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_orchestration.rb, line 22
def delete_orchestration (name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if self.data[:orchestrations][clean_name] 
    self.data[:orchestrations].delete(clean_name)
    response.status = 204
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Orchestration #{name} does not exist");
  end
end
delete_security_list(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_security_list.rb, line 19
def delete_security_list(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:security_lists].delete(clean_name)
  response.status = 204
  response
end
delete_ssh_key(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/delete_ssh_key.rb, line 22
def delete_ssh_key (name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  self.data[:sshkeys].delete(clean_name)
  response.status = 204
  response
end
get_instance(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_instance.rb, line 24
def get_instance(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if instance = self.data[:instances][clean_name] 
    if instance['state'] == 'stopping'
      if Time.now - self.data[:deleted_at][clean_name] >= Fog::Mock.delay
        self.data[:deleted_at].delete(clean_name)
        self.data[:instances].delete(clean_name)
      end
    end
    response.status = 200
    response.body = instance
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("Instance #{name} does not exist");
  end
end
get_ip_association(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_ip_association.rb, line 21
def get_ip_association(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if ip = self.data[:ip_associations][clean_name] 
    response.status = 200
    response.body = ip
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("IP Association #{name} does not exist");
  end
end
get_ip_network(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_ip_network.rb, line 21
def get_ip_network(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if ip = self.data[:ip_networks][clean_name] 
    response.status = 200
    response.body = ip
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("IP Network #{name} does not exist");
  end
end
get_ip_reservation(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_ip_reservation.rb, line 21
def get_ip_reservation(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if ip = self.data[:ip_reservations][clean_name] 
    response.status = 200
    response.body = ip
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("IP Reservation #{name} does not exist");
  end
end
get_orchestration(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_orchestration.rb, line 24
def get_orchestration(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if instance = self.data[:orchestrations][clean_name] 
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Orchestration #{name} does not exist");
  end
end
get_security_application(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_security_application.rb, line 26
def get_security_application(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if app = self.data[:security_applications][clean_name] 
    response.status = 200
    response.body = app
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Security application #{name} does not exist");
  end
end
get_security_ip_list(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_security_ip_list.rb, line 22
def get_security_ip_list(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if instance = self.data[:security_ip_lists][clean_name] 
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Security IP List #{name} does not exist");
  end
end
get_security_list(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_security_list.rb, line 22
def get_security_list(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if instance = self.data[:security_lists][clean_name] 
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Security List #{name} does not exist");
  end
end
get_security_rule(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_security_rule.rb, line 22
def get_security_rule(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if instance = self.data[:security_rules][clean_name] 
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Security Rule #{name} does not exist");
  end
end
get_ssh_key(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_ssh_key.rb, line 24
def get_ssh_key(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if sshkey = self.data[:sshkeys][clean_name] 
    response.status = 200
    response.body = sshkey
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("SSHKey #{name} does not exist");
  end
end
get_storage_attachment(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/get_storage_attachment.rb, line 21
def get_storage_attachment(name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if sa = self.data[:storage_attachments][clean_name] 
    response.status = 200
    response.body = sa
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("Storage Attachment #{name} does not exist");
  end
end
list_image_lists() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_image_lists.rb, line 16
def list_image_lists
  response = Excon::Response.new

  images = self.data[:image_lists].values

  response.body = {
    'result' => images
  }
  response
end
list_instances() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_instances.rb, line 15
def list_instances
  response = Excon::Response.new

  instances = self.data[:instances].values

  response.body = {
    'result' => instances
  }
  response
end
list_ip_associations() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_ip_associations.rb, line 16
def list_ip_associations
  response = Excon::Response.new

  ips = self.data[:ip_associations].values
  response.body = {
    'result' => ips
  }
  response
end
list_ip_networks() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_ip_networks.rb, line 16
def list_ip_networks
  response = Excon::Response.new

  ips = self.data[:ip_networks].values
  response.body = {
    'result' => ips
  }
  response
end
list_ip_reservations() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_ip_reservations.rb, line 16
def list_ip_reservations
  response = Excon::Response.new

  ips = self.data[:ip_reservations].values
  response.body = {
    'result' => ips
  }
  response
end
list_orchestrations() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_orchestrations.rb, line 16
def list_orchestrations
  response = Excon::Response.new

  orchs = self.data[:orchestrations].values
  response.body = {
    'result' => orchs
  }
  response
end
list_security_applications(public_list=false) click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_security_applications.rb, line 21
def list_security_applications(public_list=false)
  response = Excon::Response.new
  if public_list then check = "/oracle/public" 
  else check = "/Compute-" end
  instances = self.data[:security_applications].values.select { |app| app['name'].include? check}
  response.body = {
    'result' => instances
  }
  response
end
list_security_rules() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_security_rules.rb, line 16
def list_security_rules
end
list_ssh_keys() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_ssh_keys.rb, line 16
def list_ssh_keys
  response = Excon::Response.new

  sshkeys = self.data[:sshkeys].values

  response.body = {
    'result' => sshkeys
  }
  response
end
list_storage_attachments() click to toggle source
# File lib/fog/oraclecloud/requests/compute/list_storage_attachments.rb, line 16
def list_storage_attachments
  response = Excon::Response.new

  sas = self.data[:storage_attachments].values
  response.body = {
    'result' => sas
  }
  response
end
start_orchestration(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/start_orchestration.rb, line 22
def start_orchestration (name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if self.data[:orchestrations][clean_name] 
    self.data[:orchestrations][clean_name]['status'] = 'running'
    instance = self.data[:orchestrations][clean_name]
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Orchestration #{name} does not exist");
  end
end
stop_orchestration(name) click to toggle source
# File lib/fog/oraclecloud/requests/compute/stop_orchestration.rb, line 22
def stop_orchestration (name)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''

  if self.data[:orchestrations][clean_name] 
    self.data[:orchestrations][clean_name]['status'] = 'stopped'
    instance = self.data[:orchestrations][clean_name]
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::Compute::OracleCloud::NotFound.new("Orchestration #{name} does not exist");
  end
end
update_ip_reservation(params) click to toggle source
# File lib/fog/oraclecloud/requests/compute/update_ip_reservation.rb, line 24
def update_ip_reservation (params)
  response = Excon::Response.new
  clean_name = params[:name].sub "/Compute-#{@identity_domain}/#{@username}/", ''
  
  ip = self.data[:ip_reservations][clean_name].merge!(params.stringify_keys)
  if !ip['permanent'] && !ip['used'] then
    # An unused IP reservation that is no longer permanent will be deleted
    self.data[:ip_reservations].delete(clean_name)
  end

  response.status = 200
  response.body = ip
  response
end
update_orchestration(name, oplans, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/compute/update_orchestration.rb, line 49
def update_orchestration (name, oplans, options={})
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if orchestration = self.data[:orchestrations][clean_name] 
    oplans.map do |oplan|
      oplan['objects'].map do |object|
        if oplan['obj_type'] == 'launchplan' then
          object['instances'].map do |instance|
            if !instance['name'].start_with?("/Compute-") then
              instance['name'] = "/Compute-#{@identity_domain}/#{@username}/#{instance['name']}"
            end
          end
        else
          if !object['name'].start_with?("/Compute-") then
            object['name'] = "/Compute-#{@identity_domain}/#{@username}/#{object['name']}"
          end
        end
      end
    end
    self.data[:orchestrations][clean_name].merge!(options)
    self.data[:orchestrations][clean_name]['oplans'] = oplans
    response.status = 200
    response.body = self.data[:orchestrations][clean_name]
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("Orchestration #{name} does not exist");
  end
end
update_ssh_key(uri, name, enabled, key) click to toggle source
# File lib/fog/oraclecloud/requests/compute/update_ssh_key.rb, line 29
def update_ssh_key (uri, name, enabled, key)
  response = Excon::Response.new
  clean_name = name.sub "/Compute-#{@identity_domain}/#{@username}/", ''
  if sshkey = self.data[:sshkeys][clean_name] 
    self.data[:sshkeys][clean_name].merge!({
      'name' => "/Compute-#{@identity_domain}/#{@username}/#{clean_name}",
      'enabled' => enabled,
      'key' => key,
      'uri' => "#{@api_endpoint}sshkey/#{clean_name}"              
    })
    response.status = 200
    response.body = self.data[:sshkeys][clean_name]
    response
  else;
    raise Fog::Compute::OracleCloud::NotFound.new("SSHKey #{name} does not exist");
  end
end