jupiter 0.0.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ config.yaml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in jupiter.gemspec
4
4
  gemspec
5
+
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Jupiter
2
2
 
3
- TODO: Write a gem description
3
+ Jupiter is designed to expedite the deployment of new virtual machines either by cloning an existing virtual machine, even if it is running, or by using a pre-built template. The goal was to allow developers to provision a new VM in only a few minutes without the need to bother system admins unnecessarily. Jupiter can also perform a few different virtual machine administration tasks documented below.
4
+
5
+ #### Limitations
6
+
7
+ Currently Jupiter is only tested on vSphere 5 using Ubuntu 12.04.2 LTS 64-bit virtual machines. That being said, most of the vSphere calls are via the VMware API or standard UNIX commands and should be consistent with later versions... in a perfect world that is. Also the VM templates have a few requirements to be fully functional with Jupiter. Namely a single LVM partitioning and a tweaking of the sudoers file documented in more detail below.
8
+
9
+ Also, even though Jupiter is destined to be a gem, it is currently controlled only via command-line options. Programatic control will be implimented in the future.
10
+
11
+ #### Document Conventions
12
+
13
+ The terms 'Host', 'vSphere' and 'ESXi' are used interchangeably in the document. All refer to the VMWare Host Server that is being managed.
14
+
15
+ The terms 'Guest', 'VM' and 'Virtual Machine' are all used to refer to the virtual machine that is running on the ESXi server.
4
16
 
5
17
  ## Installation
6
18
 
@@ -16,9 +28,315 @@ Or install it yourself as:
16
28
 
17
29
  $ gem install jupiter
18
30
 
19
- ## Usage
31
+ Or just pull down the git repository and use as a command-line application.
32
+
33
+ ## Configuration
34
+
35
+ The god Jupiter desires the following sacrifices to function properly:
36
+
37
+ 1. Root user access to the vSphere ESXi host server
38
+ 2. Adding an ssh key to the ESXi server so the templates can be scp'd over without a need to enter a password
39
+ 3. A common 'deploy' user on the VM templates with sudoer privileges and sudoer file entries (Jupiter can revoke the privileges when done setting up the new VM)
40
+
41
+ All the configuration information used by Jupiter is stored in the config.yaml file. It is broken up into four sections.
42
+
43
+ The vmusers section stores the deploy user who has sudoer privileges on the virtual machines.
44
+
45
+ ```yaml
46
+ :vmusers:
47
+ :deploy_user: deploy_users_name
48
+ :deploy_pass: deploy_users_pass
49
+ ```
50
+
51
+ The hosts section stores the vSphere server information. You can have as many servers listed here as you wish. The desired sever is selected when Jupiter is called via the --host= switch. We use the symbolic link path for vmpath instead of the crazy actual string created by the ESXi server.
52
+
53
+ ```yaml
54
+ :hosts:
55
+ -
56
+ :name: ESXi-SERVER01
57
+ :vmpath: /vmfs/volumes/VMDATA
58
+ :host: 192.168.100.100
59
+ :sshport: 22
60
+ :sshuser: root
61
+ :sshpass: roots_password
62
+ :dcname: ha-datacenter
63
+
64
+ -
65
+ :name: ESXi-SERVER02
66
+ :vmpath: /vmdata
67
+ :host: 192.168.100.209
68
+ :sshport: 2500
69
+ :sshuser: root
70
+ :sshpass: roots_password
71
+ :dcname: ha-datacenter
72
+ ```
73
+ The templates section listed where your pre-made template files will be stored and what user has privileges to transmit them to the ESXi server.
74
+
75
+ ```yaml
76
+ :templates:
77
+ :host: 192.168.100.23
78
+ :sshport: 2500
79
+ :sshuser: template_admin_user
80
+ :sshpass: template_admin_user_pass
81
+ :location: /vm_templates
82
+
83
+ ```
84
+
85
+ The Nagios section is needed if you wish to generate a Nagios configuration file for your virtual machine and upload it to the nagios server via Jupiter. This section can have null values if you wish to only generate the config and not upload it. The sshuser must have write privileges to the Nagios object location directory in order to successfully upload the config.
86
+
87
+ ```yaml
88
+ :nagios:
89
+ :host: 192.168.1.222
90
+ :sshport: 2500
91
+ :sshuser: franky
92
+ :sshpass: frankiespassword
93
+ :location: /usr/local/nagios/etc/objects
94
+ :url: http://192.168.1.222:8000/nagios/
95
+ ```
96
+
97
+ ## Template Virtual Machine
98
+
99
+ Templates are by far the quickest way to have a virtual machine up and running. However you must create the template first. The templates Jupiter was designed with are based on Ubuntu Server LTS 64-bit but Ubuntu's conventions are pretty consistant from version to version. (Although not tested yet, this is probably true for Debian also.) Here are the considerations when building your template:
100
+
101
+ #### Hardware Setup
102
+
103
+ The VMware hardware defaults seem to work just fine. The only considerations are ram and hardisk size. Ram can be whatever size you like but consider what is appropiate for the corresponding swap disk size. Hardisk sizes can be any size also because Jupiter can resize them for you once the VM is created. However, this fuctionality is only possible if you setup your partitioning using LVM as described below. For template deployment speed it is best to have a smaller initial hardisk. Ubuntu seems to want to have at least 2 GBs of diskspace to install a basic system, so a good starting HD size for the template would be 3 GBs. 1 GB for swap space and 2 GBs for the root partition.
104
+
105
+ #### HD Partitioning
106
+
107
+ TODO: Make this clearer by numbering steps (Review actual installation to make sure this is correct)
108
+
109
+ This is not meant as a definitive source for installation instructions. There are many reputable sources for information on installing Linux that you can review, so we will only touch on the specific needed for the Jupiter template VM.
110
+
111
+ Follow Ubuntu's installation steps until you get to the Partition disks step. Select Manual as the partition method.
112
+
113
+ Because we want to later resize the partition on the template, we need the swap partition to be first on the disk. This leaves any room we add to the drive after our LVM parition so that it can grow to fill the unused space. If a swap partition is at the end of the disk we have a roadblock.
114
+
115
+ Select 'sda' since we only created one disk. Create a new partition and set the size to 1GB or however big you want your swap space to be. Set it to 'Primary', 'Beginning' and format 'swap'.
116
+
117
+ Next, create another logical parition (it should be sda2). Then change "Use as" to "physical volume for LVM" then "Done setting up the partition". Now select "Configure the Logical Volume Manager" at the top, and choose "Yes" to write the changes to disk. Then use the LVM Configuration menu to setup first a 'Volume Group' then a 'Logical Volume'. Name them something short and simple like 'VolGrp1' and 'LogVol1'. Choose "Finish" and you should be back at the main "Partition Disks" screen.
118
+
119
+ Now add a filesystem to the new LVM. Select the partition under "LVM VG VolGrp1, LV LoVol1", or whatever name you have chosen. Setup a file system as ext4 selecting "/" as the mount point. Once done, select "Done setting up the partition".
120
+
121
+ #### Adding Deploy User
122
+
123
+ Ubuntu doesn't like people (or Jupiter) logging in as root, thus the vmusers entry in the config file above. So when building a virtual machine it is necessary to add the deploy user with sudo privileges. This can be done during the installation or afterwards. Please note that Jupiter has an option to revoke the deploy users sudoer privileges. Make sure you have at least one other user with sudoer powers before doing this.
124
+
125
+ #### Software
126
+
127
+ You may wish to have other software on your template but Jupiter only requires a functional OpenSSH server and vmware-tools. Installing only the base system and the OpenSSH server will keep your template small but vmware-tools is needed for many of Jupiter's features to work properly.
128
+
129
+ #### Post Install Template Configuration
130
+
131
+ We have a couple of tasks to perform on our template before sending it to our template server. First we need to log into our running template machine as our deploy user and edit out sudoer file.
132
+
133
+ To edit the sudoer file we use visudo.
134
+
135
+ ```bash
136
+ sudo visudo
137
+ ```
138
+
139
+ Then add the following line to the end of the file (Changing the deploy\_user\_name of course):
140
+
141
+ ```bash
142
+ deploy_user_name ALL = (root) NOPASSWD: /bin/hostname, /bin/chmod, /bin/echo, /bin/sed, /etc/init.d/hostname, /usr/bin/gpasswd, /sbin/fdisk, /sbin/pvs, /sbin/pvresize, /sbin/vgs, /sbin/lvextend, /sbin/resize2fs
143
+ ```
144
+
145
+ Now we shutdown our template VM and compress that baby into a tar file.
146
+
147
+ Once the template is shutdown log onto the host server it was created on and cd to its parent directory. Example:
148
+
149
+ ```bash
150
+ cd /vmfs/volumes/VMDATA/
151
+ ```
152
+
153
+ Once there list the directory and note your templates name.
154
+
155
+ ```bash
156
+ ls -lah
20
157
 
21
- TODO: Write usage instructions here
158
+ drwxr-xr-t 1 root root 1.6K Mar 26 10:39 .
159
+ drwxr-xr-x 1 root root 512 Mar 26 15:10 ..
160
+ -r-------- 1 root root 9.3M Dec 6 11:27 .fbb.sf
161
+ -r-------- 1 root root 254.7M Dec 6 11:27 .fdc.sf
162
+ -r-------- 1 root root 1.1M Dec 6 11:27 .pb2.sf
163
+ -r-------- 1 root root 256.0M Dec 6 11:27 .pbc.sf
164
+ -r-------- 1 root root 250.6M Dec 6 11:27 .sbc.sf
165
+ -r-------- 1 root root 4.0M Dec 6 11:27 .vh.sf
166
+ drwxr-xr-x 1 root root 2.1K Feb 28 15:58 Continuous-Deployment
167
+ drwxr-xr-x 1 root root 2.1K Mar 26 12:00 Puppet-Server
168
+ drwxr-xr-x 1 root root 1.4K Mar 22 15:30 Ubuntu64-Template
169
+ drwxr-xr-x 1 root root 2.3K Feb 7 15:07 Resque-Server
170
+ ```
171
+
172
+ In this example we called it 'Ubuntu64-Template'.
173
+
174
+ Now lets tar and gzip that bad boy up with the following 2 commands. Note this may take a few minutes to run.
175
+
176
+ ```bash
177
+ tar -cf Ubuntu64-Template.tar Ubuntu64-Template
178
+ gzip Ubuntu64-Template.tar
179
+ ```
180
+
181
+ Once this is done you will have a file called 'Ubuntu64-Template.tar.gz' which will act as your template. We will move this file over to your template server below. (Any machine with space and ssh access will do. Possibly even your local workstation.)
182
+
183
+ #### Template Server
184
+
185
+ The template server currently can be any system that has SSH access and SCP capabilities. Create a user that has permission to access a directory that will hold the template tar.gz files. We are going to grant this user password-less access to the ESXi (Host) server by adding a ssh key to the host. This is necessary because ESXi servers do not seem to have a functional SCP command.
186
+
187
+ Security Concerns: It is not ideal to setup password-less access to any *nix system but this seemed the easiest solution for the moment. Please make sure the Template server is a secured system and that the template user is not used for any other services on that system.
188
+
189
+ Log into the Template server as the user you have configured and run the following commands:
190
+
191
+ ```bash
192
+ # First lets create a password less ssh key for the template server user:
193
+ cd ~/.ssh
194
+ ssh-keygen -t rsa
195
+ # Do not enter any passphrase when asked so we can have password-less access.
196
+ # Now we will add our new key to the host server like this:
197
+ cat .ssh/id_rsa.pub | ssh root@192.168.100.100 "cat >> .ssh/authorized_keys"
198
+ # Where 192.168.100.100 is the IP of the host ESXi server. Enter the root users password
199
+ # when asked. Note that you will have to run the above cat command for every ESXi host
200
+ # server you wish to manage with Jupiter.
201
+ ```
202
+
203
+ The Template server will now have ssh root access to the Host server without a password.
204
+
205
+ Now to move the Ubuntu64-Template.tar.gz template we created above to the Template server:
206
+
207
+ ```bash
208
+ # Create the template directory that is referenced in the template section of the yaml file. Example:
209
+ mkdir /vm_templates
210
+ # Them download the tar.gz file from the Host:
211
+ scp root@192.168.100.100:/vmfs/volumes/VMDATA/Ubuntu64-Template.tar.gz /vm_templates/
212
+ # '192.168.100.100' being the IP of the Host server
213
+ # '/vmfs/volumes/VMDATA' being the vmpath
214
+ # 'Ubuntu64-Template.tar.gz' being the name of the template you created
215
+ # '/vm_templates/' being the template directory you created above
216
+ ```
217
+
218
+ After the file is done downloading it is safe to remove from the ESXi server but not necessary. The first time Jupiter uses that template the file on the Host server will be removed anyway.
219
+
220
+ #### Notes on template file names
221
+ The template file name must match the template folder name and file names used in the vm. Jupiter changes the names as needed when deploying a new VM. Keep this in mind when backing up your compressed templates. They will not work properly until you change their name back to thier original name. Just renaming all the files the same name will not work because of the references to files used inside the VM image itself.
222
+
223
+ Example:
224
+
225
+ ```bash
226
+ Template-Franks-Awesome-VM.tar.gz
227
+ |
228
+ V
229
+ Folder: Template-Franks-Awesome-VM
230
+ |
231
+ V
232
+ Template-Franks-Awesome-VM-flat.vmdk
233
+ Template-Franks-Awesome-VM.nvram
234
+ Template-Franks-Awesome-VM.vmdk
235
+ Template-Franks-Awesome-VM.vmsd
236
+ Template-Franks-Awesome-VM.vmx
237
+ Template-Franks-Awesome-VM.vmxf
238
+ ```
239
+
240
+ If I rename this file to Template-Franks-Awesome-VM-Version2.tar.gz it will still show up in the usable template list but not function properly.
241
+
242
+ Stating the obvious... Best practice would be have a basic template file that has a properly configured LVM partition and keep using it to make more templates that are specialized. If one wanted to make a Nginx, MySQL template, one would use Jupiter to make a new virtual machine using the basic template, name it to something like "nginx-mysql-template" and then install nginx and mysql. Shutdown the new VM and tar/gzip that bad boy back into another template. Then upload it to the template server. Now both "basic-template.tar.gz" and "nginx-mysql-template.tar.gz" will be available as templates through Jupiter.
243
+
244
+ TODO: Finish instructions for Host and Template servers
245
+
246
+ ## BASIC USAGE
247
+ To run Jupiter from the command-line there are a number of options
248
+
249
+ ```bash
250
+ jupiter ip --guest=GUEST --host=HOST # Shows IP address for supplied VM
251
+ jupiter manage --host=HOST # Provision a new or manage an existing VM
252
+ jupiter register --guest=GUEST --host=HOST # Registers the named VM on this ESXi server
253
+ jupiter state --guest=GUEST --host=HOST # Shows power state for supplied VM
254
+ jupiter unregister --guest=GUEST --host=HOST # Unregisters VM from supplied ESXi server
255
+ ```
256
+
257
+ Most of the time you will use the 'manage' option and pass it the name of the entry for the desired ESXi server in the yaml config file.
258
+
259
+ Example:
260
+
261
+ ```bash
262
+ jupiter manage --host=ESX-SERVER77
263
+ ```
264
+
265
+ Jupiter will ask if you would like to create a new VM or work with an existing VM registered on this ESXi server.
266
+
267
+ ```bash
268
+ ################################################################################
269
+ ############################## WELCOME TO JUPITER ##############################
270
+ ################################################################################
271
+ ## We hope the god of sky and thunder will make your day most good and stuff. ##
272
+ ################################################################################
273
+
274
+ Would you like to create a new virtual machine or work with an existing one?
275
+
276
+ 1. Clone / Create a Virtual Machine
277
+ 2. Work with an existing Virtual Machine
278
+
279
+ Please select a number:
280
+ ```
281
+
282
+ Option 1 will give you a list of directories on the ESXi server in the VM images location path. (These VMs are not necessarily registered on the server.) You can choose to either clone one of these VMs or to create a new VM from a template.
283
+
284
+ ```bash
285
+ ################################################################################
286
+ ######### These are the currect virtual machines found on ESX-SERVER77 #########
287
+ ################################################################################
288
+
289
+ * Continuous-Deployment
290
+ * Puppet-Master
291
+ * nagios-openfire
292
+ * resque
293
+
294
+ ################################################################################
295
+ Would you like to clone one of these virtual machines or use a template?
296
+
297
+ 1. Clone Virtual Machine
298
+ 2. Use a Template
299
+
300
+ Please select a number:
301
+ ```
302
+
303
+ If you choose to clone a VM you will be asked to which one and what the new name for the VM should be. This process can take quite a while since large files are copied over during the cloning process. This will all depend on the size of the VM and speed of the server.
304
+
305
+ If you choose to create a VM from a template Jupiter will list the tar.gz files you have on your template server to choose from. Although this process is much faster than cloning, it still needs to copied the archived VM over to the server. You will also be prompted to enter a new name for the VM. Jupiter will take care of renaming all the appropriate files as needed.
306
+
307
+ Restrictions: When naming a new virtual machine please only use a valid file name format. (No spaces and no special characters with the exception of "-" and "_") Also please avoid using consecutive zeros in the name as these are also used in naming snapshot files.
308
+
309
+ Option 2 will ask you to select a virtual machine and then present you with a number of tasks that can be preformed on that VM.
310
+
311
+ ```bash
312
+ ################################################################################
313
+ ############### Please select a task to perform on XXXXXXXXXXXXX ###############
314
+ ################################################################################
315
+
316
+ 1. Change hostname
317
+ 2. Reboot (graceful restart)
318
+ 3. Shutdown (graceful stop)
319
+ 4. Cycle Power (non-graceful restart)
320
+ 5. Kill Power (non-graceful)
321
+ 6. Remove deploy user from sudoers
322
+ 7. Display current IP address of XXXXXXXXXXXXX
323
+ 8. Increase the alocated HD space for XXXXXXXXXXXXXX (VM must be off)
324
+ 9. Grow the LVM partition to fill the HD on XXXXXXXXXXXXXX
325
+ 10. Generate Nagios config file for XXXXXXXXXXXXXX
326
+ ```
327
+
328
+ Most of these options will only work if you have correctly built you VM as described above and have vmware-tools installed on the guest.
329
+
330
+ 1. Will change the hostname of the Linux VM by updating the name in the hosts and hostname files and restarting the hostname service.
331
+ 2. Will send a graceful reboot command via the vSphere API.
332
+ 3. Will send a graceful halt command via the vSphere API.
333
+ 4. Will kill the power (hard reset) via vSphere API and reboot the VM. (Used for frozen systems.)
334
+ 5. Will cut the power to the VM via the vSphere API.
335
+ 6. Removes all sudoer privileges for the deploy user in the yaml file. Only use this if you wish to no longer manage the VM with non API commands. (Resizing HD, Changing Hostname) Do not use this option if plan on cloning or using this VM as a template in the future.
336
+ 7. Shows IP address of VM via vSphere API.
337
+ 8. This option will resize the HD space allocated to the VM by the ESXi server. The VM must be off for this to function. This only increases the amount of space on the virtual harddisk. To access the new space you must either grow it using Jupiters 'Grow LVM Partition' option or use standard linux tools to allocate the space.
338
+ 9. Once the virtual hardisk has been made larger you can automatically grow the root LVM partition to fill all of the new space. This is only possible if you properly partitioned the VM as described in the template creation section above.
339
+ 10. Will display a valid Nagios config file for this VM or upload one to the Nagios server in the yaml file if desired.
22
340
 
23
341
  ## Contributing
24
342
 
@@ -27,3 +345,5 @@ TODO: Write usage instructions here
27
345
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
346
  4. Push to the branch (`git push origin my-new-feature`)
29
347
  5. Create new Pull Request
348
+
349
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path('../../lib', __FILE__))
4
+
5
+ require "jupiter"
6
+ Jupiter.configure
7
+ Jupiter::Cli.start
@@ -0,0 +1,37 @@
1
+ :vmusers:
2
+ :deploy_user: fred
3
+ :deploy_pass: freds-password
4
+
5
+ :hosts:
6
+ -
7
+ :name: ESX-SERVER101
8
+ :vmpath: /vmfs/volumes/VMDATA
9
+ :host: 192.168.1.101
10
+ :sshport: 22
11
+ :sshuser: root
12
+ :sshpass: roots-password
13
+ :dcname: ha-datacenter
14
+
15
+ -
16
+ :name: ESX-Server-X11
17
+ :vmpath: /tmp
18
+ :host: 192.168.1.222
19
+ :sshport: 2500
20
+ :sshuser: root
21
+ :sshpass: roots-password
22
+ :dcname: ha-datacenter
23
+
24
+ :templates:
25
+ :host: 192.168.1.210
26
+ :sshport: 2500
27
+ :sshuser: frank
28
+ :sshpass: franks-password
29
+ :location: /vm_templates
30
+
31
+ :nagios:
32
+ :host: 192.168.1.222
33
+ :sshport: 2500
34
+ :sshuser: franky
35
+ :sshpass: frankiespassword
36
+ :location: /usr/local/nagios/etc/objects
37
+ :url: http://192.168.1.222:8000/nagios/
@@ -16,4 +16,14 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ # gem.add_dependency 'sprinkle', '~> 0.4.2'
21
+ gem.add_dependency 'rbvmomi', '~> 1.6.0'
22
+ gem.add_dependency 'net-ssh', '~> 2.6.5'
23
+ gem.add_dependency 'net-scp', '~> 1.1.0'
24
+ gem.add_dependency 'thor', '~> 0.17.0'
25
+ gem.add_dependency 'pry', '~> 0.9.11.4'
26
+
27
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
19
28
  end
29
+
@@ -1,5 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require "jupiter/version"
4
+ require "rbvmomi"
5
+ require "yaml"
6
+ require "net/ssh"
7
+ require "net/scp"
8
+ require "pry"
9
+ require "thor"
10
+ require 'benchmark'
2
11
 
3
12
  module Jupiter
4
- # Your code goes here...
13
+ extend self
14
+ attr_accessor :configuration
15
+
16
+ def configure
17
+ self.configuration ||= Configuration.load_from_yaml!
18
+ end
19
+
20
+ def hosts
21
+ @hosts ||= configuration.hosts.map { |host| Host.new(host) }
22
+ end
23
+
24
+ def vmusers
25
+ @vmusers ||= configuration.vmusers
26
+ end
27
+
28
+ def templates
29
+ @templates ||= configuration.templates
30
+ end
31
+
32
+ def nagios
33
+ @nagios ||= configuration.nagios
34
+ end
35
+
36
+ def host_by_name(name)
37
+ Jupiter.hosts.find { |esxhost| esxhost.name == name }
38
+ end
5
39
  end
40
+
41
+ require "jupiter/configuration"
42
+ require "jupiter/host"
43
+ require "jupiter/virtualmachine"
44
+ require "jupiter/cli"
45
+ require "jupiter/uuid"
46
+ require "jupiter/template"
47
+ require "jupiter/cli/colorizer"
48
+ require "jupiter/cli/output"
49
+ require "jupiter/nagios"