virtualmaster 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- virtualmaster (0.1.0)
4
+ virtualmaster (0.1.1)
5
5
  commander (~> 4.1.2)
6
6
  deltacloud-client (~> 0.5.0)
7
7
  net-ssh (~> 2.3.0)
@@ -55,6 +55,14 @@ Virtualmaster CLI can install your SSH keys to a remote machine automatically us
55
55
 
56
56
  Try to login using `ssh root@195.140.253.130'
57
57
 
58
+ ## Instance provisioning with shell scripts
59
+
60
+ First steps towards automated infrastructure is provision. Using Virtualmaster CLI shell provisioner you can launch a custom shell script once server is created and automate initial setup.
61
+
62
+ virtualmaster create demo1 --script ~/setup.sh
63
+
64
+ Callbacks (like script and identity) can be run at the same time.
65
+
58
66
  ## Instance size
59
67
 
60
68
  Default hardware profile for instances are defined in the [helpers file](https://github.com/Virtualmaster/virtualmaster-cli/blob/master/lib/vmaster/helpers.rb). Profiles are stored in configuration file when user runs `virtualmaster config`.
@@ -0,0 +1,50 @@
1
+ #
2
+ # Shell Provisioner
3
+ #
4
+
5
+ def copy_file(session, file, destination)
6
+ session.open_channel do |channel|
7
+ channel.exec("cat > #{destination}") do |channel, success|
8
+ channel.on_data do |ch,data|
9
+ puts data
10
+ end
11
+
12
+ open(file) { |f| channel.send_data(f.read) }
13
+ channel.eof!
14
+ end
15
+ end
16
+ session.loop
17
+ end
18
+
19
+ def run_command(session, command)
20
+ session.open_channel do |channel|
21
+ channel.on_data do |ch,data|
22
+ puts data
23
+ end
24
+
25
+ channel.exec command
26
+ end
27
+ session.loop
28
+ end
29
+
30
+ callback :shell_provisioner do
31
+ option :script, String, 'Setup virtual machine using provided script'
32
+
33
+ before :create do |options|
34
+ abort "Shell script doesn't exist (#{options[:script]})" unless File.exists?(options[:script])
35
+ end
36
+
37
+ after :create do |options, server|
38
+ script = open(options[:script]) { |f| f.readlines}
39
+
40
+ Net::SSH.start(server.public_addresses.first[:address], 'root', :password => options[:password]) do |ssh|
41
+ destination_path = "/tmp/shell_provisioner.sh"
42
+
43
+ copy_file(ssh, options[:script], "/tmp/shell_provisioner.sh")
44
+ puts
45
+
46
+ say "***** running shell provisioner ******"
47
+ run_command(ssh, "sh /tmp/shell_provisioner.sh")
48
+ end
49
+ end
50
+ end
@@ -29,8 +29,7 @@ callback :ssh_copy_id do
29
29
 
30
30
  Net::SSH.start(server.public_addresses.first[:address], 'root', :password => options[:password]) do |ssh|
31
31
  # TODO exception handling
32
- output = ssh.exec!("mkdir ~/.ssh")
33
- output = ssh.exec!("echo '#{authorized_key}' >>~/.ssh/authorized_keys")
32
+ output = ssh.exec!("umask 077 && test -d ~/.ssh || mkdir ~/.ssh && echo '#{authorized_key}' >>~/.ssh/authorized_keys")
34
33
  end
35
34
  end
36
35
  end
@@ -64,7 +64,7 @@ module VirtualMaster
64
64
  def self.create_instance(name, image_id, profile, realm)
65
65
  api = VirtualMaster::CLI.api
66
66
 
67
- api.create_instance(image_id, {:name => name, :memory => profile[:memory], :storage => profile[:storage], :realm_id => realm})
67
+ api.create_instance(image_id, {:name => name, :hwp_id => 'default', :memory => profile[:memory], :storage => profile[:storage], :realm_id => realm})
68
68
  end
69
69
  end
70
70
  end
@@ -78,7 +78,7 @@ command :create do |c|
78
78
 
79
79
  realm = "#{options.zone}-#{options.level}"
80
80
 
81
- instance = VirtualMaster::Helpers.create_instance(name, image_id, profile, realm) if options.interactive
81
+ instance = VirtualMaster::Helpers.create_instance(name, image_id, profile, realm)
82
82
 
83
83
  # TODO handle exceptions (invalid image/profile, limits, etc.)
84
84
 
@@ -1,3 +1,7 @@
1
1
  module VirtualMaster
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
+
4
+ def self.cli_spec_version
5
+ VERSION.to_f.to_s
6
+ end
3
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtualmaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: commander
16
- requirement: &70352789585640 !ruby/object:Gem::Requirement
16
+ requirement: &70157779658640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.1.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70352789585640
24
+ version_requirements: *70157779658640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: deltacloud-client
27
- requirement: &70352789585100 !ruby/object:Gem::Requirement
27
+ requirement: &70157779658140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70352789585100
35
+ version_requirements: *70157779658140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: terminal-table
38
- requirement: &70352789584620 !ruby/object:Gem::Requirement
38
+ requirement: &70157779657680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.4.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70352789584620
46
+ version_requirements: *70157779657680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: net-ssh
49
- requirement: &70352789583960 !ruby/object:Gem::Requirement
49
+ requirement: &70157779656940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.3.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70352789583960
57
+ version_requirements: *70157779656940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70352789583320 !ruby/object:Gem::Requirement
60
+ requirement: &70157779656260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '2'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70352789583320
68
+ version_requirements: *70157779656260
69
69
  description: Command line interface to Virtualmaster. Control your virtual infrastructure.
70
70
  email:
71
71
  - radim@laststation.net
@@ -83,6 +83,7 @@ files:
83
83
  - lib/vmaster.rb
84
84
  - lib/vmaster/callbacks.rb
85
85
  - lib/vmaster/callbacks/demo_callback.rb
86
+ - lib/vmaster/callbacks/shell_provisioner.rb
86
87
  - lib/vmaster/callbacks/ssh_keys_callback.rb
87
88
  - lib/vmaster/cli.rb
88
89
  - lib/vmaster/config_command.rb