fog-linode 0.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +12 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +17 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/CONTRIBUTORS.md +1 -0
  9. data/Gemfile +6 -0
  10. data/Gemfile.lock +79 -0
  11. data/LICENSE.md +20 -0
  12. data/README.md +74 -0
  13. data/Rakefile +13 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/fog-linode.gemspec +34 -0
  17. data/lib/fog/linode.rb +17 -0
  18. data/lib/fog/linode/compute.rb +50 -0
  19. data/lib/fog/linode/compute/models/image.rb +23 -0
  20. data/lib/fog/linode/compute/models/images.rb +23 -0
  21. data/lib/fog/linode/compute/models/kernel.rb +19 -0
  22. data/lib/fog/linode/compute/models/kernels.rb +23 -0
  23. data/lib/fog/linode/compute/models/region.rb +14 -0
  24. data/lib/fog/linode/compute/models/regions.rb +23 -0
  25. data/lib/fog/linode/compute/models/server.rb +56 -0
  26. data/lib/fog/linode/compute/models/servers.rb +23 -0
  27. data/lib/fog/linode/compute/models/stack_script.rb +26 -0
  28. data/lib/fog/linode/compute/models/stack_scripts.rb +23 -0
  29. data/lib/fog/linode/compute/models/type.rb +32 -0
  30. data/lib/fog/linode/compute/models/types.rb +23 -0
  31. data/lib/fog/linode/compute/requests/create_server.rb +22 -0
  32. data/lib/fog/linode/compute/requests/delete_server.rb +17 -0
  33. data/lib/fog/linode/compute/requests/list_images.rb +16 -0
  34. data/lib/fog/linode/compute/requests/list_kernels.rb +16 -0
  35. data/lib/fog/linode/compute/requests/list_regions.rb +18 -0
  36. data/lib/fog/linode/compute/requests/list_servers.rb +16 -0
  37. data/lib/fog/linode/compute/requests/list_stack_scripts.rb +16 -0
  38. data/lib/fog/linode/compute/requests/list_types.rb +19 -0
  39. data/lib/fog/linode/compute/requests/update_server.rb +21 -0
  40. data/lib/fog/linode/compute/requests/view_image.rb +17 -0
  41. data/lib/fog/linode/compute/requests/view_kernel.rb +17 -0
  42. data/lib/fog/linode/compute/requests/view_region.rb +18 -0
  43. data/lib/fog/linode/compute/requests/view_server.rb +17 -0
  44. data/lib/fog/linode/compute/requests/view_stack_script.rb +17 -0
  45. data/lib/fog/linode/compute/requests/view_type.rb +18 -0
  46. data/lib/fog/linode/dns.rb +37 -0
  47. data/lib/fog/linode/dns/models/domain.rb +46 -0
  48. data/lib/fog/linode/dns/models/domain_record.rb +38 -0
  49. data/lib/fog/linode/dns/models/domain_records.rb +30 -0
  50. data/lib/fog/linode/dns/models/domains.rb +23 -0
  51. data/lib/fog/linode/dns/requests/create_domain.rb +22 -0
  52. data/lib/fog/linode/dns/requests/create_domain_record.rb +22 -0
  53. data/lib/fog/linode/dns/requests/delete_domain.rb +17 -0
  54. data/lib/fog/linode/dns/requests/delete_domain_record.rb +17 -0
  55. data/lib/fog/linode/dns/requests/list_domain_records.rb +19 -0
  56. data/lib/fog/linode/dns/requests/list_domains.rb +19 -0
  57. data/lib/fog/linode/dns/requests/update_domain.rb +21 -0
  58. data/lib/fog/linode/dns/requests/update_domain_record.rb +22 -0
  59. data/lib/fog/linode/dns/requests/view_domain.rb +18 -0
  60. data/lib/fog/linode/dns/requests/view_domain_record.rb +17 -0
  61. data/lib/fog/linode/paginated_collection.rb +44 -0
  62. data/lib/fog/linode/service.rb +37 -0
  63. data/lib/fog/linode/version.rb +5 -0
  64. metadata +247 -0
@@ -0,0 +1,16 @@
1
+ require 'fog/linode/paginated_collection'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ # This class provides the actual implementation for service calls
7
+ class Real
8
+ include PaginatedCollection
9
+
10
+ def list_stack_scripts(options = {})
11
+ make_paginated_request('linode/stackscripts', options)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def list_types(options = {})
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: 'linode/types',
11
+ query: options
12
+ )
13
+
14
+ response.body['data']
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def update_server(id, options = {})
7
+ response = request(
8
+ expects: [200],
9
+ method: 'PUT',
10
+ path: "linode/instances/#{id}",
11
+ body: Fog::JSON.encode(options),
12
+ headers: {
13
+ 'Content-Type' => 'application/json'
14
+ }
15
+ )
16
+ response.body
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_image(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "images/#{id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_kernel(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "linode/kernels/#{id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_region(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "regions/#{id}"
11
+ )
12
+
13
+ response.body
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_server(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "linode/instances/#{id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_stack_script(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "linode/stackscripts/#{id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Linode
3
+ class Compute
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def view_type(id, options = {})
7
+ response = request(
8
+ expects: [200],
9
+ method: 'GET',
10
+ path: "linode/types/#{id}",
11
+ query: options
12
+ )
13
+ response.body
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module Linode
3
+ # Fog service class for Linode DNS service
4
+ class DNS < Fog::Service
5
+ requires :linode_token
6
+
7
+ request_path 'fog/linode/dns/requests'
8
+ request :create_domain
9
+ request :list_domains
10
+ request :view_domain
11
+ request :update_domain
12
+ request :delete_domain
13
+ request :create_domain_record
14
+ request :list_domain_records
15
+ request :view_domain_record
16
+ request :update_domain_record
17
+ request :delete_domain_record
18
+
19
+ model_path 'fog/linode/dns/models'
20
+ collection :domains
21
+ model :domain
22
+ collection :domain_records
23
+ model :domain_record
24
+
25
+ # Real implementation for Linode DNS service
26
+ class Real < Service
27
+ end
28
+
29
+ # Mock service for unit tests
30
+ # NOTE: we do not currently use this, but Fog throws an
31
+ # error if it's not defined for a Service class
32
+ class Mock
33
+ def initialize(_options = {}); end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class DNS
6
+ # Read-only model for Linode instance types
7
+ class Domain < Fog::Model
8
+ identity :id
9
+
10
+ attribute :type
11
+ attribute :domain
12
+ attribute :group
13
+ attribute :description
14
+ attribute :status
15
+ attribute :soa_email
16
+ attribute :retry_sec
17
+ attribute :master_ips
18
+ attribute :axfr_ips
19
+ attribute :expire_sec
20
+ attribute :refresh_sec
21
+ attribute :ttl_sec
22
+ attribute :tags
23
+
24
+ def save
25
+ options = clean_attributes
26
+ if identity.nil?
27
+ merge_attributes(service.create_domain(options))
28
+ else
29
+ merge_attributes(service.update_domain(identity, options))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # The API returns "" for group, but does not accept that
36
+ # value, so we have to remove it to avoid errors on update
37
+ def clean_attributes
38
+ return attributes if group.nil? || !group.empty?
39
+
40
+ filtered_attributes = attributes.dup
41
+ filtered_attributes.delete(:group)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class DNS
6
+ # Model for Linode domain records
7
+ class DomainRecord < Fog::Model
8
+ identity :id
9
+
10
+ attribute :domain_id
11
+ attribute :type
12
+ attribute :name
13
+ attribute :target
14
+ attribute :priority
15
+ attribute :weight
16
+ attribute :port
17
+ attribute :service
18
+ attribute :protocol
19
+ attribute :ttl_sec
20
+ attribute :tag
21
+
22
+ # The `service` attribute of a Domain Record conflicts with the `service`
23
+ # attribute of `Fog::Model`. As a result, the `service` attribute for
24
+ # this model class _does not represent_ the Linode API. To work around
25
+ # this, all API interactions for this model have to go through
26
+ # `collection.service` instead of `service`.
27
+ def save
28
+ service = collection.service
29
+ if identity.nil?
30
+ merge_attributes(service.create_domain_record(domain_id, attributes))
31
+ else
32
+ merge_attributes(service.update_domain_record(domain_id, identity, attributes))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/linode/compute/models/type'
3
+
4
+ module Fog
5
+ module Linode
6
+ class DNS
7
+ # Collection class for loading Type models from Linode instance type data
8
+ class DomainRecords < Fog::Collection
9
+ model DomainRecord
10
+
11
+ def all(domain_id, options = {})
12
+ domain_records = service.list_domain_records(domain_id, options)
13
+ load(domain_records.map { |domain_record| add_domain_id(domain_id, domain_record) })
14
+ end
15
+
16
+ def get(domain_id, domain_record_id)
17
+ domain_record = service.view_domain_record(domain_id, domain_record_id)
18
+ new add_domain_id(domain_id, domain_record)
19
+ end
20
+
21
+ private
22
+
23
+ def add_domain_id(domain_id, domain_record)
24
+ domain_record['domain_id'] = domain_id
25
+ domain_record
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/linode/compute/models/type'
3
+
4
+ module Fog
5
+ module Linode
6
+ class DNS
7
+ # Collection class for loading Type models from Linode instance type data
8
+ class Domains < Fog::Collection
9
+ model Domain
10
+
11
+ def all(options = {})
12
+ domains = service.list_domains(options)
13
+ load domains
14
+ end
15
+
16
+ def get(id)
17
+ domain = service.view_domain(id)
18
+ new domain
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Linode
3
+ class DNS
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def create_domain(options = {})
7
+ response = request(
8
+ expects: [200],
9
+ method: 'POST',
10
+ path: 'domains',
11
+ body: Fog::JSON.encode(options),
12
+ headers: {
13
+ 'Content-Type' => 'application/json'
14
+ }
15
+ )
16
+
17
+ response.body
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Linode
3
+ class DNS
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def create_domain_record(domain_id, options = {})
7
+ response = request(
8
+ expects: [200],
9
+ method: 'POST',
10
+ path: "domains/#{domain_id}/records",
11
+ body: Fog::JSON.encode(options),
12
+ headers: {
13
+ 'Content-Type' => 'application/json'
14
+ }
15
+ )
16
+
17
+ response.body
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class DNS
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def delete_domain(id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'DELETE',
10
+ path: "domains/#{id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Linode
3
+ class DNS
4
+ # This class provides the actual implementation for service calls
5
+ class Real
6
+ def delete_domain_record(domain_id, domain_record_id)
7
+ response = request(
8
+ expects: [200],
9
+ method: 'DELETE',
10
+ path: "domains/#{domain_id}/records/#{domain_record_id}"
11
+ )
12
+ response.body
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end