fog-oraclecloud 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +21 -0
  5. data/README.md +34 -0
  6. data/Rakefile +2 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/fog-oracle.gemspec +30 -0
  10. data/lib/fog/oraclecloud/compute.rb +146 -0
  11. data/lib/fog/oraclecloud/database.rb +114 -0
  12. data/lib/fog/oraclecloud/java.rb +114 -0
  13. data/lib/fog/oraclecloud/models/compute/image.rb +43 -0
  14. data/lib/fog/oraclecloud/models/compute/image_list.rb +42 -0
  15. data/lib/fog/oraclecloud/models/compute/image_lists.rb +22 -0
  16. data/lib/fog/oraclecloud/models/compute/images.rb +22 -0
  17. data/lib/fog/oraclecloud/models/compute/instance.rb +65 -0
  18. data/lib/fog/oraclecloud/models/compute/instances.rb +22 -0
  19. data/lib/fog/oraclecloud/models/compute/object_plan.rb +16 -0
  20. data/lib/fog/oraclecloud/models/compute/object_plans.rb +12 -0
  21. data/lib/fog/oraclecloud/models/compute/orchestration.rb +89 -0
  22. data/lib/fog/oraclecloud/models/compute/orchestrations.rb +20 -0
  23. data/lib/fog/oraclecloud/models/compute/security_application.rb +42 -0
  24. data/lib/fog/oraclecloud/models/compute/security_applications.rb +22 -0
  25. data/lib/fog/oraclecloud/models/compute/security_list.rb +26 -0
  26. data/lib/fog/oraclecloud/models/compute/security_lists.rb +22 -0
  27. data/lib/fog/oraclecloud/models/compute/security_rule.rb +41 -0
  28. data/lib/fog/oraclecloud/models/compute/security_rules.rb +22 -0
  29. data/lib/fog/oraclecloud/models/compute/ssh_key.rb +37 -0
  30. data/lib/fog/oraclecloud/models/compute/ssh_keys.rb +22 -0
  31. data/lib/fog/oraclecloud/models/compute/volume.rb +47 -0
  32. data/lib/fog/oraclecloud/models/compute/volumes.rb +20 -0
  33. data/lib/fog/oraclecloud/models/database/instance.rb +84 -0
  34. data/lib/fog/oraclecloud/models/database/instances.rb +26 -0
  35. data/lib/fog/oraclecloud/models/java/instance.rb +107 -0
  36. data/lib/fog/oraclecloud/models/java/instances.rb +27 -0
  37. data/lib/fog/oraclecloud/models/java/server.rb +26 -0
  38. data/lib/fog/oraclecloud/models/java/servers.rb +17 -0
  39. data/lib/fog/oraclecloud/models/soa/instance.rb +65 -0
  40. data/lib/fog/oraclecloud/models/soa/instances.rb +25 -0
  41. data/lib/fog/oraclecloud/models/storage/container.rb +34 -0
  42. data/lib/fog/oraclecloud/models/storage/containers.rb +24 -0
  43. data/lib/fog/oraclecloud/models/storage/object.rb +27 -0
  44. data/lib/fog/oraclecloud/models/storage/objects.rb +27 -0
  45. data/lib/fog/oraclecloud/requests/compute/create_image.rb +30 -0
  46. data/lib/fog/oraclecloud/requests/compute/create_image_list.rb +27 -0
  47. data/lib/fog/oraclecloud/requests/compute/create_instance.rb +32 -0
  48. data/lib/fog/oraclecloud/requests/compute/create_orchestration.rb +46 -0
  49. data/lib/fog/oraclecloud/requests/compute/create_security_application.rb +28 -0
  50. data/lib/fog/oraclecloud/requests/compute/create_security_rule.rb +29 -0
  51. data/lib/fog/oraclecloud/requests/compute/create_ssh_key.rb +27 -0
  52. data/lib/fog/oraclecloud/requests/compute/create_volume.rb +29 -0
  53. data/lib/fog/oraclecloud/requests/compute/delete_image.rb +19 -0
  54. data/lib/fog/oraclecloud/requests/compute/delete_image_list.rb +19 -0
  55. data/lib/fog/oraclecloud/requests/compute/delete_instance.rb +22 -0
  56. data/lib/fog/oraclecloud/requests/compute/delete_orchestration.rb +22 -0
  57. data/lib/fog/oraclecloud/requests/compute/delete_security_application.rb +20 -0
  58. data/lib/fog/oraclecloud/requests/compute/delete_security_rule.rb +20 -0
  59. data/lib/fog/oraclecloud/requests/compute/delete_ssh_key.rb +22 -0
  60. data/lib/fog/oraclecloud/requests/compute/get_image.rb +21 -0
  61. data/lib/fog/oraclecloud/requests/compute/get_image_list.rb +21 -0
  62. data/lib/fog/oraclecloud/requests/compute/get_instance.rb +24 -0
  63. data/lib/fog/oraclecloud/requests/compute/get_orchestration.rb +24 -0
  64. data/lib/fog/oraclecloud/requests/compute/get_security_application.rb +20 -0
  65. data/lib/fog/oraclecloud/requests/compute/get_security_rule.rb +20 -0
  66. data/lib/fog/oraclecloud/requests/compute/get_ssh_key.rb +24 -0
  67. data/lib/fog/oraclecloud/requests/compute/list_image_lists.rb +16 -0
  68. data/lib/fog/oraclecloud/requests/compute/list_images.rb +16 -0
  69. data/lib/fog/oraclecloud/requests/compute/list_instances.rb +16 -0
  70. data/lib/fog/oraclecloud/requests/compute/list_orchestrations.rb +16 -0
  71. data/lib/fog/oraclecloud/requests/compute/list_security_applications.rb +21 -0
  72. data/lib/fog/oraclecloud/requests/compute/list_security_lists.rb +16 -0
  73. data/lib/fog/oraclecloud/requests/compute/list_security_rules.rb +21 -0
  74. data/lib/fog/oraclecloud/requests/compute/list_ssh_keys.rb +16 -0
  75. data/lib/fog/oraclecloud/requests/compute/list_volumes.rb +16 -0
  76. data/lib/fog/oraclecloud/requests/compute/start_orchestration.rb +22 -0
  77. data/lib/fog/oraclecloud/requests/compute/stop_orchestration.rb +22 -0
  78. data/lib/fog/oraclecloud/requests/compute/update_image.rb +27 -0
  79. data/lib/fog/oraclecloud/requests/compute/update_image_list.rb +27 -0
  80. data/lib/fog/oraclecloud/requests/compute/update_orchestration.rb +49 -0
  81. data/lib/fog/oraclecloud/requests/compute/update_ssh_key.rb +29 -0
  82. data/lib/fog/oraclecloud/requests/database/create_instance.rb +46 -0
  83. data/lib/fog/oraclecloud/requests/database/delete_instance.rb +31 -0
  84. data/lib/fog/oraclecloud/requests/database/get_instance.rb +36 -0
  85. data/lib/fog/oraclecloud/requests/database/list_instances.rb +16 -0
  86. data/lib/fog/oraclecloud/requests/java/create_instance.rb +51 -0
  87. data/lib/fog/oraclecloud/requests/java/delete_instance.rb +42 -0
  88. data/lib/fog/oraclecloud/requests/java/get_instance.rb +37 -0
  89. data/lib/fog/oraclecloud/requests/java/get_server.rb +0 -0
  90. data/lib/fog/oraclecloud/requests/java/list_instances.rb +16 -0
  91. data/lib/fog/oraclecloud/requests/java/list_servers.rb +29 -0
  92. data/lib/fog/oraclecloud/requests/soa/create_instance.rb +47 -0
  93. data/lib/fog/oraclecloud/requests/soa/delete_instance.rb +40 -0
  94. data/lib/fog/oraclecloud/requests/soa/get_instance.rb +36 -0
  95. data/lib/fog/oraclecloud/requests/soa/list_instances.rb +16 -0
  96. data/lib/fog/oraclecloud/requests/storage/create_container.rb +21 -0
  97. data/lib/fog/oraclecloud/requests/storage/delete_container.rb +15 -0
  98. data/lib/fog/oraclecloud/requests/storage/get_container.rb +24 -0
  99. data/lib/fog/oraclecloud/requests/storage/list_containers.rb +16 -0
  100. data/lib/fog/oraclecloud/soa.rb +80 -0
  101. data/lib/fog/oraclecloud/storage.rb +80 -0
  102. data/lib/fog/oraclecloud/version.rb +5 -0
  103. data/lib/fog/oraclecloud.rb +29 -0
  104. data/tests/helper.rb +1 -0
  105. data/tests/requests/database_tests.rb +52 -0
  106. data/tests/requests/instance_tests.rb +54 -0
  107. data/tests/requests/java_tests.rb +52 -0
  108. data/tests/requests/orchestrations_tests.rb +86 -0
  109. data/tests/requests/soa_tests.rb +52 -0
  110. data/tests/requests/ssh_keys_tests.rb +49 -0
  111. data/tests/requests/storage_tests.rb +54 -0
  112. metadata +253 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 723b71ff79264ce5b33642486c3ee7964af90673
4
+ data.tar.gz: 9fbd33b824585600ecf73dbccd0730362182b893
5
+ SHA512:
6
+ metadata.gz: ee21600f5d7589284db68160004784d6060351f3852460125ce65766a703bb720dadfe46009c117ccd7df45e73d48c4d2b589e9cb096065aa06c300120f85765
7
+ data.tar.gz: 3ea277d567db75726c317d75cce0601b299120a5343769011816f4f619d4a555882e9d3123352f51833a86acba3a1149beda4b502339f038e4a1d4cfcb294bfa
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-oracle.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Oracle Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Fog::OracleCloud
2
+
3
+ Module for the 'fog' gem to support the Oracle Cloud (IaaS and PaaS)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fog-oraclecloud'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fog-oraclecloud
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fog-oracle.
34
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fog/oracle"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/oraclecloud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-oraclecloud"
8
+ spec.version = Fog::OracleCloud::VERSION
9
+ spec.authors = ["Joel Nation"]
10
+ spec.email = ["joel.nation@oracle.com"]
11
+
12
+ spec.summary = %q{Module for the 'fog' gem to support Oracle Cloud Services.}
13
+ spec.description = %q{This library can be used as a module for `fog` or as standalone provider to use the Oracle Cloud Service in applications.}
14
+ spec.homepage = "http://github.com/Joelith/fog-oraclecloud"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "shindo", "~> 0.3"
25
+
26
+ spec.add_dependency 'fog-core', '~> 1.38'
27
+ spec.add_dependency 'fog-json', '~>1.0'
28
+ spec.add_dependency 'fog-xml', '~>0.1'
29
+ spec.add_dependency 'ipaddress', '~>0.8'
30
+ end
@@ -0,0 +1,146 @@
1
+ module Fog
2
+ module Compute
3
+ class OracleCloud < Fog::Service
4
+ requires :oracle_username, :oracle_password, :oracle_domain, :oracle_compute_api
5
+
6
+ model_path 'fog/oraclecloud/models/compute'
7
+ model :security_application
8
+ collection :security_applications
9
+
10
+ model :security_rule
11
+ collection :security_rules
12
+
13
+ model :security_list
14
+ collection :security_lists
15
+
16
+ model :image
17
+ collection :images
18
+
19
+ model :image_list
20
+ collection :image_lists
21
+
22
+ model :instance
23
+ collection :instances
24
+
25
+ model :ssh_key
26
+ collection :ssh_keys
27
+
28
+ model :object_plan
29
+ collection :object_plans
30
+ model :orchestration
31
+ collection :orchestrations
32
+
33
+ model :volume
34
+ collection :volumes
35
+
36
+ request_path 'fog/oraclecloud/requests/compute'
37
+ request :list_security_applications
38
+ request :create_security_application
39
+ request :delete_security_application
40
+ request :get_security_application
41
+
42
+ request :list_security_rules
43
+ request :create_security_rule
44
+ request :delete_security_rule
45
+ request :get_security_rule
46
+
47
+ request :list_security_lists
48
+
49
+ request :get_image
50
+ request :create_image
51
+ request :delete_image
52
+ request :list_images
53
+
54
+ request :list_image_lists
55
+ request :get_image_list
56
+ request :create_image_list
57
+ request :update_image_list
58
+ request :delete_image_list
59
+
60
+ request :list_instances
61
+ request :get_instance
62
+ request :create_instance
63
+ request :delete_instance
64
+
65
+ request :list_ssh_keys
66
+ request :get_ssh_key
67
+ request :create_ssh_key
68
+ request :delete_ssh_key
69
+ request :update_ssh_key
70
+
71
+ request :get_orchestration
72
+ request :list_orchestrations
73
+ request :create_orchestration
74
+ request :update_orchestration
75
+ request :delete_orchestration
76
+ request :start_orchestration
77
+ request :stop_orchestration
78
+
79
+ request :list_volumes
80
+ request :create_volume
81
+
82
+ class Real
83
+
84
+ def initialize(options={})
85
+ @username = options[:oracle_username]
86
+ @password = options[:oracle_password]
87
+ @identity_domain = options[:oracle_domain]
88
+ @api_endpoint = options[:oracle_compute_api]
89
+
90
+ @connection = Fog::XML::Connection.new(@api_endpoint)
91
+
92
+ # Get authentication token
93
+ authenticate
94
+ end
95
+
96
+ def authenticate()
97
+
98
+ begin
99
+ response = @connection.request({
100
+ :expects => 204,
101
+ :method => 'POST',
102
+ :path => "/authenticate/",
103
+ :headers => {
104
+ 'Content-Type' => 'application/oracle-compute-v3+json'
105
+ },
106
+ :body => Fog::JSON.encode({
107
+ 'user' => "/Compute-#{@identity_domain}/#{@username}",
108
+ 'password'=> @password
109
+ })
110
+ })
111
+ rescue Excon::Errors::HTTPStatusError => error
112
+ error
113
+ end
114
+ if response.nil? || !response.headers['Set-Cookie'] then
115
+ raise Error.new('Could not authenticate to Compute Cloud Service. Check your athentication details in your config')
116
+ end
117
+ @auth_cookie = response.headers['Set-Cookie']
118
+ end
119
+
120
+ def request(params, parse_json = true, &block)
121
+ begin
122
+ response = @connection.request(params.merge!({
123
+ :headers => {
124
+ 'Cookie' => @auth_cookie
125
+ }.merge!(params[:headers] || {})
126
+ }), &block)
127
+ rescue Excon::Errors::HTTPStatusError => error
128
+ raise case error
129
+ #when Excon::Errors::NotFound
130
+ #Fog::Oracle::Java::NotFound.slurp(error)
131
+ when Excon::Errors::Conflict
132
+ data = Fog::JSON.decode(error.response.body)
133
+ raise Error.new(data['message'])
134
+ else
135
+ error
136
+ end
137
+ end
138
+ if !response.body.empty? && parse_json
139
+ response.body = Fog::JSON.decode(response.body)
140
+ end
141
+ response
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,114 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database < Fog::Service
4
+ requires :oracle_username, :oracle_password, :oracle_domain, :oracle_region
5
+
6
+ model_path 'fog/oraclecloud/models/database'
7
+ model :instance
8
+ collection :instances
9
+
10
+ request_path 'fog/oraclecloud/requests/database'
11
+ request :list_instances
12
+ request :get_instance
13
+ request :create_instance
14
+ request :delete_instance
15
+
16
+ class Real
17
+
18
+ def initialize(options={})
19
+ @username = options[:oracle_username]
20
+ @password = options[:oracle_password]
21
+ @identity_domain = options[:oracle_domain]
22
+ region_url = options[:oracle_region] == 'emea' ? 'https://dbcs.emea.oraclecloud.com' : 'https://dbaas.oraclecloud.com'
23
+ Excon.ssl_verify_peer = false
24
+
25
+ @connection = Fog::XML::Connection.new(region_url)
26
+ end
27
+
28
+ def auth_header
29
+ auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
30
+ end
31
+
32
+ def request(params, parse_json = true, &block)
33
+ begin
34
+ response = @connection.request(params.merge!({
35
+ :headers => {
36
+ 'Authorization' => auth_header,
37
+ 'X-ID-TENANT-NAME' => @identity_domain,
38
+ 'Content-Type' => 'application/json',
39
+ #'Accept' => 'application/json'
40
+ }.merge!(params[:headers] || {})
41
+ }), &block)
42
+ rescue Excon::Errors::HTTPStatusError => error
43
+ raise case error
44
+ when Excon::Errors::NotFound
45
+ Fog::Oracle::Database::NotFound.slurp(error)
46
+ else
47
+ error
48
+ end
49
+ end
50
+ #https://jaas.oraclecloud.com/paas/service/jcs/api/v1.1/instances/agriculture/status/create/job/2781084
51
+ if !response.body.empty? && parse_json
52
+ # The Oracle Cloud doesn't return the Content-Type header as application/json, rather as application/vnd.com.oracle.oracloud.provisioning.Pod+json
53
+ # Should add check here to validate, but not sure if this might change in future
54
+ response.body = Fog::JSON.decode(response.body)
55
+ end
56
+ response
57
+ end
58
+ end
59
+
60
+ class Mock
61
+ def initialize(options={})
62
+ @username = options[:oracle_username]
63
+ @password = options[:oracle_password]
64
+ @identity_domain = options[:oracle_domain]
65
+
66
+ @connection = Fog::XML::Connection.new("https://dbaas.oraclecloud.com")
67
+ end
68
+
69
+ def self.data
70
+ @data ||= Hash.new do |hash, key|
71
+ hash[key] = {
72
+ :instances => {}
73
+ }
74
+ end
75
+ end
76
+
77
+ def data
78
+ self.class.data[@oracle_username]
79
+ end
80
+
81
+ # Remove, jsut for testing
82
+ def auth_header
83
+ auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
84
+ end
85
+ def request(params, parse_json = true, &block)
86
+ begin
87
+ response = @connection.request(params.merge!({
88
+ :headers => {
89
+ 'Authorization' => auth_header,
90
+ 'X-ID-TENANT-NAME' => @identity_domain,
91
+ 'Content-Type' => 'application/json',
92
+ #'Accept' => 'application/json'
93
+ }.merge!(params[:headers] || {})
94
+ }), &block)
95
+ rescue Excon::Errors::HTTPStatusError => error
96
+ raise case error
97
+ when Excon::Errors::NotFound
98
+ Fog::OracleCloud::Database::NotFound.slurp(error)
99
+ else
100
+ error
101
+ end
102
+ end
103
+ #https://jaas.oraclecloud.com/paas/service/jcs/api/v1.1/instances/agriculture/status/create/job/2781084
104
+ if !response.body.empty? && parse_json
105
+ # The Oracle Cloud doesn't return the Content-Type header as application/json, rather as application/vnd.com.oracle.oracloud.provisioning.Pod+json
106
+ # Should add check here to validate, but not sure if this might change in future
107
+ response.body = Fog::JSON.decode(response.body)
108
+ end
109
+ response
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,114 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Java < Fog::Service
4
+ requires :oracle_username, :oracle_password, :oracle_domain, :oracle_region
5
+
6
+ model_path 'fog/oraclecloud/models/java'
7
+ model :instance
8
+ collection :instances
9
+ model :server
10
+ collection :servers
11
+
12
+ request_path 'fog/oraclecloud/requests/java'
13
+ request :list_instances
14
+ request :create_instance
15
+ request :get_instance
16
+ request :delete_instance
17
+ request :list_servers
18
+
19
+ class Real
20
+
21
+ def initialize(options={})
22
+ @username = options[:oracle_username]
23
+ @password = options[:oracle_password]
24
+ @identity_domain = options[:oracle_domain]
25
+ region_url = options[:oracle_region] == 'emea' ? 'https://jcs.emea.oraclecloud.com' : 'https://jaas.oraclecloud.com'
26
+ Excon.ssl_verify_peer = false
27
+ @connection = Fog::XML::Connection.new(region_url)
28
+ end
29
+
30
+ def auth_header
31
+ auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
32
+ end
33
+
34
+ def request(params, parse_json = true, &block)
35
+ begin
36
+ response = @connection.request(params.merge!({
37
+ :headers => {
38
+ 'Authorization' => auth_header,
39
+ 'X-ID-TENANT-NAME' => @identity_domain,
40
+ 'Content-Type' => 'application/json',
41
+ #'Accept' => 'application/json'
42
+ }.merge!(params[:headers] || {})
43
+ }), &block)
44
+ rescue Excon::Errors::HTTPStatusError => error
45
+ raise case error
46
+ when Excon::Errors::NotFound
47
+ Fog::OracleCloud::Java::NotFound.slurp(error)
48
+ else
49
+ error
50
+ end
51
+ end
52
+ if !response.body.empty? && parse_json
53
+ # The Oracle Cloud doesn't return the Content-Type header as application/json, rather as application/vnd.com.oracle.oracloud.provisioning.Pod+json
54
+ # Should add check here to validate, but not sure if this might change in future
55
+ response.body = Fog::JSON.decode(response.body)
56
+ end
57
+ response
58
+ end
59
+ end
60
+
61
+ class Mock
62
+ def initialize(options={})
63
+ @username = options[:oracle_username]
64
+ @password = options[:oracle_password]
65
+ @identity_domain = options[:oracle_domain]
66
+
67
+ @connection = Fog::XML::Connection.new("https://jaas.oraclecloud.com")
68
+ end
69
+
70
+ def self.data
71
+ @data ||= Hash.new do |hash, key|
72
+ hash[key] = {
73
+ :instances => {}
74
+ }
75
+ end
76
+ end
77
+
78
+ def data
79
+ self.class.data[@oracle_username]
80
+ end
81
+
82
+ # Remove, jsut for testing
83
+ def auth_header
84
+ auth_header ||= 'Basic ' + Base64.encode64("#{@username}:#{@password}").gsub("\n",'')
85
+ end
86
+ def request(params, parse_json = true, &block)
87
+ begin
88
+ response = @connection.request(params.merge!({
89
+ :headers => {
90
+ 'Authorization' => auth_header,
91
+ 'X-ID-TENANT-NAME' => @identity_domain,
92
+ 'Content-Type' => 'application/json',
93
+ #'Accept' => 'application/json'
94
+ }.merge!(params[:headers] || {})
95
+ }), &block)
96
+ rescue Excon::Errors::HTTPStatusError => error
97
+ raise case error
98
+ when Excon::Errors::NotFound
99
+ Fog::Errors::NotFound.new("Instance not found")
100
+ else
101
+ error
102
+ end
103
+ end
104
+ if !response.body.empty? && parse_json
105
+ # The Oracle Cloud doesn't return the Content-Type header as application/json, rather as application/vnd.com.oracle.oracloud.provisioning.Pod+json
106
+ # Should add check here to validate, but not sure if this might change in future
107
+ response.body = Fog::JSON.decode(response.body)
108
+ end
109
+ response
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class Image < Fog::Model
7
+ identity :name
8
+
9
+ attribute :account
10
+ attribute :sizes
11
+ attribute :hypervisor
12
+ attribute :uri
13
+ attribute :quota
14
+ attribute :platform
15
+ attribute :no_upload
16
+ attribute :state
17
+ attribute :signed_by
18
+ attribute :file
19
+ attribute :signature
20
+ attribute :checksums
21
+ attribute :error_reason
22
+ attribute :image_format
23
+ attribute :audited
24
+
25
+ def save
26
+ #identity ? update : create
27
+ create
28
+ end
29
+
30
+ def create
31
+ requires :account, :name, :no_upload, :file, :sizes
32
+
33
+ data = service.create_image(account, name, no_upload, file, sizes)
34
+ end
35
+
36
+ def delete
37
+ requires :image_list_name
38
+ service.delete_image(image_list_name, version)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class ImageList < Fog::Model
7
+ identity :name
8
+
9
+ attribute :uri
10
+ attribute :default
11
+ attribute :description
12
+ attribute :entries
13
+
14
+ # Only used in create
15
+ attribute :default
16
+
17
+ def save
18
+ #identity ? update : create
19
+ create
20
+ end
21
+
22
+ def create
23
+ requires :name, :description
24
+
25
+ data = service.create_image_list(name, description,
26
+ :default => default)
27
+ end
28
+
29
+ def update
30
+ requires :name
31
+
32
+ data = service.update_image_list(name, :description=>description, :default=>default)
33
+ end
34
+
35
+ def delete
36
+ requires :name
37
+ service.delete_image_list(name)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class ImageLists < Fog::Collection
7
+
8
+ model Fog::Compute::OracleCloud::ImageList
9
+
10
+ def all
11
+ data = service.list_image_lists().body['result']
12
+ load(data)
13
+ end
14
+
15
+ def get(name)
16
+ data = service.get_image_list(name).body
17
+ new(data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class Images < Fog::Collection
7
+
8
+ model Fog::Compute::OracleCloud::Image
9
+
10
+ def get(name)
11
+ data = service.get_image(name).body
12
+ new(data)
13
+ end
14
+
15
+ def all
16
+ data = service.list_images().body['result']
17
+ load(data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end