unit_hosting 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/History.txt +4 -0
- data/Manifest.txt +17 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +47 -0
- data/Rakefile +26 -0
- data/lib/unit_hosting/base.rb +47 -0
- data/lib/unit_hosting/hadoop/cluster_manager.rb +36 -0
- data/lib/unit_hosting/hadoop.rb +12 -0
- data/lib/unit_hosting/vm.rb +65 -0
- data/lib/unit_hosting/vm_group.rb +45 -0
- data/lib/unit_hosting/vm_recipe.rb +28 -0
- data/lib/unit_hosting.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_unit_hosting.rb +11 -0
- metadata +110 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/unit_hosting.rb
|
7
|
+
lib/unit_hosting/base.rb
|
8
|
+
lib/unit_hosting/vm.rb
|
9
|
+
lib/unit_hosting/vm_group.rb
|
10
|
+
lib/unit_hosting/vm_recipe.rb
|
11
|
+
lib/unit_hosting/hadoop.rb
|
12
|
+
lib/unit_hosting/hadoop/cluster_manager.rb
|
13
|
+
script/console
|
14
|
+
script/destroy
|
15
|
+
script/generate
|
16
|
+
test/test_helper.rb
|
17
|
+
test/test_unit_hosting.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= UnitHosting
|
2
|
+
|
3
|
+
* http://github.com/tumf/uhapi
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is a simple API wrapper of UnitHosting( http://www.unit-hosting.com/ ) .
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
sudo gem install unit_hosting
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
Copyright (c) 2010 Dino Co.,Ltd. http//www.dino.co.jp/
|
28
|
+
Copyright (c) 2010 Yoshihiro TAKAHARA
|
29
|
+
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
31
|
+
a copy of this software and associated documentation files (the
|
32
|
+
'Software'), to deal in the Software without restriction, including
|
33
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
34
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
35
|
+
permit persons to whom the Software is furnished to do so, subject to
|
36
|
+
the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
43
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
44
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
45
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
46
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
47
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/unit_hosting'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'unit_hosting' do
|
14
|
+
self.developer 'Yoshihiro TAKAHARA', 'takahara@dino.co.jp'
|
15
|
+
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
require 'rubygems'
|
4
|
+
require 'pp'
|
5
|
+
require 'logger'
|
6
|
+
require 'xmlrpc/client'
|
7
|
+
require 'optparse'
|
8
|
+
require 'rexml/document'
|
9
|
+
|
10
|
+
module UnitHosting
|
11
|
+
def keypath instance_id
|
12
|
+
"%s/.UnitHosting/keys/%s.key" % [ENV['HOME'], instance_id]
|
13
|
+
end
|
14
|
+
module_function :keypath
|
15
|
+
class Base
|
16
|
+
attr_reader :instance_id;
|
17
|
+
def initialize(instance_id=nil,api_key=nil)
|
18
|
+
@instance_id = instance_id
|
19
|
+
@api_key = api_key
|
20
|
+
@server = XMLRPC::Client.
|
21
|
+
new_from_uri("https://www.unit-hosting.com/xmlrpc")
|
22
|
+
@server.instance_variable_get(:@http).
|
23
|
+
instance_variable_get(:@ssl_context).
|
24
|
+
instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
|
25
|
+
end
|
26
|
+
def self.load(instance_id)
|
27
|
+
self.new.load(instance_id)
|
28
|
+
end
|
29
|
+
def load(instance_id)
|
30
|
+
load_key(UnitHosting::keypath(instance_id))
|
31
|
+
end
|
32
|
+
def load_key(file)
|
33
|
+
File::open(file) do |f|
|
34
|
+
xml = f.read
|
35
|
+
doc = REXML::Document.new(xml)
|
36
|
+
@instance_id = doc.elements[@instance_id_elm].text
|
37
|
+
@api_key = doc.elements[@api_key_elm].text
|
38
|
+
end
|
39
|
+
self
|
40
|
+
end
|
41
|
+
def server_call(method,param = {})
|
42
|
+
param["instance_id"] = @instance_id
|
43
|
+
param["api_key"] = @api_key
|
44
|
+
return @server.call(method,param)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
require 'unit_hosting/vm_group'
|
4
|
+
|
5
|
+
module UnitHosting
|
6
|
+
module Hadoop
|
7
|
+
class ClusterManger
|
8
|
+
attr_reader :nodes, :master, :slave, :clusters, :slaves, :group
|
9
|
+
def clear_vars
|
10
|
+
@nodes = nil
|
11
|
+
@master = nil
|
12
|
+
@slave = nil
|
13
|
+
@clusters = Array.new
|
14
|
+
@slaves = Array.new
|
15
|
+
end
|
16
|
+
def initialize server_group
|
17
|
+
@group = UnitHosting::VmGroup.load(server_group)
|
18
|
+
update
|
19
|
+
end
|
20
|
+
def update
|
21
|
+
@vms = @group.vms
|
22
|
+
clear_vars
|
23
|
+
@vms.each do |instance_id,vm|
|
24
|
+
@master = vm if vm.display_name == "master"
|
25
|
+
@slave = vm if vm.display_name == "slave"
|
26
|
+
@clusters << vm if vm.display_name == "slave-cluster"
|
27
|
+
end
|
28
|
+
@slaves = @clusters.clone
|
29
|
+
@slaves << slave
|
30
|
+
@nodes = @slaves.clone
|
31
|
+
@nodes << @master
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
5
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
module UnitHosting
|
8
|
+
module Hadoop
|
9
|
+
VERSION = '0.0.1'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
require 'unit_hosting'
|
4
|
+
|
5
|
+
module UnitHosting
|
6
|
+
class Vm < Base
|
7
|
+
def initialize(instance_id=nil,api_key=nil)
|
8
|
+
@instance_id_elm = '/server/instance_id'
|
9
|
+
@api_key_elm = '/server/key'
|
10
|
+
super
|
11
|
+
end
|
12
|
+
def reboot
|
13
|
+
server_call("vm.reboot")
|
14
|
+
end
|
15
|
+
def start
|
16
|
+
server_call("vm.start")
|
17
|
+
end
|
18
|
+
def shutdown
|
19
|
+
server_call("vm.shutdown")
|
20
|
+
end
|
21
|
+
def power_off
|
22
|
+
server_call("vm.powerOff")
|
23
|
+
end
|
24
|
+
def destroy
|
25
|
+
server_call("vm.destroy")
|
26
|
+
end
|
27
|
+
def status?
|
28
|
+
server_call("vm.getStatus")
|
29
|
+
end
|
30
|
+
def memory_unit_size size
|
31
|
+
server_call("vm.setMemoryUnitSize",{"size" => size})
|
32
|
+
end
|
33
|
+
def cpu_unit_num num
|
34
|
+
server_call("vm.setCpuUnitNum",{"num" => num})
|
35
|
+
end
|
36
|
+
def memory_unit_size?
|
37
|
+
server_call("vm.getMemoryUnitSize")
|
38
|
+
end
|
39
|
+
def cpu_unit_num?
|
40
|
+
server_call("vm.getCpuUnitNum")
|
41
|
+
end
|
42
|
+
def ipInfo?
|
43
|
+
server_call("vm.getIpInfo")
|
44
|
+
end
|
45
|
+
def display_name
|
46
|
+
server_call("vm.getDisplayName")
|
47
|
+
end
|
48
|
+
def display_name= name
|
49
|
+
server_call("vm.setDisplayName",{"display_name" => name})
|
50
|
+
end
|
51
|
+
def replicate name=""
|
52
|
+
server_call("vm.replicate",{"display_name" => name})
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
if $0 == __FILE__
|
59
|
+
vm = UnitHosting::Vm.load("tumf-vm-105")
|
60
|
+
pp vm.status?
|
61
|
+
pp vm.ipInfo?
|
62
|
+
# vm.reboot
|
63
|
+
end
|
64
|
+
|
65
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
require 'unit_hosting'
|
4
|
+
|
5
|
+
module UnitHosting
|
6
|
+
class VmGroup < Base
|
7
|
+
def initialize(instance_id=nil,api_key=nil)
|
8
|
+
@instance_id_elm = '/server-group/instance_id'
|
9
|
+
@api_key_elm = '/server-group/key'
|
10
|
+
super
|
11
|
+
end
|
12
|
+
# このサーバグループに含まれるVMオブジェクトをすべて返す
|
13
|
+
def vms
|
14
|
+
objs = Hash.new
|
15
|
+
server_call("vmGroup.getVms").each do |vm|
|
16
|
+
objs[vm["instance_id"]] = Vm.new(vm["instance_id"],vm["api_key"])
|
17
|
+
end
|
18
|
+
objs
|
19
|
+
end
|
20
|
+
def vm_api_key instance_id
|
21
|
+
server_call("vmGroup.getVms").each do |vm|
|
22
|
+
return vm["api_key"] if vm[instance_id] == instance_id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# instance_idに紐づくvmを返す
|
26
|
+
def vm(instance_id)
|
27
|
+
Vm.new(instance_id,vm_api_key(instance_id))
|
28
|
+
end
|
29
|
+
# vmの作成
|
30
|
+
def create_vm(recipe)
|
31
|
+
r = server_call("vmGroup.createVm",recipe.params)
|
32
|
+
return false if r["result"] != "success"
|
33
|
+
r
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if $0 == __FILE__
|
39
|
+
pp UnitHosting::VmGroup.load('tumf-sg-10').vm('tumf-vm-107')
|
40
|
+
exit
|
41
|
+
recipe = UnitHosting::VmRecipe.new
|
42
|
+
# recipe.
|
43
|
+
end
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim:set fileencoding=utf-8:
|
3
|
+
require 'unit_hosting/base'
|
4
|
+
module UnitHosting
|
5
|
+
class VmRecipe
|
6
|
+
attr_accessor :rootpw,:ssh_key,:plan_id
|
7
|
+
attr_accessor :op_user,:op_mail,:user_script,:display_name
|
8
|
+
def initialize
|
9
|
+
@op_user = ENV['USER']
|
10
|
+
end
|
11
|
+
def load_ssh_key file
|
12
|
+
File::open(file) do |f|
|
13
|
+
@ssh_key = f.read
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def params
|
17
|
+
param = {
|
18
|
+
"rootpw" => @rootpw,
|
19
|
+
"ssh_key" => @ssh_key,
|
20
|
+
"op_user" => @op_user,
|
21
|
+
"op_mail" => @op_mail,
|
22
|
+
"user_script" => @user_script,
|
23
|
+
"plan_id" => @plan_id,
|
24
|
+
"display_name" => @display_name
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/unit_hosting.rb
ADDED
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/unit_hosting.rb'}"
|
9
|
+
puts "Loading unit_hosting gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unit_hosting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Yoshihiro TAKAHARA
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-11 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubyforge
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
version: 2.0.3
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: hoe
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 6
|
44
|
+
- 0
|
45
|
+
version: 2.6.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: This is a simple API wrapper of UnitHosting( http://www.unit-hosting.com/ ) .
|
49
|
+
email:
|
50
|
+
- takahara@dino.co.jp
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- History.txt
|
57
|
+
- Manifest.txt
|
58
|
+
- PostInstall.txt
|
59
|
+
files:
|
60
|
+
- History.txt
|
61
|
+
- Manifest.txt
|
62
|
+
- PostInstall.txt
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- lib/unit_hosting.rb
|
66
|
+
- lib/unit_hosting/base.rb
|
67
|
+
- lib/unit_hosting/vm.rb
|
68
|
+
- lib/unit_hosting/vm_group.rb
|
69
|
+
- lib/unit_hosting/vm_recipe.rb
|
70
|
+
- lib/unit_hosting/hadoop.rb
|
71
|
+
- lib/unit_hosting/hadoop/cluster_manager.rb
|
72
|
+
- script/console
|
73
|
+
- script/destroy
|
74
|
+
- script/generate
|
75
|
+
- test/test_helper.rb
|
76
|
+
- test/test_unit_hosting.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/tumf/uhapi
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: unit_hosting
|
104
|
+
rubygems_version: 1.3.6
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: This is a simple API wrapper of UnitHosting( http://www.unit-hosting.com/ ) .
|
108
|
+
test_files:
|
109
|
+
- test/test_helper.rb
|
110
|
+
- test/test_unit_hosting.rb
|