fog-oraclecloud 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/oraclecloud/compute.rb +395 -6
  3. data/lib/fog/oraclecloud/database.rb +6 -0
  4. data/lib/fog/oraclecloud/java.rb +1 -0
  5. data/lib/fog/oraclecloud/models/compute/instance.rb +64 -2
  6. data/lib/fog/oraclecloud/models/compute/ip_association.rb +42 -0
  7. data/lib/fog/oraclecloud/models/compute/ip_associations.rb +22 -0
  8. data/lib/fog/oraclecloud/models/compute/ip_reservation.rb +10 -5
  9. data/lib/fog/oraclecloud/models/compute/security_application.rb +1 -0
  10. data/lib/fog/oraclecloud/models/compute/security_applications.rb +6 -2
  11. data/lib/fog/oraclecloud/models/compute/security_association.rb +31 -0
  12. data/lib/fog/oraclecloud/models/compute/security_associations.rb +20 -0
  13. data/lib/fog/oraclecloud/models/compute/security_ip_list.rb +27 -0
  14. data/lib/fog/oraclecloud/models/compute/security_ip_lists.rb +22 -0
  15. data/lib/fog/oraclecloud/models/compute/security_list.rb +75 -1
  16. data/lib/fog/oraclecloud/models/compute/security_rule.rb +3 -3
  17. data/lib/fog/oraclecloud/models/database/access_rule.rb +52 -0
  18. data/lib/fog/oraclecloud/models/database/access_rules.rb +28 -0
  19. data/lib/fog/oraclecloud/models/database/instance.rb +17 -4
  20. data/lib/fog/oraclecloud/monitoring.rb +1 -1
  21. data/lib/fog/oraclecloud/requests/compute/create_instance.rb +34 -1
  22. data/lib/fog/oraclecloud/requests/compute/create_ip_association.rb +39 -0
  23. data/lib/fog/oraclecloud/requests/compute/create_security_application.rb +18 -0
  24. data/lib/fog/oraclecloud/requests/compute/create_security_association.rb +47 -0
  25. data/lib/fog/oraclecloud/requests/compute/create_security_ip_list.rb +47 -0
  26. data/lib/fog/oraclecloud/requests/compute/create_security_list.rb +49 -0
  27. data/lib/fog/oraclecloud/requests/compute/create_security_rule.rb +22 -0
  28. data/lib/fog/oraclecloud/requests/compute/delete_security_list.rb +29 -0
  29. data/lib/fog/oraclecloud/requests/compute/get_ip_association.rb +36 -0
  30. data/lib/fog/oraclecloud/requests/compute/get_ip_network.rb +1 -1
  31. data/lib/fog/oraclecloud/requests/compute/get_security_application.rb +21 -1
  32. data/lib/fog/oraclecloud/requests/compute/get_security_ip_list.rb +37 -0
  33. data/lib/fog/oraclecloud/requests/compute/get_security_list.rb +37 -0
  34. data/lib/fog/oraclecloud/requests/compute/get_security_rule.rb +17 -0
  35. data/lib/fog/oraclecloud/requests/compute/list_ip_associations.rb +28 -0
  36. data/lib/fog/oraclecloud/requests/compute/list_security_applications.rb +17 -4
  37. data/lib/fog/oraclecloud/requests/compute/list_security_rules.rb +1 -1
  38. data/lib/fog/oraclecloud/requests/compute/update_ip_reservation.rb +2 -0
  39. data/lib/fog/oraclecloud/requests/database/create_access_rule.rb +47 -0
  40. data/lib/fog/oraclecloud/requests/database/get_access_rule.rb +50 -0
  41. data/lib/fog/oraclecloud/soa.rb +1 -1
  42. data/lib/fog/oraclecloud/storage.rb +1 -1
  43. data/lib/fog/oraclecloud/version.rb +1 -1
  44. data/tests/requests/database_tests.rb +15 -8
  45. data/tests/requests/ip_reservation_tests.rb +33 -0
  46. data/tests/requests/security_application_tests.rb +32 -0
  47. metadata +23 -2
@@ -17,6 +17,8 @@ module Fog
17
17
  collection :servers
18
18
  model :patch
19
19
  collection :patches
20
+ model :access_rule
21
+ collection :access_rules
20
22
 
21
23
  request_path 'fog/oraclecloud/requests/database'
22
24
  request :list_instances
@@ -35,6 +37,8 @@ module Fog
35
37
  request :backup_instance
36
38
  request :recover_instance
37
39
  request :list_patches
40
+ request :create_access_rule
41
+ request :get_access_rule
38
42
 
39
43
  class Real
40
44
 
@@ -62,6 +66,7 @@ module Fog
62
66
 
63
67
  def request(params, parse_json = true, &block)
64
68
  begin
69
+ Fog::Logger.debug("Sending #{params[:body].to_s} to #{params[:path]}")
65
70
  response = @connection.request(params.merge!({
66
71
  :headers => {
67
72
  'Authorization' => auth_header,
@@ -109,6 +114,7 @@ module Fog
109
114
  :snapshots => {},
110
115
  :servers => {},
111
116
  :backups => {},
117
+ :access_rules => {},
112
118
  :recoveries => {},
113
119
  :deleted_at => {},
114
120
  :created_at => {},
@@ -54,6 +54,7 @@ module Fog
54
54
 
55
55
  def request(params, parse_json = true, &block)
56
56
  begin
57
+ Fog::Logger.debug("Sending #{params[:body].to_s} to #{params[:path]}")
57
58
  response = @connection.request(params.merge!({
58
59
  :headers => {
59
60
  'Authorization' => auth_header,
@@ -58,9 +58,9 @@ module Fog
58
58
  end
59
59
 
60
60
  def create
61
- requires :name, :shape, :imagelist, :sshkeys
61
+ requires :name, :sshkeys
62
62
 
63
- data = service.create_instance(name, shape, imagelist, label, sshkeys)
63
+ data = service.create_instance(name, shape || 'oc3', imagelist || '/oracle/public/oel_6.4_2GB_v1', label, sshkeys)
64
64
  merge_attributes(data.body['instances'][0])
65
65
  end
66
66
 
@@ -68,6 +68,68 @@ module Fog
68
68
  requires :name
69
69
  service.delete_instance(name)
70
70
  end
71
+
72
+ def get_security_lists
73
+ seclists = []
74
+ networking['eth0']['seclists'].each do |seclist|
75
+ seclists.push(Fog::Compute[:oraclecloud].security_lists.new({
76
+ 'name'=>seclist
77
+ }))
78
+ end
79
+ seclists
80
+ end
81
+
82
+ def create_security_list(seclist_name=nil, description=nil, policy="deny", outbound_policy="permit")
83
+ if !seclist_name then
84
+ seclist_name = "#{name}_SecList"
85
+ end
86
+ data = Fog::Compute[:oraclecloud].security_lists.create(
87
+ :name => seclist_name,
88
+ :description => description,
89
+ :policy => policy,
90
+ :outbound_cidr_policy => outbound_policy
91
+ )
92
+ # Now attach to this instance
93
+ Fog::Compute[:oraclecloud].security_associations.create(
94
+ :name => "#{name}_SecAssoc",
95
+ :seclist => seclist_name,
96
+ :vcable => vcable_id
97
+ )
98
+ data
99
+ end
100
+
101
+ def get_public_ip_address
102
+ if !networking['eth0'] or !networking['eth0']['nat'] or !networking['eth0']['nat'].include? 'ipreservation:' then
103
+ # Instance doesn't have a public ip reservation yet
104
+ return false
105
+ end
106
+ ip_name = networking['eth0']['nat'].sub "ipreservation:", ''
107
+ ip = Fog::Compute[:oraclecloud].ip_reservations.get(ip_name)
108
+ ip.ip
109
+ end
110
+
111
+ def add_public_ip_address
112
+ existing = get_public_ip_address
113
+ if existing then
114
+ raise ArgumentError.new "Can't add public id address to instance that already has one (#{existing.ip})"
115
+ end
116
+ begin
117
+ ip = Fog::Compute[:oraclecloud].ip_reservations.get("#{name}_publicIp")
118
+ rescue Fog::Compute::OracleCloud::NotFound
119
+ # Doesn't exist yet. Create it now
120
+ ip = Fog::Compute[:oraclecloud].ip_reservations.create(
121
+ :name => "#{name}_publicIp"
122
+ )
123
+ end
124
+ # Attach it to this instance
125
+ Fog::Logger.debug "Associating IP Reservation (#{name}_publicIp) with vcable: #{vcable_id}"
126
+ assoc = Fog::Compute[:oraclecloud].ip_associations.create(
127
+ :parentpool => "ipreservation:#{name}_publicIp",
128
+ :vcable => vcable_id
129
+ )
130
+ Fog::Logger.debug "Created IP Association - #{assoc.uri}"
131
+ ip
132
+ end
71
133
  end
72
134
  end
73
135
  end
@@ -0,0 +1,42 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class IpAssociation < Fog::Model
7
+ identity :name
8
+
9
+ attribute :account
10
+ attribute :ip
11
+ attribute :parentpool
12
+ attribute :reservation
13
+ attribute :vcable
14
+ attribute :uri
15
+
16
+ def save
17
+ if name.nil? then
18
+ create
19
+ else
20
+ # TODO: Support?
21
+ #update
22
+ end
23
+ end
24
+
25
+ def create
26
+ requires :parentpool, :vcable
27
+ data = service.create_ip_association({
28
+ :parentpool => parentpool,
29
+ :vcable => vcable
30
+ })
31
+ merge_attributes(data.body)
32
+ end
33
+
34
+ def destroy
35
+ requires :name
36
+ service.delete_ip_association(name)
37
+ end
38
+
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 IpAssociations < Fog::Collection
7
+
8
+ model Fog::Compute::OracleCloud::IpAssociation
9
+
10
+ def all
11
+ data = service.list_ip_associations().body['result']
12
+ load(data)
13
+ end
14
+
15
+ def get(name)
16
+ data = service.get_ip_association(name).body
17
+ new(data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -16,14 +16,18 @@ module Fog
16
16
  attribute :used
17
17
 
18
18
  def save
19
- if !name.nil? && !name.start_with?("/Compute-") then
20
- create
21
- else
22
- update
23
- end
19
+ begin
20
+ # Check if it's already created
21
+ res = Fog::Compute[:oraclecloud].ip_reservations.get(name)
22
+ update
23
+ rescue Fog::Compute::OracleCloud::NotFound
24
+ # It wasn't found.
25
+ create
26
+ end
24
27
  end
25
28
 
26
29
  def create
30
+ requires :name
27
31
  data = service.create_ip_reservation({
28
32
  :name => name,
29
33
  :parentpool => parentpool || '/oracle/public/ippool',
@@ -34,6 +38,7 @@ module Fog
34
38
  end
35
39
 
36
40
  def update
41
+ requires :name, :parentpool
37
42
  data = service.update_ip_reservation({
38
43
  :name => name,
39
44
  :parentpool => parentpool,
@@ -30,6 +30,7 @@ module Fog
30
30
  :icmptype => icmptype,
31
31
  :icmpcode => icmpcode,
32
32
  :description => description)
33
+ merge_attributes(data.body)
33
34
  end
34
35
 
35
36
  def destroy
@@ -1,5 +1,3 @@
1
- require 'fog/core/collection'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class OracleCloud
@@ -9,6 +7,12 @@ module Fog
9
7
 
10
8
  def all
11
9
  data = service.list_security_applications().body['result']
10
+ public_data = service.list_security_applications('public').body['result']
11
+ load(data.concat(public_data))
12
+ end
13
+
14
+ def all_public
15
+ data = service.list_security_applications('public').body['result']
12
16
  load(data)
13
17
  end
14
18
 
@@ -0,0 +1,31 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class SecurityAssociation < Fog::Model
7
+ identity :name
8
+
9
+ attribute :seclist
10
+ attribute :vcable
11
+ attribute :uri
12
+
13
+ def save
14
+ #identity ? update : create
15
+ create
16
+ end
17
+
18
+ def create
19
+ requires :name, :seclist, :vcable
20
+
21
+ data = service.create_security_association(name, seclist, vcable)
22
+ end
23
+
24
+ def destroy
25
+ requires :name
26
+ service.delete_security_association(name)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module Fog
2
+ module Compute
3
+ class OracleCloud
4
+ class SecurityAssociations < Fog::Collection
5
+
6
+ model Fog::Compute::OracleCloud::SecurityAssociation
7
+
8
+ def all
9
+ data = service.list_security_associations().body['result']
10
+ load(data)
11
+ end
12
+
13
+ def get(name)
14
+ data = service.get_security_association(name).body
15
+ new(data)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class SecurityIpList < Fog::Model
7
+ identity :name
8
+
9
+ attribute :description
10
+ attribute :uri
11
+ attribute :secipentries
12
+
13
+ def save
14
+ #identity ? update : create
15
+ create
16
+ end
17
+
18
+ def create
19
+ requires :name, :secipentries
20
+
21
+ data = service.create_security_ip_list(name, description, secipentries)
22
+ merge_attributes(data.body)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OracleCloud
6
+ class SecurityIpLists < Fog::Collection
7
+
8
+ model Fog::Compute::OracleCloud::SecurityIpList
9
+
10
+ def all
11
+ data = service.list_security_ip_lists().body['result']
12
+ load(data)
13
+ end
14
+
15
+ def get(name)
16
+ data = service.get_security_ip_list(name).body
17
+ new(data)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,7 +7,7 @@ module Fog
7
7
  identity :name
8
8
 
9
9
  attribute :account
10
- attribute :name
10
+ attribute :description
11
11
  attribute :uri
12
12
  attribute :outbound_cidr_policy
13
13
  attribute :proxyuri
@@ -20,6 +20,80 @@ module Fog
20
20
  #identity ? update : create
21
21
  create
22
22
  end
23
+
24
+ def create
25
+ requires :name
26
+
27
+ data = service.create_security_list(name, description, policy, outbound_cidr_policy)
28
+ merge_attributes(data.body)
29
+
30
+ end
31
+
32
+ def destroy
33
+ requires :name
34
+ service.delete_security_list(name)
35
+ end
36
+
37
+ def add_rule (port, list, rule_name=nil)
38
+ if !rule_name then rule_name = "#{name}_#{port}_#{list}" end
39
+ if port.is_a? Numeric then
40
+ # See if it's a public port
41
+ secapps = Fog::Compute[:oraclecloud].security_applications.all_public
42
+ public_app = secapps.detect { |app|
43
+ Float(app.dport || 0) == port }
44
+ if public_app then
45
+ secapp = public_app.name
46
+ else
47
+ begin
48
+ custom_app = Fog::Compute[:oraclecloud].security_applications.get("#{name}_#{port}")
49
+ rescue Fog::Compute::OracleCloud::NotFound
50
+
51
+ # Create custom security application
52
+ custom_app = Fog::Compute[:oraclecloud].security_applications.create(
53
+ :name => "#{name}_#{port}",
54
+ :protocol => 'tcp',
55
+ :dport => port
56
+ )
57
+ end
58
+ secapp = custom_app.name
59
+ end
60
+ else
61
+ # They want to use a named security application
62
+ # TODO: Add support for user created security apps
63
+ secapp = '/oracle/public/' + port
64
+ end
65
+ block = /\d{,2}|1\d{2}|2[0-4]\d|25[0-5]/
66
+ re = /\A#{block}\.#{block}\.#{block}\.#{block}\z/
67
+
68
+ if re =~ list then
69
+ # They sent an ip address. Create new security ip list
70
+ # Check if it exists already (assume this has been run before)
71
+ begin
72
+ seclist = Fog::Compute[:oraclecloud].security_ip_lists.get("#{name}_#{list}")
73
+ rescue Fog::Compute::OracleCloud::NotFound
74
+ Fog::Logger.debug "Creating Security IP List for #{list}"
75
+ seclist = Fog::Compute[:oraclecloud].security_ip_lists.create(
76
+ :name => "#{name}_#{list}",
77
+ :secipentries => [list]
78
+ )
79
+ end
80
+ list_name = "seciplist:#{name}_#{list}"
81
+ else
82
+ list_name = list
83
+ end
84
+ begin
85
+ rule = Fog::Compute[:oraclecloud].security_rules.get(rule_name)
86
+ rescue Fog::Compute::OracleCloud::NotFound
87
+ Fog::Logger.debug "Creating Security Rule for #{list_name} to #{name} (app:#{port})"
88
+ rule = Fog::Compute[:oraclecloud].security_rules.create(
89
+ :application => secapp,
90
+ :name => rule_name,
91
+ :src_list => list_name,
92
+ :dst_list => "seclist:#{name}"
93
+ )
94
+ end
95
+ rule
96
+ end
23
97
  end
24
98
  end
25
99
  end