fog-cloudatcost 0.1.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.
- checksums.yaml +7 -0
- data/.codeclimate.yml +28 -0
- data/.gitignore +37 -0
- data/.rubocop.yml +1168 -0
- data/.travis.yml +38 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +21 -0
- data/fog-cloudatcost.gemspec +32 -0
- data/gemfiles/Gemfile-edge +9 -0
- data/lib/fog/cloudatcost.rb +5 -0
- data/lib/fog/cloudatcost/compute.rb +80 -0
- data/lib/fog/cloudatcost/core.rb +9 -0
- data/lib/fog/cloudatcost/examples/getting_started.md +82 -0
- data/lib/fog/cloudatcost/models/server.rb +96 -0
- data/lib/fog/cloudatcost/models/servers.rb +28 -0
- data/lib/fog/cloudatcost/models/task.rb +21 -0
- data/lib/fog/cloudatcost/models/tasks.rb +28 -0
- data/lib/fog/cloudatcost/models/template.rb +10 -0
- data/lib/fog/cloudatcost/models/templates.rb +28 -0
- data/lib/fog/cloudatcost/requests/console.rb +32 -0
- data/lib/fog/cloudatcost/requests/create_server.rb +33 -0
- data/lib/fog/cloudatcost/requests/delete_server.rb +33 -0
- data/lib/fog/cloudatcost/requests/list_servers.rb +28 -0
- data/lib/fog/cloudatcost/requests/list_tasks.rb +28 -0
- data/lib/fog/cloudatcost/requests/list_templates.rb +28 -0
- data/lib/fog/cloudatcost/requests/power_off.rb +34 -0
- data/lib/fog/cloudatcost/requests/power_on.rb +34 -0
- data/lib/fog/cloudatcost/requests/rename_server.rb +32 -0
- data/lib/fog/cloudatcost/requests/reset.rb +34 -0
- data/lib/fog/cloudatcost/requests/reverse_dns.rb +32 -0
- data/lib/fog/cloudatcost/requests/run_mode.rb +32 -0
- data/lib/fog/cloudatcost/version.rb +5 -0
- data/spec/fog/models/server_spec.rb +18 -0
- data/spec/fog/models/servers_spec.rb +11 -0
- data/spec/fog/models/task_spec.rb +58 -0
- data/spec/fog/models/tasks_spec.rb +11 -0
- data/spec/fog/models/template_spec.rb +14 -0
- data/spec/fog/models/templates_spec.rb +11 -0
- data/spec/model_setup.rb +14 -0
- data/spec/spec_helper.rb +5 -0
- metadata +208 -0
data/.travis.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
script: bundle exec rake test
|
4
|
+
cache: bundler
|
5
|
+
branches:
|
6
|
+
except:
|
7
|
+
- "/\\Av\\d+\\Z/"
|
8
|
+
matrix:
|
9
|
+
fast_finish: true
|
10
|
+
include:
|
11
|
+
- rvm: 1.9.3
|
12
|
+
gemfile: Gemfile
|
13
|
+
- rvm: 2.0.0
|
14
|
+
gemfile: Gemfile
|
15
|
+
- rvm: 2.1.0
|
16
|
+
gemfile: Gemfile
|
17
|
+
- rvm: 2.1.1
|
18
|
+
gemfile: Gemfile
|
19
|
+
- rvm: 2.1.1
|
20
|
+
gemfile: gemfiles/Gemfile-edge
|
21
|
+
- rvm: 2.2.0
|
22
|
+
gemfile: Gemfile
|
23
|
+
- rvm: 2.2.0
|
24
|
+
gemfile: gemfiles/Gemfile-edge
|
25
|
+
- rvm: 2.3.0
|
26
|
+
gemfile: Gemfile
|
27
|
+
- rvm: 2.3.0
|
28
|
+
gemfile: gemfiles/Gemfile-edge
|
29
|
+
- rvm: jruby-19mode
|
30
|
+
gemfile: Gemfile
|
31
|
+
- rvm: jruby-head
|
32
|
+
gemfile: Gemfile
|
33
|
+
allow_failures:
|
34
|
+
- rvm: jruby-head
|
35
|
+
|
36
|
+
addons:
|
37
|
+
code_climate:
|
38
|
+
repo_token: 412dc14b81fbd1f8d7356deb5feac31a8d69583d00ec1ba18040caf99343ee25
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fog-cloudatcost (0.1.0)
|
5
|
+
fog-core (~> 1.27)
|
6
|
+
fog-json (~> 1.0)
|
7
|
+
fog-xml (~> 0.1)
|
8
|
+
ipaddress (~> 0.8)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
builder (3.2.2)
|
14
|
+
codeclimate-test-reporter (0.4.8)
|
15
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
docile (1.1.5)
|
18
|
+
excon (0.45.4)
|
19
|
+
fog-core (1.35.0)
|
20
|
+
builder
|
21
|
+
excon (~> 0.45)
|
22
|
+
formatador (~> 0.2)
|
23
|
+
fog-json (1.0.2)
|
24
|
+
fog-core (~> 1.0)
|
25
|
+
multi_json (~> 1.10)
|
26
|
+
fog-xml (0.1.2)
|
27
|
+
fog-core
|
28
|
+
nokogiri (~> 1.5, >= 1.5.11)
|
29
|
+
formatador (0.2.5)
|
30
|
+
ipaddress (0.8.2)
|
31
|
+
json (1.8.3)
|
32
|
+
mini_portile2 (2.0.0)
|
33
|
+
multi_json (1.11.2)
|
34
|
+
nokogiri (1.6.7.1)
|
35
|
+
mini_portile2 (~> 2.0.0.rc2)
|
36
|
+
rake (10.4.2)
|
37
|
+
rspec (3.4.0)
|
38
|
+
rspec-core (~> 3.4.0)
|
39
|
+
rspec-expectations (~> 3.4.0)
|
40
|
+
rspec-mocks (~> 3.4.0)
|
41
|
+
rspec-core (3.4.1)
|
42
|
+
rspec-support (~> 3.4.0)
|
43
|
+
rspec-expectations (3.4.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.4.0)
|
46
|
+
rspec-mocks (3.4.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.4.0)
|
49
|
+
rspec-support (3.4.1)
|
50
|
+
rubyzip (0.9.9)
|
51
|
+
simplecov (0.11.1)
|
52
|
+
docile (~> 1.1.0)
|
53
|
+
json (~> 1.8)
|
54
|
+
simplecov-html (~> 0.10.0)
|
55
|
+
simplecov-html (0.10.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
bundler (~> 1.6)
|
62
|
+
codeclimate-test-reporter
|
63
|
+
fog-cloudatcost!
|
64
|
+
rake (~> 10.0)
|
65
|
+
rspec (~> 3.4.0)
|
66
|
+
rubyzip (~> 0.9.9)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
1.11.2
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Suraj Shirvankar
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/h0lyalg0rithm/fog-cloudatcost)
|
2
|
+
[](https://codeclimate.com/github/h0lyalg0rithm/fog-cloudatcost)
|
3
|
+
|
4
|
+
# fog-cloudatcost
|
5
|
+
Module for the 'fog' gem to support Amazon Web Services http://panel.cloudatcost.com/
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'rake/testtask'
|
7
|
+
|
8
|
+
task :test do
|
9
|
+
sh("bundle exec rspec")
|
10
|
+
end
|
11
|
+
|
12
|
+
require_relative 'lib/fog/cloudatcost'
|
13
|
+
|
14
|
+
task :default => :test
|
15
|
+
mock = ENV['FOG_MOCK'] || 'true'
|
16
|
+
|
17
|
+
namespace :test do
|
18
|
+
task :travis do
|
19
|
+
sh("export FOG_MOCK=#{mock} && bundle exec rspec")
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'fog/cloudatcost/version'
|
4
|
+
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fog-cloudatcost'
|
8
|
+
spec.version = Fog::CloudAtCost::VERSION
|
9
|
+
spec.authors = ["Suraj Shirvankar"]
|
10
|
+
spec.email = ["surajshirvankar@gmail.com"]
|
11
|
+
spec.summary = %q{Module for the 'fog' gem to support CloudAtCost.}
|
12
|
+
spec.description = %q{This library can be used as a module for `fog` or as standalone provider
|
13
|
+
to use the Amazon Web Services in applications..}
|
14
|
+
spec.homepage = 'http://github.com/fog/fog-cloudatcost'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.4.0'
|
25
|
+
spec.add_development_dependency 'rubyzip', '~> 0.9.9'
|
26
|
+
|
27
|
+
spec.add_dependency 'fog-core', '~> 1.27'
|
28
|
+
spec.add_dependency 'fog-json', '~> 1.0'
|
29
|
+
spec.add_dependency 'fog-xml', '~> 0.1'
|
30
|
+
spec.add_dependency 'ipaddress', '~> 0.8'
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'fog/cloudatcost/core'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class CloudAtCost < Fog::Service
|
6
|
+
requires :api_key, :email
|
7
|
+
|
8
|
+
|
9
|
+
model_path 'fog/cloudatcost/models'
|
10
|
+
model :server
|
11
|
+
collection :servers
|
12
|
+
model :task
|
13
|
+
collection :tasks
|
14
|
+
model :template
|
15
|
+
collection :templates
|
16
|
+
|
17
|
+
request_path 'fog/cloudatcost/requests'
|
18
|
+
request :list_servers
|
19
|
+
request :list_tasks
|
20
|
+
request :console
|
21
|
+
request :create_server
|
22
|
+
request :list_templates
|
23
|
+
request :power_off
|
24
|
+
request :power_on
|
25
|
+
request :rename_server
|
26
|
+
request :reset
|
27
|
+
request :reverse_dns
|
28
|
+
request :run_mode
|
29
|
+
|
30
|
+
class Mock
|
31
|
+
|
32
|
+
def initialize(options={})
|
33
|
+
@api_key = options[:api_key]
|
34
|
+
@email = options[:email]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class Real
|
40
|
+
|
41
|
+
def initialize(options={})
|
42
|
+
@api_key = options[:api_key]
|
43
|
+
@email = options[:email]
|
44
|
+
persistent = false
|
45
|
+
@connection = Fog::Core::Connection.new 'https://panel.cloudatcost.com', persistent, options
|
46
|
+
end
|
47
|
+
|
48
|
+
def request(params)
|
49
|
+
params[:headers] ||= { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
50
|
+
params[:query] ||= {}
|
51
|
+
required_params = {
|
52
|
+
key: "#{@api_key}",
|
53
|
+
login: "#{@email}"
|
54
|
+
}
|
55
|
+
begin
|
56
|
+
if params[:method] == 'POST'
|
57
|
+
params_body = required_params.merge(params[:body])
|
58
|
+
params[:body] = params_body.reduce(""){ |acc,(x,y)| "#{acc}&#{x}=#{y}" }
|
59
|
+
else
|
60
|
+
params[:query] = required_params.merge(params[:query])
|
61
|
+
end
|
62
|
+
response = @connection.request(params)
|
63
|
+
rescue Excon::Errors::HTTPStatusError => error
|
64
|
+
raise case error
|
65
|
+
when Excon::Errors::NotFound
|
66
|
+
Fog::Compute::Bluebox::NotFound.slurp(error)
|
67
|
+
else
|
68
|
+
error
|
69
|
+
end
|
70
|
+
end
|
71
|
+
unless response.body.empty?
|
72
|
+
response.body = Fog::JSON.decode(response.body)
|
73
|
+
end
|
74
|
+
response
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# Getting started: the compute service
|
2
|
+
The CloudAtCost UI is pretty terrible,its slow and it stops working most of the time.Moreover you cannot customize the machines.This is where the fog comes to play.
|
3
|
+
|
4
|
+
To use fog
|
5
|
+
|
6
|
+
You'll need a CloudAtCost account and an API token to use this provider.
|
7
|
+
|
8
|
+
Get one from https://panel.cloudatcost.com.
|
9
|
+
|
10
|
+
Click on the settings button in menu.
|
11
|
+
Make sure you add your ip to the allowed ip field.
|
12
|
+
|
13
|
+
Write down the API Token.
|
14
|
+
|
15
|
+
## Connecting, retrieving and managing server objects
|
16
|
+
|
17
|
+
First, create a connection to the host:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'fog'
|
21
|
+
|
22
|
+
cac = Fog::Compute.new({
|
23
|
+
:provider => 'CloudAtCost',
|
24
|
+
:email => 'example@email.com', # Your email address
|
25
|
+
:api_key => 'poiuweoruwoeiuroiwuer', # your API Token
|
26
|
+
})
|
27
|
+
```
|
28
|
+
|
29
|
+
## Listing servers
|
30
|
+
|
31
|
+
Listing servers and attributes:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
cac do |server|
|
35
|
+
puts server.ip
|
36
|
+
puts server.servername
|
37
|
+
puts server.vmname
|
38
|
+
puts server.mode
|
39
|
+
puts server.label
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
## Server creation and life-cycle management
|
44
|
+
|
45
|
+
Creating a new server :
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
server = cac.servers.create :cpu => 'foobar', # 1, 2, 4
|
49
|
+
:ram => 1024, # multiple of 4 min 512
|
50
|
+
:storage => 10, # 10G
|
51
|
+
:template_id => 75 #Template id
|
52
|
+
```
|
53
|
+
|
54
|
+
The server is automatically started after that.
|
55
|
+
|
56
|
+
As you can see you need the template_id to create the server:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
cac.templates.each do |image|
|
60
|
+
puts image.id
|
61
|
+
puts image.detail
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
Power off a server:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
server = cac.servers.first
|
69
|
+
server.power_off
|
70
|
+
```
|
71
|
+
|
72
|
+
Power on a server:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
server.power_on
|
76
|
+
```
|
77
|
+
|
78
|
+
Destroying the server:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
server.destroy
|
82
|
+
```
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'fog/compute/models/server'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class CloudAtCost
|
6
|
+
class Server < Fog::Compute::Server
|
7
|
+
identity :sid
|
8
|
+
attribute :id
|
9
|
+
attribute :CustID
|
10
|
+
attribute :packageid
|
11
|
+
attribute :servername
|
12
|
+
attribute :label
|
13
|
+
attribute :vmname
|
14
|
+
attribute :ip
|
15
|
+
attribute :netmask
|
16
|
+
attribute :gateway
|
17
|
+
attribute :hostname
|
18
|
+
attribute :rootpass
|
19
|
+
attribute :vncport
|
20
|
+
attribute :vncpass
|
21
|
+
attribute :servertype
|
22
|
+
attribute :template
|
23
|
+
attribute :cpu
|
24
|
+
attribute :cpuusage
|
25
|
+
attribute :ram
|
26
|
+
attribute :ramusage
|
27
|
+
attribute :storage
|
28
|
+
attribute :hdusage
|
29
|
+
attribute :sdate
|
30
|
+
attribute :status
|
31
|
+
attribute :panel_note
|
32
|
+
attribute :mode
|
33
|
+
attribute :uid
|
34
|
+
attribute :rdns
|
35
|
+
attribute :rdnsdefault
|
36
|
+
attribute :template_id
|
37
|
+
|
38
|
+
|
39
|
+
def new_instance?
|
40
|
+
not persisted?
|
41
|
+
end
|
42
|
+
|
43
|
+
def save
|
44
|
+
raise Fog::Errors::Error.new('Re-saving an existing object may create a duplicate') if persisted?
|
45
|
+
save!
|
46
|
+
end
|
47
|
+
|
48
|
+
def save!
|
49
|
+
requires :cpu, :ram, :storage, :template_id
|
50
|
+
data = service.create_server(cpu, ram, storage, template_id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
perform_action :delete_server
|
55
|
+
end
|
56
|
+
|
57
|
+
def power_on
|
58
|
+
perform_action :power_on
|
59
|
+
end
|
60
|
+
|
61
|
+
def power_off
|
62
|
+
perform_action :power_off
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
perform_action :reset
|
67
|
+
end
|
68
|
+
|
69
|
+
def run_mode(mode)
|
70
|
+
perform_action :run_mode, mode
|
71
|
+
end
|
72
|
+
|
73
|
+
def rename_server(name)
|
74
|
+
perform_action :rename_server, name
|
75
|
+
end
|
76
|
+
|
77
|
+
def reverse_dns(hostname)
|
78
|
+
perform_action :reverse_dns, hostname
|
79
|
+
end
|
80
|
+
|
81
|
+
def console
|
82
|
+
perform_action :console
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def perform_action(action, *args)
|
88
|
+
requires :sid
|
89
|
+
response = service.send(action, sid, *args)
|
90
|
+
response.body
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|