mystro-common 0.1.11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/.gitignore +3 -0
  2. data/.rspec +2 -0
  3. data/CHANGELOG.md +42 -4
  4. data/Gemfile +7 -1
  5. data/Rakefile +137 -1
  6. data/lib/{mystro/ext/fog → fog/ext}/balancer.rb +0 -0
  7. data/lib/fog/ext/dynect/dns.rb +140 -0
  8. data/lib/fog/ext/dynect/models/dns/record.rb +66 -0
  9. data/lib/fog/ext/dynect/models/dns/records.rb +87 -0
  10. data/lib/fog/ext/dynect/models/dns/zone.rb +60 -0
  11. data/lib/fog/ext/dynect/models/dns/zones.rb +29 -0
  12. data/lib/fog/ext/dynect/requests/dns/delete_record.rb +56 -0
  13. data/lib/fog/ext/dynect/requests/dns/delete_zone.rb +42 -0
  14. data/lib/fog/ext/dynect/requests/dns/get_all_records.rb +56 -0
  15. data/lib/fog/ext/dynect/requests/dns/get_node_list.rb +56 -0
  16. data/lib/fog/ext/dynect/requests/dns/get_record.rb +85 -0
  17. data/lib/fog/ext/dynect/requests/dns/get_zone.rb +58 -0
  18. data/lib/fog/ext/dynect/requests/dns/post_record.rb +72 -0
  19. data/lib/fog/ext/dynect/requests/dns/post_session.rb +44 -0
  20. data/lib/fog/ext/dynect/requests/dns/post_zone.rb +71 -0
  21. data/lib/fog/ext/dynect/requests/dns/put_zone.rb +76 -0
  22. data/lib/fog/ext/dynect.rb +26 -0
  23. data/lib/mystro/cloud/action.rb +22 -0
  24. data/lib/mystro/cloud/connect/aws/balancer.rb +55 -0
  25. data/lib/mystro/cloud/connect/aws/compute.rb +151 -0
  26. data/lib/mystro/cloud/connect/aws/listener.rb +36 -0
  27. data/lib/mystro/cloud/connect/aws/record.rb +58 -0
  28. data/lib/mystro/cloud/connect/aws/zone.rb +35 -0
  29. data/lib/mystro/cloud/connect/aws.rb +14 -0
  30. data/lib/mystro/cloud/connect/dynect/record.rb +72 -0
  31. data/lib/mystro/cloud/connect/dynect/zone.rb +35 -0
  32. data/lib/mystro/cloud/connect/dynect.rb +17 -0
  33. data/lib/mystro/cloud/connect/fog.rb +66 -0
  34. data/lib/mystro/cloud/connect.rb +64 -0
  35. data/lib/mystro/cloud/model/balancer.rb +15 -0
  36. data/lib/mystro/cloud/model/compute.rb +27 -0
  37. data/lib/mystro/cloud/model/listener.rb +30 -0
  38. data/lib/mystro/cloud/model/record.rb +20 -0
  39. data/lib/mystro/cloud/model/volume.rb +12 -0
  40. data/lib/mystro/cloud/model/zone.rb +9 -0
  41. data/lib/mystro/cloud/model.rb +183 -0
  42. data/lib/mystro/cloud.rb +32 -0
  43. data/lib/mystro/common/version.rb +4 -3
  44. data/lib/mystro/dsl/balancer.rb +18 -0
  45. data/lib/mystro/dsl/compute.rb +57 -0
  46. data/lib/mystro/dsl/health.rb +7 -0
  47. data/lib/mystro/dsl/listener.rb +5 -0
  48. data/lib/mystro/dsl/oldtemplate.rb +281 -0
  49. data/lib/mystro/dsl/template.rb +12 -278
  50. data/lib/mystro/dsl/template_file.rb +18 -0
  51. data/lib/mystro/dsl/volume.rb +8 -0
  52. data/lib/mystro/dsl.rb +40 -0
  53. data/lib/mystro/organization.rb +83 -0
  54. data/lib/mystro/plugin.rb +4 -3
  55. data/lib/mystro/provider.rb +40 -0
  56. data/lib/mystro/userdata.rb +1 -1
  57. data/lib/mystro-common.rb +32 -31
  58. data/mystro-common.gemspec +2 -1
  59. data/spec/cloud/aws/balancer_spec.rb +10 -0
  60. data/spec/cloud/aws/compute_spec.rb +10 -0
  61. data/spec/cloud/aws/record_spec.rb +10 -0
  62. data/spec/cloud/dynect/record_spec.rb +10 -0
  63. data/spec/model/compute_spec.rb +36 -0
  64. data/spec/model/model_spec.rb +89 -0
  65. data/spec/model/record_spec.rb +27 -0
  66. data/spec/spec_helper.rb +36 -0
  67. data/spec/support/balancer.rb +49 -0
  68. data/spec/support/compute.rb +65 -0
  69. data/spec/support/record.rb +45 -0
  70. data/test/config.yml +71 -0
  71. metadata +99 -14
  72. data/lib/mystro/account.rb +0 -105
  73. data/lib/mystro/connect/balancer.rb +0 -91
  74. data/lib/mystro/connect/compute.rb +0 -100
  75. data/lib/mystro/connect/dns.rb +0 -51
  76. data/lib/mystro/connect/environment.rb +0 -31
  77. data/lib/mystro/connect.rb +0 -124
  78. data/lib/mystro/job.rb +0 -0
  79. data/lib/mystro/model.rb +0 -71
@@ -0,0 +1,42 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Delete a zone
7
+ #
8
+ # ==== Parameters
9
+ # * zone<~String> - zone to host
10
+
11
+ def delete_zone(zone)
12
+ request(
13
+ :expects => 200,
14
+ :method => :delete,
15
+ :path => "Zone/#{zone}"
16
+ )
17
+ end
18
+ end
19
+
20
+ class Mock
21
+ def delete_zone(zone)
22
+ self.data[:zones].delete(zone)
23
+
24
+ response = Excon::Response.new
25
+ response.status = 200
26
+ response.body = {
27
+ "status" => "success",
28
+ "data" => {},
29
+ "job_id" => Fog::Dynect::Mock.job_id,
30
+ "msgs" => [{
31
+ "ERR_CD" => '',
32
+ "INFO" => '',
33
+ "LVL" => '',
34
+ "SOURCE" => ''
35
+ }]
36
+ }
37
+ response
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Get one or more node lists
7
+ #
8
+ # ==== Parameters
9
+ # * zone<~String> - zone to lookup node lists for
10
+ # * options<~Hash>
11
+ # * fqdn<~String> - fully qualified domain name of node to lookup
12
+
13
+ def get_all_records(zone, options = {})
14
+ requested_fqdn = options['fqdn'] || options[:fqdn]
15
+ request(
16
+ :expects => 200,
17
+ :idempotent => true,
18
+ :method => :get,
19
+ :path => ['AllRecord', zone, requested_fqdn].compact.join('/')
20
+ )
21
+ end
22
+ end
23
+
24
+ class Mock
25
+ def get_all_records(zone, options = {})
26
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
27
+
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+
31
+ data = [zone[:zone]]
32
+
33
+ if fqdn = options[:fqdn]
34
+ data = data | zone[:records].collect { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact
35
+ else
36
+ data = data | zone[:records].collect { |type, records| records.collect { |record| record[:fqdn] } }.flatten
37
+ end
38
+
39
+ response.body = {
40
+ "status" => "success",
41
+ "data" => data,
42
+ "job_id" => Fog::Dynect::Mock.job_id,
43
+ "msgs" => [{
44
+ "INFO" => "get_tree: Here is your zone tree",
45
+ "SOURCE" => "BLL",
46
+ "ERR_CD" => nil,
47
+ "LVL" => "INFO"
48
+ }]
49
+ }
50
+
51
+ response
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Get one or more node lists
7
+ #
8
+ # ==== Parameters
9
+ # * zone<~String> - zone to lookup node lists for
10
+ # * options<~Hash>
11
+ # * fqdn<~String> - fully qualified domain name of node to lookup
12
+
13
+ def get_node_list(zone, options = {})
14
+ requested_fqdn = options['fqdn'] || options[:fqdn]
15
+ request(
16
+ :expects => 200,
17
+ :idempotent => true,
18
+ :method => :get,
19
+ :path => ['AllRecord', zone, requested_fqdn].compact.join('/')
20
+ )
21
+ end
22
+ end
23
+
24
+ class Mock
25
+ def get_node_list(zone, options = {})
26
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
27
+
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+
31
+ data = [zone[:zone]]
32
+
33
+ if fqdn = options[:fqdn]
34
+ data = data | zone[:records].collect { |type, records| records.select { |record| record[:fqdn] == fqdn } }.flatten.compact
35
+ else
36
+ data = data | zone[:records].collect { |type, records| records.collect { |record| record[:fqdn] } }.flatten
37
+ end
38
+
39
+ response.body = {
40
+ "status" => "success",
41
+ "data" => data,
42
+ "job_id" => Fog::Dynect::Mock.job_id,
43
+ "msgs" => [{
44
+ "INFO" => "get_tree: Here is your zone tree",
45
+ "SOURCE" => "BLL",
46
+ "ERR_CD" => nil,
47
+ "LVL" => "INFO"
48
+ }]
49
+ }
50
+
51
+ response
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # List records of a given type
7
+ #
8
+ # ==== Parameters
9
+ # * type<~String> - type of record in ['AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT']
10
+ # * zone<~String> - name of zone to lookup
11
+ # * fqdn<~String> - name of fqdn to lookup
12
+ # * options<~Hash>:
13
+ # * record_id<~String> - id of record
14
+
15
+ def get_record(type, zone, fqdn, options = {})
16
+ path = ["#{type.to_s.upcase}Record", zone, fqdn, options['record_id']].compact.join('/')
17
+ request(
18
+ :expects => 200,
19
+ :idempotent => true,
20
+ :method => :get,
21
+ :path => path
22
+ )
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def get_record(type, zone, fqdn, options = {})
28
+ raise ArgumentError unless [
29
+ 'AAAA', 'ANY', 'A', 'CNAME',
30
+ 'DHCID', 'DNAME', 'DNSKEY',
31
+ 'DS', 'KEY', 'LOC', 'MX',
32
+ 'NSA', 'NS', 'PTR', 'PX',
33
+ 'RP', 'SOA', 'SPF', 'SRV',
34
+ 'SSHFP', 'TXT'
35
+ ].include? type
36
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
37
+
38
+ response = Excon::Response.new
39
+ response.status = 200
40
+
41
+ if record_id = options['record_id']
42
+ raise Fog::DNS::Dynect::NotFound unless record = zone[:records][type].find { |record| record[:record_id] == record_id.to_i }
43
+ response.body = {
44
+ "status" => "success",
45
+ "data" => {
46
+ "zone" => record[:zone][:zone],
47
+ "ttl" => record[:ttl],
48
+ "fqdn" => record[:fqdn],
49
+ "record_type" => type,
50
+ "rdata" => record[:rdata],
51
+ "record_id" => record[:record_id]
52
+ },
53
+ "job_id" => Fog::Dynect::Mock.job_id,
54
+ "msgs" => [{
55
+ "INFO" => "get: Found the record",
56
+ "SOURCE" => "API-B",
57
+ "ERR_CD" => nil,
58
+ "LVL" => "INFO"
59
+ }]
60
+ }
61
+ else
62
+ records = if type == "ANY"
63
+ zone[:records].values.flatten.select { |record| record[:fqdn] == fqdn }
64
+ else
65
+ zone[:records][type].select { |record| record[:fqdn] == fqdn }
66
+ end
67
+ response.body = {
68
+ "status" => "success",
69
+ "data" => records.collect { |record| "/REST/#{record[:type]}Record/#{record[:zone][:zone]}/#{record[:fqdn]}/#{record[:record_id]}" },
70
+ "job_id" => Fog::Dynect::Mock.job_id,
71
+ "msgs" => [{
72
+ "INFO" => "detail: Found #{records.size} record",
73
+ "SOURCE" => "BLL",
74
+ "ERR_CD" => nil,
75
+ "LVL" => "INFO"
76
+ }]
77
+ }
78
+ end
79
+
80
+ response
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,58 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Get one or more zones
7
+ #
8
+ # ==== Parameters
9
+ # * options<~Hash>:
10
+ # * zone<~String> - name of zone to lookup, or omit to return list of zones
11
+
12
+ def get_zone(options = {})
13
+ request(
14
+ :expects => 200,
15
+ :idempotent => true,
16
+ :method => :get,
17
+ :path => ['Zone', options['zone']].compact.join('/')
18
+ )
19
+ end
20
+ end
21
+
22
+ class Mock
23
+ def get_zone(options = {})
24
+ if options['zone']
25
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][options['zone']]
26
+ data = {
27
+ "zone_type" => zone[:zone_type],
28
+ "serial_style" => zone[:serial_style],
29
+ "serial" => zone[:serial],
30
+ "zone" => zone[:zone]
31
+ }
32
+ info = "get: Your zone, #{zone[:zone]}"
33
+ else
34
+ data = self.data[:zones].collect { |zone, data| "/REST/Zone/#{zone}/" }
35
+ info = "get: Your #{data.size} zones"
36
+ end
37
+
38
+ response = Excon::Response.new
39
+ response.status = 200
40
+
41
+ response.body = {
42
+ "status" => "success",
43
+ "data" => data,
44
+ "job_id" => Fog::Dynect::Mock.job_id,
45
+ "msgs" => [{
46
+ "INFO" => info,
47
+ "SOURCE" => "BLL",
48
+ "ERR_CD" => nil,
49
+ "LVL" => "INFO"
50
+ }]
51
+ }
52
+
53
+ response
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,72 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Create a record
7
+ #
8
+ # ==== Parameters
9
+ # * type<~String> - type of record in ['AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT']
10
+ # * zone<~String> - zone of record
11
+ # * rdata<~Hash> - rdata for record
12
+ # * options<~Hash>: (options vary by type, listing below includes common parameters)
13
+ # * ttl<~Integer> - ttl for the record, defaults to zone ttl
14
+
15
+ def post_record(type, zone, fqdn, rdata, options = {})
16
+ options.merge!('rdata' => rdata)
17
+ request(
18
+ :body => Fog::JSON.encode(options),
19
+ :expects => 200,
20
+ :method => :post,
21
+ :path => ["#{type.to_s.upcase}Record", zone, fqdn].join('/')
22
+ )
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def post_record(type, zone, fqdn, rdata, options = {})
28
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
29
+
30
+ records = zone[:records]
31
+ record_id = zone[:next_record_id]
32
+ zone[:next_record_id] += 1
33
+
34
+ record = {
35
+ :type => type,
36
+ :zone => zone,
37
+ :fqdn => fqdn,
38
+ :rdata => rdata,
39
+ :ttl => options[:ttl] || zone[:ttl],
40
+ :record_id => record_id
41
+ }
42
+
43
+ records[type] << record
44
+
45
+ response = Excon::Response.new
46
+ response.status = 200
47
+
48
+ response.body = {
49
+ "status" => "success",
50
+ "data" => {
51
+ "zone" => record[:zone][:zone],
52
+ "ttl" => record[:ttl],
53
+ "fqdn" => record[:fqdn],
54
+ "record_type" => record[:type],
55
+ "rdata" => record[:rdata],
56
+ "record_id" => record[:record_id]
57
+ },
58
+ "job_id" => Fog::Dynect::Mock.job_id,
59
+ "msgs" => [{
60
+ "INFO"=>"add: Record added",
61
+ "SOURCE"=>"BLL",
62
+ "ERR_CD"=>nil,
63
+ "LVL"=>"INFO"
64
+ }]
65
+ }
66
+
67
+ response
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ def post_session
7
+ request(
8
+ :expects => 200,
9
+ :idempotent => true,
10
+ :method => :post,
11
+ :path => "Session",
12
+ :body => Fog::JSON.encode({
13
+ :customer_name => @dynect_customer,
14
+ :user_name => @dynect_username,
15
+ :password => @dynect_password
16
+ })
17
+ )
18
+ end
19
+ end
20
+
21
+ class Mock
22
+ def post_session
23
+ response = Excon::Response.new
24
+ response.status = 200
25
+ response.body = {
26
+ "status" => "success",
27
+ "data" => {
28
+ "token" => auth_token,
29
+ "version" => Fog::Dynect::Mock.version
30
+ },
31
+ "job_id" => Fog::Dynect::Mock.job_id,
32
+ "msgs"=>[{
33
+ "INFO"=>"login: Login successful",
34
+ "SOURCE"=>"BLL",
35
+ "ERR_CD"=>nil,
36
+ "LVL"=>"INFO"
37
+ }]
38
+ }
39
+ response
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,71 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Create a zone
7
+ #
8
+ # ==== Parameters
9
+ # * rname<~String> - administrative contact
10
+ # * ttl<~Integer> - time to live (in seconds) for records in this zone
11
+ # * zone<~String> - name of zone to host
12
+ # * options<~Hash>:
13
+ # * serial_style<~String> - style of serial number, in ['day', 'epoch', 'increment', 'minute']. Defaults to increment
14
+
15
+ def post_zone(rname, ttl, zone, options = {})
16
+ body = Fog::JSON.encode({
17
+ :rname => rname,
18
+ :token => auth_token,
19
+ :ttl => ttl
20
+ }.merge!(options))
21
+
22
+ request(
23
+ :body => body,
24
+ :expects => 200,
25
+ :method => :post,
26
+ :path => 'Zone/' << zone
27
+ )
28
+ end
29
+ end
30
+
31
+ class Mock
32
+ def post_zone(rname, ttl, zone, options = {})
33
+ new_zone = self.data[:zones][zone] = {
34
+ :next_record_id => 0,
35
+ :records => Hash.new do |records_hash, type|
36
+ records_hash[type] = []
37
+ end,
38
+ :records_to_delete => [],
39
+ :rname => rname,
40
+ :serial_style => options[:serial_style] || "increment",
41
+ :serial => 0,
42
+ :ttl => ttl,
43
+ :zone => zone,
44
+ :zone_type => "Primary"
45
+ }
46
+
47
+ response = Excon::Response.new
48
+ response.status = 200
49
+ response.body = {
50
+ "status" => "success",
51
+ "data" => {
52
+ "zone_type" => new_zone[:zone_type],
53
+ "serial_style" => new_zone[:serial_style],
54
+ "serial" => new_zone[:serial],
55
+ "zone" => zone
56
+ },
57
+ "job_id" => Fog::Dynect::Mock.job_id,
58
+ "msgs" => [{
59
+ "INFO" => "create: New zone #{zone} created. Publish it to put it on our server.",
60
+ "SOURCE" => "BLL",
61
+ "ERR_CD" => nil,
62
+ "LVL" => "INFO"
63
+ }]
64
+ }
65
+
66
+ response
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,76 @@
1
+ module Fog
2
+ module DNS
3
+ class Dynect
4
+ class Real
5
+
6
+ # Update a zone
7
+ #
8
+ # ==== Parameters
9
+ # * zone<~String> - name or id of zone
10
+ # * options<~Hash>:
11
+ # * freeze<~Boolean> - causes zone to become frozen
12
+ # * publish<~Boolean> - causes all pending changes to be pushed to nameservers
13
+ # * thaw<~Boolean> - causes zone to cease being frozen
14
+
15
+ def put_zone(zone, options = {})
16
+ request(
17
+ :body => Fog::JSON.encode(options),
18
+ :expects => 200,
19
+ :method => :put,
20
+ :path => 'Zone/' << zone
21
+ )
22
+ end
23
+ end
24
+
25
+ class Mock
26
+ def put_zone(zone, options = {})
27
+ raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
28
+
29
+ raise ArgumentError unless options.size == 1
30
+
31
+ response = Excon::Response.new
32
+ response.status = 200
33
+
34
+ data = {}
35
+
36
+ if options['freeze']
37
+ zone['frozen'] = true
38
+ info = "freeze: Your zone is now frozen"
39
+ elsif options['publish']
40
+ zone[:changes] = {}
41
+ zone[:records_to_delete].each do |record|
42
+ zone[:records][record[:type]].delete_if { |r| r[:fqdn] == record[:fqdn] && r[:record_id] == record[:record_id] }
43
+ end
44
+ zone[:records_to_delete] = []
45
+ data = {
46
+ "zone_type" => zone[:zone_type],
47
+ "serial_style" => zone[:serial_style],
48
+ "serial" => zone[:serial] += 1,
49
+ "zone" => zone[:zone]
50
+ }
51
+ info = "publish: #{zone[:zone]} published"
52
+ elsif options['thaw']
53
+ zone[:frozen] = false
54
+ info = "thaw: Your zone is now thawed, you may edit normally"
55
+ else
56
+ raise ArgumentError
57
+ end
58
+
59
+ response.body = {
60
+ "status" => "success",
61
+ "data" => data,
62
+ "job_id" => Fog::Dynect::Mock.job_id,
63
+ "msgs" => [{
64
+ "INFO" => info,
65
+ "SOURCE"=>"BLL",
66
+ "ERR_CD"=>nil,
67
+ "LVL"=>"INFO"
68
+ }]
69
+ }
70
+
71
+ response
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,26 @@
1
+ require 'nokogiri'
2
+
3
+ require 'fog/core'
4
+ require 'fog/core/parser'
5
+
6
+ module Fog
7
+ module Dynect
8
+ extend Fog::Provider
9
+
10
+ service(:dns, 'ext/dynect/dns', 'DNS')
11
+
12
+ class Mock
13
+ def self.job_id
14
+ Fog::Mock.random_numbers(8).to_i
15
+ end
16
+
17
+ def self.token
18
+ Fog::Mock.random_hex(48)
19
+ end
20
+
21
+ def self.version
22
+ [Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1)].join('.')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ module Mystro
2
+ module Cloud
3
+ class Action
4
+ attr_reader :action
5
+ attr_accessor :options, :class, :data
6
+ def initialize(klass, action)
7
+ @class = klass
8
+ @action = action
9
+ @options = {}
10
+ @data = {}
11
+ end
12
+
13
+ def model
14
+ @class.split('::').last
15
+ end
16
+
17
+ def to_model
18
+ @class.constantize.new(@data)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,55 @@
1
+ module Mystro
2
+ module Cloud
3
+ module Aws
4
+ class Balancer < Connect
5
+ manages 'Fog::Balancer', :load_balancers
6
+
7
+ def create(model)
8
+ list = model.computes
9
+ enc = encode(model)
10
+ bal = service.send(collection).create(enc)
11
+ bal.register_instances(list)
12
+ bal.save
13
+ decode(bal)
14
+ end
15
+
16
+ protected
17
+
18
+ def _decode(balancer)
19
+ model = Mystro::Cloud::Balancer.new
20
+ model.id = balancer.id
21
+ model.dns = balancer.dns_name
22
+ model.computes = balancer.instances
23
+ model.zones = balancer.availability_zones
24
+ model.health = balancer.health_check
25
+
26
+ decoded = []
27
+ balancer.listeners.each do |l|
28
+ decoded << listeners.decode(l)
29
+ end
30
+ model.listeners = decoded
31
+
32
+ model._raw = balancer
33
+ model
34
+ end
35
+
36
+ def _encode(model)
37
+ Mystro::Log.debug "encode < #{model.inspect}"
38
+ o = {
39
+ id: model.id,
40
+ 'ListenerDescriptions' => model.listeners.map {|l| listeners.encode(l)},
41
+ 'AvailabilityZones' => model.zones
42
+ }
43
+ Mystro::Log.debug "encode > #{o.inspect}"
44
+ o
45
+ end
46
+
47
+ private
48
+
49
+ def listeners
50
+ @listeners ||= Mystro::Cloud::Aws::Listener.new(options)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end