fog-tenderloin 0.0.1
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.
- data/README.md +19 -0
- data/lib/fog-tenderloin.rb +2 -0
- data/lib/fog/tenderloin.rb +31 -0
- data/lib/fog/tenderloin/compute.rb +74 -0
- data/lib/fog/tenderloin/models/compute/server.rb +74 -0
- data/lib/fog/tenderloin/models/compute/servers.rb +32 -0
- data/lib/fog/tenderloin/requests/compute/destroy_vm.rb +13 -0
- data/lib/fog/tenderloin/requests/compute/get_vm.rb +13 -0
- data/lib/fog/tenderloin/requests/compute/list_vms.rb +13 -0
- data/lib/fog/tenderloin/requests/compute/start_vm.rb +13 -0
- data/lib/fog/tenderloin/requests/compute/stop_vm.rb +13 -0
- metadata +90 -0
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# fog-tenderloin
|
2
|
+
|
3
|
+
Implementation of Tenderloin for Fog.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
This will treat a collection of loin definition files as a fog server collection, allowing you to start/stop/SSH in to them.
|
8
|
+
|
9
|
+
The default search pattern is `**/*.loin`, this can be configured when you create instantiate the instance.
|
10
|
+
|
11
|
+
Fog::Compute.new(:provider => "Tenderloin", :loinfile_glob => '**/*.loin', :loin_cmd => 'loin')
|
12
|
+
|
13
|
+
The loin\_cmd and loinfile\_glob parameters are optional - the defaults are shown above.
|
14
|
+
|
15
|
+
You can then manipulate this as per usual for fog
|
16
|
+
|
17
|
+
compute.servers.first.start
|
18
|
+
compute.servers.first.ssh("ls /")
|
19
|
+
compute.servers.first.stop
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fog/core'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Tenderloin
|
5
|
+
|
6
|
+
extend Fog::Provider
|
7
|
+
|
8
|
+
service(:compute, 'tenderloin/compute', 'Compute')
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Monkey patch out provider lookup
|
14
|
+
module Fog
|
15
|
+
module Compute
|
16
|
+
class << self
|
17
|
+
alias_method :pre_tenderloin_new, :new
|
18
|
+
|
19
|
+
def new(attributes)
|
20
|
+
dup_attr = attributes.dup # prevent delete from having side effects
|
21
|
+
provider = dup_attr.delete(:provider).to_s.downcase.to_sym
|
22
|
+
if provider == :tenderloin
|
23
|
+
require 'fog/tenderloin/compute'
|
24
|
+
Fog::Compute::Tenderloin.new(dup_attr)
|
25
|
+
else
|
26
|
+
pre_tenderloin_new(attributes)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'fog/tenderloin'
|
2
|
+
require 'fog/compute'
|
3
|
+
require 'base64'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Fog
|
7
|
+
module Compute
|
8
|
+
class Tenderloin < Fog::Service
|
9
|
+
|
10
|
+
recognizes :loin_cmd, :loinfile_glob
|
11
|
+
|
12
|
+
model_path 'fog/tenderloin/models/compute'
|
13
|
+
model :server
|
14
|
+
collection :servers
|
15
|
+
|
16
|
+
request_path 'fog/tenderloin/requests/compute'
|
17
|
+
request :list_vms
|
18
|
+
request :get_vm
|
19
|
+
request :start_vm
|
20
|
+
request :stop_vm
|
21
|
+
request :destroy_vm
|
22
|
+
|
23
|
+
class Mock
|
24
|
+
|
25
|
+
def initialize(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def request(options)
|
29
|
+
raise "Not implemented"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Real
|
34
|
+
|
35
|
+
def initialize(options)
|
36
|
+
@vm_glob = options[:loinfile_glob] || "**/*.loin"
|
37
|
+
@loin_cmd = options[:loin_cmd] || "loin"
|
38
|
+
end
|
39
|
+
|
40
|
+
def request(params, json_resp=false)
|
41
|
+
params = params.join(" ") if params.kind_of? Array
|
42
|
+
ret = `#{@loin_cmd} #{params}`
|
43
|
+
|
44
|
+
raise "Error running command:\n#{ret}" if $? != 0
|
45
|
+
|
46
|
+
if json_resp
|
47
|
+
to_dotted_hash(Fog::JSON.decode(ret))
|
48
|
+
else
|
49
|
+
ret
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_dotted_hash(source, target = {}, namespace = nil)
|
54
|
+
prefix = "#{namespace}." if namespace
|
55
|
+
case source
|
56
|
+
when Hash
|
57
|
+
source.each do |key, value|
|
58
|
+
to_dotted_hash(value, target, "#{prefix}#{key}")
|
59
|
+
end
|
60
|
+
when Array
|
61
|
+
source.each_with_index do |value, index|
|
62
|
+
to_dotted_hash(value, target, "#{prefix}#{index}")
|
63
|
+
end
|
64
|
+
else
|
65
|
+
target[namespace] = source
|
66
|
+
end
|
67
|
+
target
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'fog/compute/models/server'
|
2
|
+
|
3
|
+
module Fog
|
4
|
+
module Compute
|
5
|
+
class Tenderloin
|
6
|
+
|
7
|
+
class Server < Fog::Compute::Server
|
8
|
+
|
9
|
+
identity :id
|
10
|
+
|
11
|
+
attribute :running, :aliases => 'vm.running'
|
12
|
+
attribute :ip, :aliases => 'vm.ip'
|
13
|
+
attribute :private_key, :aliases => 'config.ssh.key'
|
14
|
+
attribute :port, :aliases => 'config.ssh.port'
|
15
|
+
attribute :username, :aliases => 'config.ssh.username'
|
16
|
+
attribute :password, :aliases => 'config.ssh.password'
|
17
|
+
|
18
|
+
|
19
|
+
def ssh(commands, options={}, &blk)
|
20
|
+
require 'net/ssh'
|
21
|
+
options[:password] = password
|
22
|
+
super(commands, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ready?
|
26
|
+
running && ip
|
27
|
+
end
|
28
|
+
|
29
|
+
def running?
|
30
|
+
running
|
31
|
+
end
|
32
|
+
|
33
|
+
def public_ip_address
|
34
|
+
ip
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(attributes={})
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def save
|
42
|
+
raise "Save not implemented"
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
requires :id
|
47
|
+
connection.destroy_vm(id)
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def start
|
52
|
+
requires :id
|
53
|
+
connection.start_vm(id)
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
def stop
|
58
|
+
requires :id
|
59
|
+
connection.stop_vm(id)
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def sshable?
|
64
|
+
ready? && !public_ip_address.nil? && !!Timeout::timeout(30) { ssh 'pwd' }
|
65
|
+
rescue SystemCallError, Net::SSH::AuthenticationFailed, Timeout::Error
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/tenderloin/models/compute/server'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module Compute
|
6
|
+
class Tenderloin
|
7
|
+
|
8
|
+
class Servers < Fog::Collection
|
9
|
+
|
10
|
+
model Fog::Compute::Tenderloin::Server
|
11
|
+
|
12
|
+
def all()
|
13
|
+
vms = connection.list_vms().collect do |vm|
|
14
|
+
connection.get_vm(vm)
|
15
|
+
end
|
16
|
+
load(vms)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(identifier)
|
20
|
+
data = connection.get_vm(identifier)
|
21
|
+
if data.empty?
|
22
|
+
nil
|
23
|
+
else
|
24
|
+
new(data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fog-tenderloin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lincoln Stoll
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fog
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.7'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.7'
|
46
|
+
description: Fog implementation for Tenderloin
|
47
|
+
email:
|
48
|
+
- lincoln@github.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.md
|
53
|
+
files:
|
54
|
+
- lib/fog/tenderloin/compute.rb
|
55
|
+
- lib/fog/tenderloin/models/compute/server.rb
|
56
|
+
- lib/fog/tenderloin/models/compute/servers.rb
|
57
|
+
- lib/fog/tenderloin/requests/compute/destroy_vm.rb
|
58
|
+
- lib/fog/tenderloin/requests/compute/get_vm.rb
|
59
|
+
- lib/fog/tenderloin/requests/compute/list_vms.rb
|
60
|
+
- lib/fog/tenderloin/requests/compute/start_vm.rb
|
61
|
+
- lib/fog/tenderloin/requests/compute/stop_vm.rb
|
62
|
+
- lib/fog/tenderloin.rb
|
63
|
+
- lib/fog-tenderloin.rb
|
64
|
+
- README.md
|
65
|
+
homepage: http://github.com/lstoll/fog-tenderloin
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options:
|
69
|
+
- --charset=UTF-8
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.23
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Fog implementation for Tenderloin
|
90
|
+
test_files: []
|