Class: Fog::Compute::OracleCloud::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/oraclecloud/compute.rb,
lib/fog/oraclecloud/requests/compute/get_ssh_key.rb,
lib/fog/oraclecloud/requests/compute/get_instance.rb,
lib/fog/oraclecloud/requests/compute/list_ssh_keys.rb,
lib/fog/oraclecloud/requests/compute/create_ssh_key.rb,
lib/fog/oraclecloud/requests/compute/delete_ssh_key.rb,
lib/fog/oraclecloud/requests/compute/get_ip_network.rb,
lib/fog/oraclecloud/requests/compute/list_instances.rb,
lib/fog/oraclecloud/requests/compute/update_ssh_key.rb,
lib/fog/oraclecloud/requests/compute/create_instance.rb,
lib/fog/oraclecloud/requests/compute/delete_instance.rb,
lib/fog/oraclecloud/requests/compute/list_image_lists.rb,
lib/fog/oraclecloud/requests/compute/list_ip_networks.rb,
lib/fog/oraclecloud/requests/compute/create_ip_network.rb,
lib/fog/oraclecloud/requests/compute/delete_ip_network.rb,
lib/fog/oraclecloud/requests/compute/get_orchestration.rb,
lib/fog/oraclecloud/requests/compute/get_security_list.rb,
lib/fog/oraclecloud/requests/compute/get_security_rule.rb,
lib/fog/oraclecloud/requests/compute/get_ip_association.rb,
lib/fog/oraclecloud/requests/compute/get_ip_reservation.rb,
lib/fog/oraclecloud/requests/compute/stop_orchestration.rb,
lib/fog/oraclecloud/requests/compute/list_orchestrations.rb,
lib/fog/oraclecloud/requests/compute/list_security_rules.rb,
lib/fog/oraclecloud/requests/compute/start_orchestration.rb,
lib/fog/oraclecloud/requests/compute/create_orchestration.rb,
lib/fog/oraclecloud/requests/compute/create_security_list.rb,
lib/fog/oraclecloud/requests/compute/create_security_rule.rb,
lib/fog/oraclecloud/requests/compute/delete_orchestration.rb,
lib/fog/oraclecloud/requests/compute/delete_security_list.rb,
lib/fog/oraclecloud/requests/compute/get_security_ip_list.rb,
lib/fog/oraclecloud/requests/compute/list_ip_associations.rb,
lib/fog/oraclecloud/requests/compute/list_ip_reservations.rb,
lib/fog/oraclecloud/requests/compute/update_orchestration.rb,
lib/fog/oraclecloud/requests/compute/create_ip_association.rb,
lib/fog/oraclecloud/requests/compute/create_ip_reservation.rb,
lib/fog/oraclecloud/requests/compute/delete_ip_reservation.rb,
lib/fog/oraclecloud/requests/compute/update_ip_reservation.rb,
lib/fog/oraclecloud/requests/compute/get_storage_attachment.rb,
lib/fog/oraclecloud/requests/compute/create_security_ip_list.rb,
lib/fog/oraclecloud/requests/compute/get_security_application.rb,
lib/fog/oraclecloud/requests/compute/list_storage_attachments.rb,
lib/fog/oraclecloud/requests/compute/create_storage_attachment.rb,
lib/fog/oraclecloud/requests/compute/list_security_applications.rb,
lib/fog/oraclecloud/requests/compute/create_security_application.rb,
lib/fog/oraclecloud/requests/compute/create_security_association.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



189
190
191
192
193
194
# 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

Class Method Details

.dataObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# 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

.resetObject



592
593
594
# File 'lib/fog/oraclecloud/compute.rb', line 592

def self.reset
  @data = nil
end

Instance Method Details

#create_instance(name, shape, imagelist, label, sshkeys) ⇒ Object



32
33
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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 = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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 = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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 = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

#dataObject



596
597
598
# File 'lib/fog/oraclecloud/compute.rb', line 596

def data 
  self.class.data
end

#delete_instance(name) ⇒ Object



22
23
24
25
26
27
28
29
# 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) ⇒ Object



19
20
21
22
23
24
25
# 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) ⇒ Object



19
20
21
22
23
24
25
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



19
20
21
22
23
24
25
# 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) ⇒ Object



22
23
24
25
26
27
28
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# 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_listsObject



16
17
18
19
20
21
22
23
24
25
# 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_instancesObject



15
16
17
18
19
20
21
22
23
24
# 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_associationsObject



16
17
18
19
20
21
22
23
24
# 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_networksObject



16
17
18
19
20
21
22
23
24
# 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_reservationsObject



16
17
18
19
20
21
22
23
24
# 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_orchestrationsObject



16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# 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_rulesObject



16
17
# File 'lib/fog/oraclecloud/requests/compute/list_security_rules.rb', line 16

def list_security_rules
end

#list_ssh_keysObject



16
17
18
19
20
21
22
23
24
25
# 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_attachmentsObject



16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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 = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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