fog-joyent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rubocop.yml +20 -0
  4. data/.rubocop_todo.yml +436 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +26 -0
  8. data/CONTRIBUTING.md +18 -0
  9. data/CONTRIBUTORS.md +17 -0
  10. data/Gemfile +4 -0
  11. data/LICENSE.md +10 -0
  12. data/README.md +29 -0
  13. data/Rakefile +12 -0
  14. data/fog-joyent.gemspec +29 -0
  15. data/lib/fog/bin/joyent.rb +33 -0
  16. data/lib/fog/joyent.rb +16 -0
  17. data/lib/fog/joyent/analytics.rb +310 -0
  18. data/lib/fog/joyent/compute.rb +272 -0
  19. data/lib/fog/joyent/core.rb +10 -0
  20. data/lib/fog/joyent/errors.rb +91 -0
  21. data/lib/fog/joyent/models/analytics/field.rb +13 -0
  22. data/lib/fog/joyent/models/analytics/fields.rb +24 -0
  23. data/lib/fog/joyent/models/analytics/instrumentation.rb +82 -0
  24. data/lib/fog/joyent/models/analytics/instrumentations.rb +23 -0
  25. data/lib/fog/joyent/models/analytics/joyent_module.rb +13 -0
  26. data/lib/fog/joyent/models/analytics/joyent_modules.rb +24 -0
  27. data/lib/fog/joyent/models/analytics/metric.rb +17 -0
  28. data/lib/fog/joyent/models/analytics/metrics.rb +16 -0
  29. data/lib/fog/joyent/models/analytics/transformation.rb +13 -0
  30. data/lib/fog/joyent/models/analytics/transformations.rb +24 -0
  31. data/lib/fog/joyent/models/analytics/type.rb +16 -0
  32. data/lib/fog/joyent/models/analytics/types.rb +24 -0
  33. data/lib/fog/joyent/models/analytics/value.rb +20 -0
  34. data/lib/fog/joyent/models/compute/datacenter.rb +11 -0
  35. data/lib/fog/joyent/models/compute/datacenters.rb +21 -0
  36. data/lib/fog/joyent/models/compute/flavor.rb +19 -0
  37. data/lib/fog/joyent/models/compute/flavors.rb +21 -0
  38. data/lib/fog/joyent/models/compute/image.rb +26 -0
  39. data/lib/fog/joyent/models/compute/images.rb +30 -0
  40. data/lib/fog/joyent/models/compute/key.rb +19 -0
  41. data/lib/fog/joyent/models/compute/keys.rb +32 -0
  42. data/lib/fog/joyent/models/compute/network.rb +12 -0
  43. data/lib/fog/joyent/models/compute/networks.rb +14 -0
  44. data/lib/fog/joyent/models/compute/server.rb +124 -0
  45. data/lib/fog/joyent/models/compute/servers.rb +35 -0
  46. data/lib/fog/joyent/models/compute/snapshot.rb +44 -0
  47. data/lib/fog/joyent/models/compute/snapshots.rb +35 -0
  48. data/lib/fog/joyent/requests/analytics/create_instrumentation.rb +25 -0
  49. data/lib/fog/joyent/requests/analytics/delete_instrumentation.rb +23 -0
  50. data/lib/fog/joyent/requests/analytics/describe_analytics.rb +26 -0
  51. data/lib/fog/joyent/requests/analytics/get_instrumentation.rb +26 -0
  52. data/lib/fog/joyent/requests/analytics/get_instrumentation_value.rb +30 -0
  53. data/lib/fog/joyent/requests/analytics/list_instrumentations.rb +25 -0
  54. data/lib/fog/joyent/requests/compute/add_machine_tags.rb +19 -0
  55. data/lib/fog/joyent/requests/compute/create_key.rb +54 -0
  56. data/lib/fog/joyent/requests/compute/create_machine.rb +16 -0
  57. data/lib/fog/joyent/requests/compute/create_machine_snapshot.rb +16 -0
  58. data/lib/fog/joyent/requests/compute/delete_all_machine_metadata.rb +16 -0
  59. data/lib/fog/joyent/requests/compute/delete_all_machine_tags.rb +15 -0
  60. data/lib/fog/joyent/requests/compute/delete_key.rb +27 -0
  61. data/lib/fog/joyent/requests/compute/delete_machine.rb +15 -0
  62. data/lib/fog/joyent/requests/compute/delete_machine_metadata.rb +16 -0
  63. data/lib/fog/joyent/requests/compute/delete_machine_snapshot.rb +18 -0
  64. data/lib/fog/joyent/requests/compute/delete_machine_tag.rb +15 -0
  65. data/lib/fog/joyent/requests/compute/get_dataset.rb +27 -0
  66. data/lib/fog/joyent/requests/compute/get_image.rb +28 -0
  67. data/lib/fog/joyent/requests/compute/get_key.rb +29 -0
  68. data/lib/fog/joyent/requests/compute/get_machine.rb +29 -0
  69. data/lib/fog/joyent/requests/compute/get_machine_metadata.rb +24 -0
  70. data/lib/fog/joyent/requests/compute/get_machine_snapshot.rb +15 -0
  71. data/lib/fog/joyent/requests/compute/get_machine_tag.rb +18 -0
  72. data/lib/fog/joyent/requests/compute/get_package.rb +32 -0
  73. data/lib/fog/joyent/requests/compute/list_datacenters.rb +16 -0
  74. data/lib/fog/joyent/requests/compute/list_datasets.rb +24 -0
  75. data/lib/fog/joyent/requests/compute/list_images.rb +25 -0
  76. data/lib/fog/joyent/requests/compute/list_keys.rb +25 -0
  77. data/lib/fog/joyent/requests/compute/list_machine_snapshots.rb +15 -0
  78. data/lib/fog/joyent/requests/compute/list_machine_tags.rb +20 -0
  79. data/lib/fog/joyent/requests/compute/list_machines.rb +26 -0
  80. data/lib/fog/joyent/requests/compute/list_networks.rb +26 -0
  81. data/lib/fog/joyent/requests/compute/list_packages.rb +34 -0
  82. data/lib/fog/joyent/requests/compute/reboot_machine.rb +15 -0
  83. data/lib/fog/joyent/requests/compute/resize_machine.rb +16 -0
  84. data/lib/fog/joyent/requests/compute/start_machine.rb +16 -0
  85. data/lib/fog/joyent/requests/compute/start_machine_from_snapshot.rb +15 -0
  86. data/lib/fog/joyent/requests/compute/stop_machine.rb +16 -0
  87. data/lib/fog/joyent/requests/compute/update_machine_metadata.rb +15 -0
  88. data/lib/fog/joyent/version.rb +5 -0
  89. data/tests/helper.rb +18 -0
  90. data/tests/helpers/mock_helper.rb +16 -0
  91. data/tests/helpers/succeeds_helper.rb +9 -0
  92. data/tests/joyent/models/analytics/field_tests.rb +10 -0
  93. data/tests/joyent/models/analytics/fields_tests.rb +13 -0
  94. data/tests/joyent/models/analytics/instrumentation_tests.rb +13 -0
  95. data/tests/joyent/models/analytics/instrumentations_tests.rb +3 -0
  96. data/tests/joyent/models/analytics/joyent_module_tests.rb +10 -0
  97. data/tests/joyent/models/analytics/joyent_modules_tests.rb +13 -0
  98. data/tests/joyent/models/analytics/metric_tests.rb +10 -0
  99. data/tests/joyent/models/analytics/metrics_tests.rb +20 -0
  100. data/tests/joyent/models/analytics/transformation_tests.rb +10 -0
  101. data/tests/joyent/models/analytics/transformations_tests.rb +13 -0
  102. data/tests/joyent/models/analytics/type_tests.rb +10 -0
  103. data/tests/joyent/models/analytics/types_tests.rb +13 -0
  104. data/tests/joyent/requests/analytics/instrumentation_tests.rb +44 -0
  105. data/tests/joyent/requests/compute/datasets_tests.rb +58 -0
  106. data/tests/joyent/requests/compute/keys_tests.rb +47 -0
  107. data/tests/joyent/requests/compute/machines_tests.rb +66 -0
  108. data/tests/joyent/requests/compute/networks_tests.rb +39 -0
  109. data/tests/joyent/requests/compute/packages_tests.rb +68 -0
  110. metadata +235 -0
@@ -0,0 +1,35 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/joyent/models/compute/server'
3
+
4
+ module Fog
5
+ module Compute
6
+ class Joyent
7
+ class Servers < Fog::Collection
8
+ model Fog::Compute::Joyent::Server
9
+
10
+ def all
11
+ load(service.list_machines().body)
12
+ end
13
+
14
+ def create(params = {})
15
+ data = service.create_machine(params).body
16
+ server = new(data)
17
+ server
18
+ end
19
+
20
+ def bootstrap(new_attributes = {})
21
+ server = create(new_attributes)
22
+ server.wait_for { ready? }
23
+ server
24
+ end
25
+
26
+ def get(machine_id)
27
+ data = service.get_machine(machine_id).body
28
+ server = new(data)
29
+ server.tags = server.list_tags if server.tags.nil?
30
+ server
31
+ end
32
+ end
33
+ end # Joyent
34
+ end # Compute
35
+ end # Fog
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Snapshot < Fog::Model
5
+ identity :name
6
+
7
+ attribute :name
8
+ attribute :state
9
+ attribute :machine_id
10
+ attribute :created, :type => :time
11
+ attribute :updated, :type => :time
12
+
13
+ def reload
14
+ requires :name
15
+ requires :machine_id
16
+
17
+ service.snapshots.get(self.machine_id, self.name)
18
+ end
19
+
20
+ def start
21
+ requires :name
22
+ requires :machine_id
23
+
24
+ service.start_machine_from_snapshot(self.machine_id, self.name)
25
+ true
26
+ end
27
+
28
+ def destroy
29
+ requires :name
30
+ requires :machine_id
31
+
32
+ service.delete_machine_snapshot(self.machine_id, self.name)
33
+ true
34
+ end
35
+
36
+ def machine
37
+ requires :machine_id
38
+
39
+ service.servers.get(self.machine_id)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'fog/joyent/models/compute/snapshot'
2
+
3
+ module Fog
4
+ module Compute
5
+ class Joyent
6
+ class Snapshots < Fog::Collection
7
+ model Fog::Compute::Joyent::Snapshot
8
+
9
+ def create(machine_id, snapshot_name)
10
+ data = self.service.create_machine_snapshot(machine_id, snapshot_name).body
11
+ data['machine_id'] = machine_id
12
+ new(data)
13
+ end
14
+
15
+ def all(machine_id)
16
+ data = service.list_machine_snapshots(machine_id).body.map do |m|
17
+ m["machine_id"] = machine_id
18
+ m
19
+ end
20
+ load(data)
21
+ end
22
+
23
+ def get(machine_id, snapshot_name)
24
+ data = service.get_machine_snapshot(machine_id, snapshot_name).body
25
+ if data
26
+ data["machine_id"] = machine_id
27
+ new(data)
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def create_instrumentation(values = {})
6
+ request(
7
+ :path => "#{@joyent_username}/analytics/instrumentations",
8
+ :method => "POST",
9
+ :body => values,
10
+ :expects => [200,201]
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def create_instrumentation(values = {})
17
+ response = Excon::Response.new
18
+ response.status = 201
19
+ response.body = self.data[:instrumentation]
20
+ response
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def delete_instrumentation(id)
6
+ request(
7
+ :path => "#{@joyent_username}/analytics/instrumentations/#{id}",
8
+ :method => "DELETE",
9
+ :expects => 204
10
+ )
11
+ end
12
+ end
13
+
14
+ class Mock
15
+ def delete_instrumentation(id)
16
+ response = Excon::Response.new
17
+ response.status = 204
18
+ response
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def describe_analytics(force = false)
6
+ @describe_analytics = nil if force
7
+ @describe_analytics ||= request(
8
+ :path => "#{@joyent_username}/analytics",
9
+ :method => "GET",
10
+ :expects => 200,
11
+ :idempotent => true
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def describe_analytics(force = false)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = self.data[:describe_analytics]
21
+ response
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def get_instrumentation(id)
6
+ request(
7
+ :path => "#{@joyent_username}/analytics/instrumentations/#{id}",
8
+ :method => "GET",
9
+ :expects => 200,
10
+ :idempotent => true
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def get_instrumentation(id)
17
+ raise Fog::Compute::Joyent::Errors::NotFound.new('not found') unless id == self.data[:instrumentation]['id']
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = self.data[:instrumentation]
21
+ response
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def get_instrumentation_value(url, requested_start_time, ndatapoints, duration)
6
+ request(
7
+ :path => url,
8
+ :method => 'GET',
9
+ :expects => 200,
10
+ :idempotent => true,
11
+ :query => {
12
+ :ndatapoints => ndatapoints,
13
+ :start_time => requested_start_time.to_i,
14
+ :duration => duration
15
+ }
16
+ )
17
+ end
18
+ end
19
+
20
+ class Mock
21
+ def get_instrumentation_value(url, requested_start_time, ndatapoints, duration)
22
+ response = Excon::Response.new
23
+ response.status = 200
24
+ response.body = [self.data[:values]]
25
+ response
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Joyent
3
+ class Analytics
4
+ class Real
5
+ def list_instrumentations
6
+ request(
7
+ :path => "#{@joyent_username}/analytics/instrumentations",
8
+ :method => "GET",
9
+ :expects => 200,
10
+ :idempotent => true
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_instrumentations
17
+ response = Excon::Response.new
18
+ response.status = 200
19
+ response.body = [self.data[:instrumentation]]
20
+ response
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Real
5
+ # https://us-west-1.api.joyentcloud.com/docs#AddMachineTags
6
+ def add_machine_tags(machine_id, tags={})
7
+ raise ArgumentError, "tags must be a Hash of tags" unless tags.is_a?(Hash)
8
+
9
+ request(
10
+ :path => "/my/machines/#{machine_id}/tags",
11
+ :method => "POST",
12
+ :body => tags,
13
+ :expects => 200
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Mock
5
+ #
6
+ # https://us-west-1.api.joyentcloud.com/docs#CreateKey
7
+ #
8
+ def create_key(params)
9
+ name = params[:name]
10
+ key = params[:key]
11
+
12
+ record = {
13
+ "name" => name,
14
+ "key" => key,
15
+ "created" => Time.now.utc,
16
+ "updated" => Time.now.utc
17
+ }
18
+
19
+ self.data[:keys][name] = record
20
+
21
+ response = Excon::Response.new
22
+ response.status = 201
23
+ response.body = record
24
+ response
25
+ end
26
+ end # Mock
27
+
28
+ class Real
29
+ # Creates a new SSH Key
30
+ # ==== Parameters
31
+ # * name<~String> - Name to assign to this key
32
+ # * key<~String> - OpenSSH formatted public key
33
+ #
34
+ # ==== Returns
35
+ # * response<~Excon::Response>:
36
+ # * body<~Hash>:
37
+ # * 'name'<~String> - Name for this key
38
+ # * 'key'<~String> - OpenSSH formatted public key
39
+ #
40
+ def create_key(params={})
41
+ raise ArgumentError, "error creating key: [name] is required" unless params[:name]
42
+ raise ArgumentError, "error creating key: [key] is required" unless params[:key]
43
+
44
+ request(
45
+ :method => "POST",
46
+ :path => "/my/keys",
47
+ :body => { "name" => params[:name], "key" => params[:key] },
48
+ :expects => 201
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Real
5
+ def create_machine(params = {})
6
+ request(
7
+ :method => "POST",
8
+ :path => "/my/machines",
9
+ :body => params,
10
+ :expects => [200, 201, 202]
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Real
5
+ def create_machine_snapshot(machine_id, snapshot_name)
6
+ request(
7
+ :method => "POST",
8
+ :path => "/my/machines/#{machine_id}/snapshots",
9
+ :body => {"name" => snapshot_name },
10
+ :expects => [201]
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Real
5
+ # https://us-west-1.api.joyentcloud.com/docs#DeleteMachineMetadata
6
+ def delete_all_machine_metadata(machine_id)
7
+ request(
8
+ :method => "DELETE",
9
+ :path => "/my/machines/#{machine_id}/metadata",
10
+ :expects => 204
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Real
5
+ def delete_all_machine_tags(machine_id)
6
+ request(
7
+ :path => "/my/machines/#{machine_id}/tags",
8
+ :method => "DELETE",
9
+ :expects => 204
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Compute
3
+ class Joyent
4
+ class Mock
5
+ def delete_key(keyname)
6
+ if self.data[:keys].delete(keyname)
7
+ response = Excon::Response.new
8
+ response.status = 204
9
+ response
10
+ else
11
+ raise Excon::Errors::NotFound, "Not Found"
12
+ end
13
+ end
14
+ end
15
+
16
+ class Real
17
+ def delete_key(name)
18
+ request(
19
+ :method => "DELETE",
20
+ :path => "/my/keys/#{name}",
21
+ :expects => 204
22
+ )
23
+ end
24
+ end # Real
25
+ end
26
+ end
27
+ end