marhan_cli 0.0.13 → 0.0.15

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.
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ module MarhanCli
4
+ class Bash
5
+
6
+ def ssh_command(param)
7
+ raise ArgumentError, "user has to be set" unless param[:user]
8
+ raise ArgumentError, "host has to be set" unless param[:host]
9
+ param[:port] ||= "22"
10
+ return "ssh #{param[:host]} -l #{param[:user]} -p #{param[:port]}"
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module MarhanCli
4
+ class Jenkins
5
+
6
+ def initialize
7
+ @config_file = "/Library/LaunchDaemons/org.jenkins-ci.plist"
8
+ end
9
+
10
+ def start_command
11
+ "sudo launchctl load #@config_file"
12
+ end
13
+
14
+ def stop_command
15
+ "sudo launchctl unload #@config_file"
16
+ end
17
+
18
+ end
19
+ end
@@ -8,28 +8,38 @@ module MarhanCli
8
8
 
9
9
  attr_reader :guests
10
10
 
11
- def initialize(guests)
12
- @guests = guests
11
+ def initialize(config)
12
+ @guests = config.guests
13
13
  end
14
14
 
15
- def start_guest(guest_config_name)
16
- "VBoxManage startvm '#{vbox_name(guest_config_name)}'"
15
+ def guest_start_command(guest_name)
16
+ "VBoxManage startvm '#{vbox_name(guest_name)}'"
17
17
  end
18
18
 
19
- def stop_guest(guest_config_name)
20
- "VBoxManage controlvm '#{vbox_name(guest_config_name)}' acpipowerbutton"
19
+ def guest_stop_command(guest_name)
20
+ "VBoxManage controlvm '#{vbox_name(guest_name)}' acpipowerbutton"
21
21
  end
22
22
 
23
- def guest_ssh_server_up?(guest_config_name)
24
- remote_machine = RemoteMachine.new(@guests[guest_config_name].ssh.host, @guests[guest_config_name].ssh.port)
25
- remote_machine.ssh_server_running?(@guests[guest_config_name].ssh.user)
23
+ def guest_ssh_server_up?(guest_name)
24
+ remote_machine = RemoteMachine.new(@guests[guest_name].ssh.host, @guests[guest_name].ssh.port)
25
+ remote_machine.ssh_server_running?(@guests[guest_name].ssh.user)
26
26
  end
27
27
 
28
- def vbox_name(guest_config_name)
29
- Constraint.not_nil_or_empty! guest_config_name, "Guest config name have to be set!"
30
- Constraint.not_nil_or_empty! @guests[guest_config_name], "No guest with key '#{guest_config_name}' found in configuration!"
31
- Constraint.not_nil_or_empty! @guests[guest_config_name].name, "Guest name is not configured!"
32
- @guests[guest_config_name].name
28
+ def ssh_connection_configured?(guest_name)
29
+ @guests[guest_name].key?(:ssh)
30
+ end
31
+
32
+ def guest_ssh_command(guest_name)
33
+ bash = MarhanCli::Bash.new
34
+ raise ArgumentError, "No ssh configuration found for #{guest_name}" unless guests[guest_name].ssh?
35
+ bash.ssh_command(guests[guest_name].ssh)
36
+ end
37
+
38
+ def vbox_name(guest_name)
39
+ Constraint.not_nil_or_empty! guest_name, "Guest config name have to be set!"
40
+ Constraint.not_nil_or_empty! @guests[guest_name], "No guest with key '#{guest_name}' found in configuration!"
41
+ Constraint.not_nil_or_empty! @guests[guest_name].name, "Guest name is not configured!"
42
+ @guests[guest_name].name
33
43
  end
34
44
  end
35
45
  end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'marhan_cli/command'
3
+ require 'marhan_cli/apps/jenkins'
4
+
5
+ module MarhanCli
6
+ class ServiceCommand < MarhanCli::Command
7
+
8
+ namespace :serv
9
+
10
+ desc "serv:start", "Starts daemon service"
11
+
12
+ method_option :service,
13
+ :type => :string,
14
+ :aliases => "-s",
15
+ :desc => "Name of service in configuration file."
16
+
17
+ def start
18
+ execute start_service
19
+ end
20
+
21
+
22
+ desc "serv:stop", "Stops daemon service"
23
+
24
+ method_option :service,
25
+ :type => :string,
26
+ :aliases => "-s",
27
+ :desc => "Name of service in configuration file."
28
+
29
+ def stop
30
+ execute stop_service
31
+ end
32
+
33
+ private
34
+
35
+ def start_service
36
+ Proc.new do
37
+ run Jenkins.new.start_command
38
+ end
39
+ end
40
+
41
+ def stop_service
42
+ Proc.new do
43
+ run Jenkins.new.stop_command
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'marhan_cli/command'
3
3
  require 'marhan_cli/apps/virtual_box'
4
+ require 'marhan_cli/apps/bash'
4
5
 
5
6
  module MarhanCli
6
7
  class VBoxCommand < MarhanCli::Command
@@ -31,24 +32,20 @@ module MarhanCli
31
32
 
32
33
  private
33
34
 
34
- def start_ssh_client
35
-
36
- end
37
-
38
35
  def start_guest
39
36
  Proc.new do
40
37
  vbox_config = load_vbox_config
41
- virtual_box = VirtualBox.new(vbox_config.guests)
42
- guest_to_start = get_or_ask(:guest)
43
- run virtual_box.start_guest(guest_to_start)
38
+ virtual_box = VirtualBox.new(vbox_config)
39
+ guest_name = get_or_ask(:guest)
40
+ run virtual_box.guest_start_command(guest_name)
44
41
 
45
- if vbox_config.guests[guest_to_start].key?(:ssh)
42
+ if virtual_box.ssh_connection_configured?(guest_name)
46
43
  say ""
47
44
  say "Waiting for response from SSH server...", :green
48
- if virtual_box.guest_ssh_server_up?(guest_to_start)
45
+ if virtual_box.guest_ssh_server_up?(guest_name)
49
46
  say "SSH server is up. Trying to connect...", :green
50
47
  say ""
51
- run "ssh -p 2222 localhost"
48
+ run virtual_box.guest_ssh_command(guest_name)
52
49
  end
53
50
  end
54
51
  end
@@ -58,8 +55,8 @@ module MarhanCli
58
55
  Proc.new do
59
56
  config = load_vbox_config
60
57
  guest_name = get_or_ask(:guest)
61
- virtual_box = VirtualBox.new(config.guests)
62
- run virtual_box.stop_guest(guest_name)
58
+ virtual_box = VirtualBox.new(config)
59
+ run virtual_box.guest_stop_command(guest_name)
63
60
  end
64
61
  end
65
62
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module MarhanCli
3
- VERSION = "0.0.13"
3
+ VERSION = "0.0.15"
4
4
  end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'marhan_cli/apps/bash'
4
+
5
+ describe "bash" do
6
+
7
+ context ".new" do
8
+ it "creates new instance" do
9
+ MarhanCli::Bash.new.should be_a(MarhanCli::Bash)
10
+ end
11
+ end
12
+
13
+ context ".ssh_command" do
14
+
15
+ let(:subject) { MarhanCli::Bash.new }
16
+ let(:params) { {:user => "any_user", :password => "any_password", :host => "any_host"} }
17
+
18
+ describe "with valid params" do
19
+
20
+ it "returns ssh command string for user, password and host" do
21
+ subject.ssh_command(params).should eq("ssh any_host -l any_user -p 22")
22
+ end
23
+
24
+ it "returns ssh command string for user, password, host and port" do
25
+ subject.ssh_command(params.merge({:port => "2222"})).should eq("ssh any_host -l any_user -p 2222")
26
+ end
27
+
28
+ end
29
+
30
+ describe "raises error" do
31
+
32
+ it "if user not set" do
33
+ expect {
34
+ subject.ssh_command(params.merge({:user => nil}))
35
+ }.to raise_error(error=ArgumentError, message="user has to be set")
36
+ end
37
+
38
+ it "if host not set" do
39
+ expect {
40
+ subject.ssh_command(params.merge({:host => nil}))
41
+ }.to raise_error(error=ArgumentError, message="host has to be set")
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'marhan_cli/apps/jenkins'
4
+
5
+ describe "Jenkins" do
6
+
7
+ let(:subject) { MarhanCli::Jenkins.new }
8
+
9
+ context ".new" do
10
+ it "creates a new instance of Jenkins" do
11
+ subject.should be_a(MarhanCli::Jenkins)
12
+ end
13
+ end
14
+
15
+ context ".start_command" do
16
+
17
+ it "returns command string" do
18
+ subject.start_command.should eq("sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist")
19
+ end
20
+ end
21
+
22
+ context ".stop_command" do
23
+
24
+ it "returns command string" do
25
+ subject.stop_command.should eq("sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist")
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  require 'marhan_cli/apps/virtual_box'
4
4
  require 'marhan_cli/config'
5
5
 
6
- describe "VirtualBoxApp" do
6
+ describe MarhanCli::VirtualBox do
7
7
 
8
8
  let(:config_param) { MarhanCli::Config.init(
9
- File.join("spec", "unit", "fixtures", "config.yml")).vbox.guests }
9
+ File.join("spec", "unit", "fixtures", "config.yml")).vbox }
10
10
 
11
11
  let(:subject) { MarhanCli::VirtualBox.new(config_param) }
12
12
 
@@ -19,15 +19,15 @@ describe "VirtualBoxApp" do
19
19
 
20
20
  describe "with config hash as argument" do
21
21
  it "has set config hash" do
22
- subject.guests.should eq(config_param)
22
+ subject.guests.should eq(config_param.guests)
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
- context ".start_guest" do
27
+ context ".guest_start_command" do
28
28
  describe "with configured guest as argument" do
29
29
  it "returns correct command" do
30
- subject.start_guest('linux').should eq("VBoxManage startvm 'Ubuntu Linux'")
30
+ subject.guest_start_command('linux').should eq("VBoxManage startvm 'Ubuntu Linux'")
31
31
  end
32
32
  end
33
33
 
@@ -61,11 +61,45 @@ describe "VirtualBoxApp" do
61
61
  end
62
62
  end
63
63
 
64
- context ".stop_guest" do
64
+ context ".guest_stop_command" do
65
65
  describe "with configured guest as argument" do
66
66
  it "returns correct command" do
67
- subject.stop_guest('linux').should eq("VBoxManage controlvm 'Ubuntu Linux' acpipowerbutton")
67
+ subject.guest_stop_command('linux').should eq("VBoxManage controlvm 'Ubuntu Linux' acpipowerbutton")
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ context ".ssh_connection_configured?" do
73
+ describe "if ssh connection is configured" do
74
+ it "returns 'true'" do
75
+ subject.ssh_connection_configured?('linux').should be(true)
76
+ end
77
+ end
78
+
79
+ describe "if ssh connection is not configured" do
80
+ it "returns 'false'" do
81
+ subject.ssh_connection_configured?('windows').should be(false)
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ context ".guest_ssh_command" do
88
+
89
+ describe "with existing ssh configuration" do
90
+ it "returns ssh connection command" do
91
+ subject.guest_ssh_command('linux').should eq("ssh localhost -l nameofuser -p 2222")
92
+ end
93
+ end
94
+
95
+ describe "without any ssh configuration " do
96
+ it "raise error" do
97
+ expect {
98
+ subject.guest_ssh_command('windows')
99
+ }.to raise_error(error=ArgumentError, message="No ssh configuration found for windows")
100
+ end
101
+ end
102
+
103
+ end
104
+
71
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marhan_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
12
+ date: 2012-12-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -141,10 +141,13 @@ files:
141
141
  - Rakefile
142
142
  - bin/mcli
143
143
  - lib/marhan_cli.rb
144
+ - lib/marhan_cli/apps/bash.rb
145
+ - lib/marhan_cli/apps/jenkins.rb
144
146
  - lib/marhan_cli/apps/true_crypt.rb
145
147
  - lib/marhan_cli/apps/virtual_box.rb
146
148
  - lib/marhan_cli/command.rb
147
149
  - lib/marhan_cli/commands/network_command.rb
150
+ - lib/marhan_cli/commands/service_command.rb
148
151
  - lib/marhan_cli/commands/true_crypt_command.rb
149
152
  - lib/marhan_cli/commands/vbox_command.rb
150
153
  - lib/marhan_cli/commands/web_command.rb
@@ -157,6 +160,8 @@ files:
157
160
  - spec/integration/marhan_cli/apps/virtual_box_scene.rb
158
161
  - spec/spec_helper.rb
159
162
  - spec/unit/fixtures/config.yml
163
+ - spec/unit/lib/marhan_cli/apps/bash_spec.rb
164
+ - spec/unit/lib/marhan_cli/apps/jenkins_spec.rb
160
165
  - spec/unit/lib/marhan_cli/apps/virtual_box_spec.rb
161
166
  - spec/unit/lib/marhan_cli/config_spec.rb
162
167
  - spec/unit/lib/marhan_cli/helper/constraint_spec.rb
@@ -188,6 +193,8 @@ test_files:
188
193
  - spec/integration/marhan_cli/apps/virtual_box_scene.rb
189
194
  - spec/spec_helper.rb
190
195
  - spec/unit/fixtures/config.yml
196
+ - spec/unit/lib/marhan_cli/apps/bash_spec.rb
197
+ - spec/unit/lib/marhan_cli/apps/jenkins_spec.rb
191
198
  - spec/unit/lib/marhan_cli/apps/virtual_box_spec.rb
192
199
  - spec/unit/lib/marhan_cli/config_spec.rb
193
200
  - spec/unit/lib/marhan_cli/helper/constraint_spec.rb