unit-hosting 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Yoshihiro TAKAHARA
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,38 @@
1
+ = unit-hosting
2
+
3
+ This is a command to manage virtual servers on UnitHosting(http://www.unit-hosting.com).
4
+
5
+ == Install
6
+
7
+ sudo gem install unit-hosting
8
+
9
+ == Usage
10
+
11
+ unit-hosting [global options] command [command options] args..
12
+
13
+ === Global Options
14
+
15
+
16
+ === Commands
17
+
18
+ * login
19
+ * logout
20
+ * vm create|destroy|boot|shutdown
21
+ * group add|delete
22
+
23
+
24
+ == Contributing to unit-hosting
25
+
26
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
27
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
28
+ * Fork the project
29
+ * Start a feature/bugfix branch
30
+ * Commit and push until you are happy with your contribution
31
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
32
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2011 Yoshihiro TAKAHARA. See LICENSE.txt for
37
+ further details.
38
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "unit-hosting"
16
+ gem.homepage = "http://github.com/tumf/unit-hosting"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{unit-hosting command line tool}
19
+ gem.description = %Q{This is a command to manage virtual servers on UnitHosting(http://www.unit-hosting.com).}
20
+ gem.email = "y.takahara@gmail.com"
21
+ gem.authors = ["Yoshihiro TAKAHARA"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "unit-hosting #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/unit-hosting ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # vim:set fileencoding=utf-8:
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+ require 'unit-hosting/cli'
5
+ UnitHosting::CLI::run(ARGV)
6
+ exit
7
+
File without changes
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require "rubygems"
4
+ require "mechanize"
5
+
6
+ module UnitHosting
7
+ UHURL = "https://www.unit-hosting.com"
8
+ class Agent < Mechanize
9
+ def initialize
10
+ super
11
+ max_history = 0
12
+ end
13
+
14
+ def getr path
15
+ get(UHURL + path)
16
+ end
17
+
18
+ def login id,password
19
+ getr("/login")
20
+ form = page.forms[0]
21
+ form.fields.find{|f| f.name == "username" }.value = id
22
+ form.fields.find{|f| f.name == "password" }.value = password
23
+ submit(form)
24
+ end
25
+
26
+ def login?
27
+ getr("/dashboard")
28
+ /ログアウト/ =~ page.body # => OK
29
+ end
30
+
31
+ def logout
32
+ getr("/logout")
33
+ end
34
+
35
+ def groups
36
+ getr("/my/group")
37
+ page.search("#server-groups .instance_id a").each { |i|
38
+ puts i.text.to_s
39
+ }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'optparse'
4
+ require 'unit-hosting/commands'
5
+
6
+ module UnitHosting
7
+ class CLI
8
+ def initialize
9
+ @options = Hash.new
10
+ @options[:debug] = false
11
+ end
12
+
13
+ def execute(argv)
14
+ begin
15
+ @opt = OptionParser.new
16
+ @opt.on('--version', 'show version') { version;exit }
17
+ @opt.on('--help', 'show this message') { usage;exit }
18
+ @opt.on('--debug', 'debug mode') { @options[:debug] = true }
19
+ cmd_argv = @opt.order!(argv)
20
+ cmd = cmd_argv.shift
21
+ raise unless cmd
22
+ Commands.new(cmd_argv,@options).send(cmd)
23
+ rescue =>e
24
+ puts "Message: #{e}\n"
25
+ usage
26
+ raise e if @options[:debug]
27
+ end
28
+ end
29
+
30
+ def usage(e=nil)
31
+ puts @opt
32
+ puts "\nCommands:\n"
33
+ COMMANDS.each { |c|
34
+ puts " " + c
35
+ }
36
+ end
37
+
38
+ def version
39
+ File.open(File.dirname(__FILE__) + '/../../VERSION',"r") { |file|
40
+ puts file.gets
41
+ }
42
+ end
43
+
44
+ class << self
45
+ def run(argv)
46
+ self.new.execute(argv)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require "rubygems"
4
+ require "highline/import"
5
+
6
+ require "keystorage"
7
+
8
+ require "unit-hosting"
9
+ require "unit-hosting/agent"
10
+ #require "unit-hosting/api"
11
+
12
+ module UnitHosting
13
+ COMMANDS = ["help","login","logout"]
14
+ class Commands
15
+
16
+ def initialize(cmd_options,options)
17
+ @options = options
18
+ @command_options = cmd_options
19
+ @help = false
20
+ @agent = Agent.new
21
+
22
+ @summery = ""
23
+ @banner = ""
24
+ end
25
+
26
+ def help
27
+ opt = OptionParser.new
28
+ opt.parse!(@command_options)
29
+ @summery = "Show command helps."
30
+ @banner = "command"
31
+ return opt if @help
32
+ @help = true
33
+ command = @command_options.shift
34
+ raise "Unknown command: " + command unless COMMANDS.include?(command)
35
+ opt = send(command)
36
+ puts "Summery: #{@summery}"
37
+ opt.banner="Usage: unit-hosting [options] #{command} #{@banner}"
38
+ puts opt
39
+ end
40
+
41
+ def login
42
+ opt = OptionParser.new
43
+ opt.parse!(@command_options)
44
+ @summery = "Login to https://www.unit-hosting.com ."
45
+ @banner = ""
46
+ return opt if @help
47
+
48
+ user = ask('Enter user: ') do |q|
49
+ q.validate = /\w+/
50
+ end
51
+
52
+ ok = false
53
+ while(!ok)
54
+ password = ask("Enter your password: ") do |q|
55
+ q.validate = /\w+/
56
+ q.echo = false
57
+ end
58
+
59
+ @agent.login(user,password)
60
+ if @agent.login? # => OK
61
+ ok = true
62
+ Keystorage.set("unit-hosting",user,password)
63
+ puts "login OK"
64
+ else
65
+ puts "password mismatch"
66
+ end
67
+ end
68
+ end
69
+
70
+ def logout
71
+ opt = OptionParser.new
72
+ opt.parse!(@command_options)
73
+ @summery = "Logout from https://www.unit-hosting.com ."
74
+ @banner = ""
75
+ return opt if @help
76
+ Keystorage.delete("bookscan")
77
+ end
78
+
79
+
80
+ def update
81
+ start
82
+ groups = @agent.groups
83
+ end
84
+
85
+ private
86
+ def start
87
+ return true if @agent.login?
88
+ user = Keystorage.list("unit-hosting").shift
89
+ login unless user
90
+ if user
91
+ @agent.login(user,Keystorage.get("unit-hosting",user))
92
+ login unless @agent.login?
93
+ end
94
+ end
95
+
96
+ end
97
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'unit-hosting'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestUnitHosting < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unit-hosting
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Yoshihiro TAKAHARA
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-20 00:00:00 +09:00
19
+ default_executable: unit-hosting
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ name: shoulda
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ prerelease: false
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :development
37
+ name: bundler
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ prerelease: false
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ name: jeweler
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ prerelease: false
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ name: rcov
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ prerelease: false
80
+ requirement: *id004
81
+ description: This is a command to manage virtual servers on UnitHosting(http://www.unit-hosting.com).
82
+ email: y.takahara@gmail.com
83
+ executables:
84
+ - unit-hosting
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - bin/unit-hosting
97
+ - lib/unit-hosting.rb
98
+ - lib/unit-hosting/agent.rb
99
+ - lib/unit-hosting/cli.rb
100
+ - lib/unit-hosting/commands.rb
101
+ - test/helper.rb
102
+ - test/test_unit-hosting.rb
103
+ has_rdoc: true
104
+ homepage: http://github.com/tumf/unit-hosting
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirements: []
131
+
132
+ rubyforge_project:
133
+ rubygems_version: 1.4.2
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: unit-hosting command line tool
137
+ test_files:
138
+ - test/helper.rb
139
+ - test/test_unit-hosting.rb