vmtools 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/NOTICE +15 -0
- data/Rakefile +2 -0
- data/bin/vmtools +19 -0
- data/config/vmtconfig.rb +20 -0
- data/docs/CHANGELOG.md +44 -0
- data/docs/README.md +86 -0
- data/lib/vmtools/version.rb +20 -0
- data/lib/vmtools.rb +205 -0
- data/templates/Vagrantfile.erb +24 -0
- data/vmtools.gemspec +27 -0
- metadata +105 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/NOTICE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
vmtools - util for creating test VMs
|
2
|
+
|
3
|
+
Copyright 2012 Konstantin Lysenko
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
data/Rakefile
ADDED
data/bin/vmtools
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright 2012, Atalanta Systems LTD [yyyy] [name of copyright owner]
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require_relative '../lib/vmtools'
|
17
|
+
|
18
|
+
vm = VMTools::VM.new
|
19
|
+
vm.run
|
data/config/vmtconfig.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
current_dir = File.dirname(__FILE__)
|
2
|
+
current_orgname = "change_me"
|
3
|
+
fwd_ports = {"80" => "8080"}
|
4
|
+
|
5
|
+
# Chef stuff
|
6
|
+
orgname "#{current_orgname}"
|
7
|
+
knife_config "/add_a_path_to_org_knife_config_here_please/.chef/knife.rb"
|
8
|
+
|
9
|
+
## Common stuff
|
10
|
+
homedir "#{ENV['HOME']}"
|
11
|
+
testbox_name "testbox"
|
12
|
+
vm_type "vagrant"
|
13
|
+
|
14
|
+
# Vagrant stuff
|
15
|
+
vtemplate "Vagrantfile.erb"
|
16
|
+
vconfig "#{current_dir}/Vagrantfile"
|
17
|
+
vmemory "768"
|
18
|
+
vforward_ports fwd_ports
|
19
|
+
vbox_name "precise32"
|
20
|
+
vbox_url "http://files.vagrantup.com/precise32.box"
|
data/docs/CHANGELOG.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
|
3
|
+
* Create a wrapper for vmtools start
|
4
|
+
* Create a dir structure like: ./lib, ./bin and so on
|
5
|
+
* Move VMTools class to VM class and create VMTools module.
|
6
|
+
* Create a Gem for vmtools
|
7
|
+
* Make vmtools use default config and template if there're no oneincurrent dir
|
8
|
+
* Add Apache 2.0 license as vmtools license
|
9
|
+
|
10
|
+
## 0.1.0
|
11
|
+
|
12
|
+
* Write some documentation in README.md file, so now, you can get an idea,
|
13
|
+
what this vmtools doing my reading README.md file.
|
14
|
+
|
15
|
+
## 0.0.7
|
16
|
+
|
17
|
+
* Add vagrant options to config (like port redirects and so on stuff)
|
18
|
+
|
19
|
+
## 0.0.6
|
20
|
+
|
21
|
+
* Move VM type options (it's vagrant only now) to config
|
22
|
+
|
23
|
+
## 0.0.5
|
24
|
+
|
25
|
+
* Move options parsing in separate class/method.
|
26
|
+
It's make a script ready to spliting up on lib and run wrapper.
|
27
|
+
|
28
|
+
## 0.0.4
|
29
|
+
|
30
|
+
* Internal upgrade, replace Trollop to https://github.com/opscode/mixlib-cli.
|
31
|
+
Now it parse options a little faster.
|
32
|
+
|
33
|
+
## 0.0.3
|
34
|
+
|
35
|
+
* Create class for vmtools functionality, so it can be moved to lib later,
|
36
|
+
so we can have in bin only simple wrapper.
|
37
|
+
|
38
|
+
## 0.0.2
|
39
|
+
|
40
|
+
* Add config management with https://github.com/opscode/mixlib-config
|
41
|
+
|
42
|
+
## 0.0.1
|
43
|
+
|
44
|
+
* First working version
|
data/docs/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
vmtools is a tool for recreate test VMs.
|
4
|
+
|
5
|
+
It basically:
|
6
|
+
|
7
|
+
1. Create VM with vagrant.
|
8
|
+
2. Tring to start chef-client on this VM and add node to opscode hosted chef server.
|
9
|
+
|
10
|
+
vmtools have following parts:
|
11
|
+
|
12
|
+
* vmtools.rb util - executable file with code
|
13
|
+
* vmtconfig.rb - vmtools config with VM parameters. Default vmtconfig.rb populated to /usr/lib/ruby/gems/1.9.1/gems/vmtools-0.2.0/config/vmtconfig.rb dir. parameters from vmtconfig substitutes in Vagrantfile.erb template and generate resulting Vagrantfile.
|
14
|
+
* Vagrantfile.erb - erb template for Vagrantfile. Default Vagrantfile.erb is in the /usr/lib/ruby/gems/1.9.1/gems/vmtools-0.2.0/templates/Vagrantfile.erb dir
|
15
|
+
|
16
|
+
# Installation
|
17
|
+
|
18
|
+
gem install vmtools
|
19
|
+
|
20
|
+
# Usage
|
21
|
+
## Getting started
|
22
|
+
|
23
|
+
Steps to start using vmtools:
|
24
|
+
|
25
|
+
1. Install vmtools
|
26
|
+
|
27
|
+
gem install vmtools
|
28
|
+
|
29
|
+
2. Run vmtools and create VM:
|
30
|
+
|
31
|
+
vmtools.rb -c
|
32
|
+
|
33
|
+
## Configuration
|
34
|
+
|
35
|
+
* There is vmtconfig.rb and Vagrantfile.erb files with vmtools configuration settings.
|
36
|
+
* if there's no vmtconfig.rb and Vagrantfile.erb files in current dir, vmtools use vmtconfig.rb and Vagrantfile.erb files from these directories:
|
37
|
+
|
38
|
+
/usr/lib/ruby/gems/1.9.1/gems/vmtools-0.2.0/config/vmtconfig.rb
|
39
|
+
/usr/lib/ruby/gems/1.9.1/gems/vmtools-0.2.0/templates/Vagrantfile.erb.
|
40
|
+
|
41
|
+
* You can copy these files to current dir and change it according you needs.
|
42
|
+
* vmtools generate Vagrantfile from Vagrantfile.erb template. Usually it will be enough just to fill vmtconfig.rb, but if you want in resulting Vagrantfile something that vmtconfig.rb file didn't cover - please mend Vagrantfile.erb template.
|
43
|
+
* note that if you will not change configs - chef part of vmtools will not work.
|
44
|
+
|
45
|
+
## vmtools commands
|
46
|
+
vmtools have following commands:
|
47
|
+
|
48
|
+
* -c, --create Create new VM according to config file
|
49
|
+
* -d, --delete Delete VM according to config file
|
50
|
+
* -r, --recreate Delete current VM and then create new VM according to config file
|
51
|
+
* -v, --version Print version info
|
52
|
+
* -h, --help Show short help
|
53
|
+
|
54
|
+
# Versions
|
55
|
+
stable versions:
|
56
|
+
|
57
|
+
* 0.x - stable versions
|
58
|
+
* 0.x.x - bug fixes for stable version
|
59
|
+
|
60
|
+
development brench haven't versions.
|
61
|
+
|
62
|
+
# Contributing
|
63
|
+
|
64
|
+
1. Fork it
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
69
|
+
|
70
|
+
# License and Author
|
71
|
+
|
72
|
+
Author:: Lysenko Konstantin (<konstantin@atalanta-systems.com>)
|
73
|
+
|
74
|
+
Copyright:: 2012, Atalanta Systems LTD
|
75
|
+
|
76
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
77
|
+
you may not use this file except in compliance with the License.
|
78
|
+
You may obtain a copy of the License at
|
79
|
+
|
80
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
81
|
+
|
82
|
+
Unless required by applicable law or agreed to in writing, software
|
83
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
84
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
85
|
+
See the License for the specific language governing permissions and
|
86
|
+
limitations under the License.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2012, Atalanta Systems LTD
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
|
16
|
+
=end
|
17
|
+
|
18
|
+
module VMTools
|
19
|
+
VERSION = "0.2.0"
|
20
|
+
end
|
data/lib/vmtools.rb
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2012, Atalanta Systems LTD
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
|
16
|
+
=end
|
17
|
+
|
18
|
+
require "vmtools/version"
|
19
|
+
require 'vagrant'
|
20
|
+
require 'erb'
|
21
|
+
require 'mixlib/config'
|
22
|
+
require 'mixlib/cli'
|
23
|
+
|
24
|
+
module VMTools
|
25
|
+
class VMConfig
|
26
|
+
extend(Mixlib::Config)
|
27
|
+
configure do |c|
|
28
|
+
c[:orgname] = 'atalanta'
|
29
|
+
c[:knife_config] = '/home/jakshi/Dropbox/atalanta-systems/git-repos/atalanta-chef-repo/.chef/knife.rb'
|
30
|
+
c[:vtemplate] = 'Vagrantfile.erb'
|
31
|
+
c[:vconfig] = 'Vagranfile'
|
32
|
+
c[:homedir] = "#{ENV['HOME']}"
|
33
|
+
c[:testbox_name] = 'testbox'
|
34
|
+
c[:vm_type] = 'vagrant'
|
35
|
+
c[:vmemory] = "768"
|
36
|
+
c[:vforward_ports] = {}
|
37
|
+
c[:vbox_name] = "precise32"
|
38
|
+
c[:vbox_url] = "http://files.vagrantup.com/precise32.box"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class VMCLI
|
43
|
+
|
44
|
+
include Mixlib::CLI
|
45
|
+
|
46
|
+
option :create_vm,
|
47
|
+
:short => "-c",
|
48
|
+
:long => "--create",
|
49
|
+
:description => "Create new VM according to config file"
|
50
|
+
|
51
|
+
option :delete_vm,
|
52
|
+
:short => "-d",
|
53
|
+
:long => "--delete",
|
54
|
+
:description => "Delete VM according to config file"
|
55
|
+
|
56
|
+
option :recreate_vm,
|
57
|
+
:short => "-r",
|
58
|
+
:long => "--recreate",
|
59
|
+
:description => "Delete current VM and then create new VM according to config file"
|
60
|
+
|
61
|
+
option :version,
|
62
|
+
:short => "-v",
|
63
|
+
:long => "--version",
|
64
|
+
:description => "Print version info"
|
65
|
+
|
66
|
+
option :help,
|
67
|
+
:short => "-h",
|
68
|
+
:long => "--help",
|
69
|
+
:description => "Show this message",
|
70
|
+
:on => :tail,
|
71
|
+
:boolean => true,
|
72
|
+
:show_options => true,
|
73
|
+
:exit => 0
|
74
|
+
end
|
75
|
+
|
76
|
+
class VM
|
77
|
+
def get_binding # this is only a helper method to access the objects
|
78
|
+
# binding method
|
79
|
+
binding
|
80
|
+
end
|
81
|
+
def initialize
|
82
|
+
# Get vmtools gem path
|
83
|
+
spec = Gem::Specification.find_by_name("vmtools")
|
84
|
+
@gem_root = spec.gem_dir
|
85
|
+
# Read config.
|
86
|
+
# First searching for config in current dir and then in ruby gems dir
|
87
|
+
begin
|
88
|
+
VMConfig.from_file('vmtconfig.rb')
|
89
|
+
rescue Errno::ENOENT
|
90
|
+
puts "Warring: There's no vmtconfig.rb in current dir. Using default vmtconfig.rb"
|
91
|
+
VMConfig.from_file("#{@gem_root}/config/vmtconfig.rb")
|
92
|
+
end
|
93
|
+
|
94
|
+
# Now only vagrant type of VMs is supported.
|
95
|
+
if VMConfig.vm_type != 'vagrant'
|
96
|
+
puts "Well, this's embarassing, but only vagrant VMs are supported now"
|
97
|
+
puts "Your specified #{VMConfig.vm_type} VM in config."
|
98
|
+
exit(0)
|
99
|
+
end
|
100
|
+
# Assign class instance variables
|
101
|
+
## Chef stuff
|
102
|
+
@orgname = VMConfig.orgname
|
103
|
+
@knife_config = VMConfig.knife_config
|
104
|
+
|
105
|
+
## Common stuff
|
106
|
+
@testbox_name = VMConfig.testbox_name
|
107
|
+
|
108
|
+
## Vagrant stuff
|
109
|
+
@template = VMConfig.vtemplate
|
110
|
+
@vconfig = VMConfig.vconfig
|
111
|
+
@homedir = VMConfig.homedir
|
112
|
+
@vmemory = VMConfig.vmemory
|
113
|
+
@vforward_ports = VMConfig.vforward_ports
|
114
|
+
@vbox_name = VMConfig.vbox_name
|
115
|
+
@vbox_url = VMConfig.vbox_url
|
116
|
+
end
|
117
|
+
|
118
|
+
def run
|
119
|
+
# Proccess command line parameters
|
120
|
+
## If no arguments - then let's print help
|
121
|
+
if ARGV.empty?
|
122
|
+
puts "Well, this's embarassing, but you need to specify an option! Please read help:"
|
123
|
+
ARGV << "-h"
|
124
|
+
end
|
125
|
+
|
126
|
+
cli = VMCLI.new
|
127
|
+
banner = <<-eos
|
128
|
+
Vmtools is util for create/delete/recreate test VM
|
129
|
+
VM configuration stored in vmtconfig.rb file
|
130
|
+
|
131
|
+
Usage:
|
132
|
+
vmtools --create|--delete|--recreate
|
133
|
+
|
134
|
+
Options:
|
135
|
+
eos
|
136
|
+
cli.banner=banner
|
137
|
+
## Parse options
|
138
|
+
begin
|
139
|
+
cli.parse_options
|
140
|
+
rescue OptionParser::InvalidOption
|
141
|
+
# if we have wrong option, print help.
|
142
|
+
puts "Well, this's embarassing, but wrong option! Please read help:"
|
143
|
+
ARGV.clear << "-h"
|
144
|
+
retry
|
145
|
+
end
|
146
|
+
cli.config.each do |opt,value|
|
147
|
+
if value
|
148
|
+
case opt
|
149
|
+
when :create_vm
|
150
|
+
self.create
|
151
|
+
when :delete_vm
|
152
|
+
self.delete
|
153
|
+
when :recreate_vm
|
154
|
+
self.delete
|
155
|
+
self.create
|
156
|
+
when :version
|
157
|
+
puts "vmtools #{VMTools::VERSION} (c) 2012 Atalanta Systems"
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def create
|
164
|
+
# Read template content
|
165
|
+
# First searching for config in current dir and then in ruby gems dir
|
166
|
+
begin
|
167
|
+
template_content = IO.read(@vtemplate)
|
168
|
+
rescue Errno::ENOENT
|
169
|
+
puts "Warring: There's no Vagrantfile.erb in current dir. Using default Vagrantfile.erb"
|
170
|
+
template_content = IO.read("#{@gem_root}/templates/Vagrantfile.erb")
|
171
|
+
end
|
172
|
+
|
173
|
+
erb = ERB.new(template_content)
|
174
|
+
|
175
|
+
env = Vagrant::Environment.new
|
176
|
+
# Clean out old vagrant config before writing a new one
|
177
|
+
begin
|
178
|
+
File.delete(@vconfig)
|
179
|
+
rescue Errno::ENOENT
|
180
|
+
puts "Warring: There's no #{@vconfig} in this dir. Nothing to delete"
|
181
|
+
end
|
182
|
+
# Generate new config from erb template
|
183
|
+
IO.write(@vconfig,erb.result(self.get_binding))
|
184
|
+
env.cli("up")
|
185
|
+
end
|
186
|
+
|
187
|
+
def delete
|
188
|
+
# Delete chef client/node
|
189
|
+
ENV['ORGNAME'] = "#{@orgname}"
|
190
|
+
system("knife node delete #{@testbox} -c #{@knife_config} -y")
|
191
|
+
system("knife client delete #{@testbox} -c #{@knife_config} -y")
|
192
|
+
# Delete VM
|
193
|
+
env = Vagrant::Environment.new
|
194
|
+
begin
|
195
|
+
File.delete(@vconfig)
|
196
|
+
rescue Errno::ENOENT
|
197
|
+
puts "Warring: There's no #{@vconfig} in this dir. Nothing to delete"
|
198
|
+
end
|
199
|
+
env.cli("destroy","--force")
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
# Module end
|
205
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant::Config.run do |config|
|
5
|
+
|
6
|
+
config.vm.box_url = "<%= @vbox_url %>"
|
7
|
+
config.vm.box = "<%= @vbox_name %>"
|
8
|
+
config.vm.customize [
|
9
|
+
"modifyvm", :id,
|
10
|
+
"--name", "<%= @testbox_name %>",
|
11
|
+
"--memory", "<%= @vmemory %>"
|
12
|
+
]
|
13
|
+
<% @vforward_ports.each do |in_port,out_port| %>
|
14
|
+
config.vm.forward_port <%= in_port %>, <%= out_port %>
|
15
|
+
<% end %>
|
16
|
+
config.vm.provision :chef_client do |chef|
|
17
|
+
chef.chef_server_url = "https://api.opscode.com/organizations/<%= @orgname %>"
|
18
|
+
chef.validation_key_path = "<%= @homedir %>/.chef/<%= @orgname %>-validator.pem"
|
19
|
+
chef.validation_client_name = "<%= @orgname %>-validator"
|
20
|
+
chef.node_name = "<%= @testbox_name %>"
|
21
|
+
chef.provisioning_path = "/etc/chef"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/vmtools.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/vmtools/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Konstantin Lysenko"]
|
6
|
+
gem.email = ["konstantin@atalanta-systems.com"]
|
7
|
+
gem.description = <<-EOF
|
8
|
+
Util that (re)create chef cookbook testboxes inside Virtualbox VMs.
|
9
|
+
It uses vagrant.
|
10
|
+
EOF
|
11
|
+
gem.summary = %q{(re)create virtualbox testboxes for testing chef cookbooks}
|
12
|
+
gem.license = 'Apache 2.0'
|
13
|
+
gem.licenses = ['Apache 2.0']
|
14
|
+
gem.homepage = ""
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.files.reject! { |fn| fn.include? "TODO.md" }
|
17
|
+
gem.files.reject! { |fn| fn.include? ".gitignore" }
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.name = "vmtools"
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
gem.version = VMTools::VERSION
|
23
|
+
gem.add_runtime_dependency "chef", ["~> 0.10.0"]
|
24
|
+
gem.add_runtime_dependency "vagrant", ["~> 1.0.0"]
|
25
|
+
gem.add_runtime_dependency "mixlib-cli", ["~> 1.2.0"]
|
26
|
+
gem.add_runtime_dependency "mixlib-config", ["~> 1.1.0"]
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vmtools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Konstantin Lysenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chef
|
16
|
+
requirement: &12533140 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12533140
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: vagrant
|
27
|
+
requirement: &12532620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12532620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mixlib-cli
|
38
|
+
requirement: &12532140 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *12532140
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mixlib-config
|
49
|
+
requirement: &12531660 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *12531660
|
58
|
+
description: ! " Util that (re)create chef cookbook testboxes inside Virtualbox VMs.\n
|
59
|
+
\ It uses vagrant.\n"
|
60
|
+
email:
|
61
|
+
- konstantin@atalanta-systems.com
|
62
|
+
executables:
|
63
|
+
- vmtools
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- NOTICE
|
70
|
+
- Rakefile
|
71
|
+
- bin/vmtools
|
72
|
+
- config/vmtconfig.rb
|
73
|
+
- docs/CHANGELOG.md
|
74
|
+
- docs/README.md
|
75
|
+
- lib/vmtools.rb
|
76
|
+
- lib/vmtools/version.rb
|
77
|
+
- templates/Vagrantfile.erb
|
78
|
+
- vmtools.gemspec
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- Apache 2.0
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.11
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: (re)create virtualbox testboxes for testing chef cookbooks
|
104
|
+
test_files: []
|
105
|
+
has_rdoc:
|