vagrant-group 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +87 -19
- data/lib/vagrant-group/command.rb +68 -21
- data/lib/vagrant-group/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12d6231dc315ba52c0e2f07ad0a0eaccd63101e
|
4
|
+
data.tar.gz: 8dc59ae99e730295f0b4357764d68f1fd382e52f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d63f1fefa01536aeb55e274909ba006184dd3b76a642652f306627e6359fa3db7049688e3476d387b2ff697f5defb2d438f096d375904c8c03c7a53427ab12
|
7
|
+
data.tar.gz: 45df86faca90dba6a310629b6963383d9a01f243d6398db4d6802436ddcce3e80f05cf2f00cf6f5123d239fff38ec8442e06b2850bef5a36b1ab9c658f807e47
|
data/README.md
CHANGED
@@ -2,18 +2,35 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/vagrant-group.svg)](http://badge.fury.io/rb/vagrant-group)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
This plugin makes your life easier when it comes to maintain big development environments based on Vagrant.
|
6
|
+
You can associate each VM to multiple groups, e.g. based on role (webserver, database) or project they belong to.
|
7
|
+
Then with one simple command you can run basic commands on entire group.
|
8
|
+
|
9
|
+
For big configuration you may be also interested in [vagrant-dotvm plugin](https://github.com/krzysztof-magosa/vagrant-dotvm).
|
8
10
|
|
9
11
|
## How to install
|
10
12
|
|
11
13
|
```sh
|
12
|
-
vagrant plugin install vagrant-group
|
14
|
+
$ vagrant plugin install vagrant-group
|
13
15
|
```
|
14
16
|
|
15
17
|
## How to configure
|
16
18
|
|
19
|
+
You need to add definition of groups to your existing `Vagrantfile`:
|
20
|
+
```ruby
|
21
|
+
config.group.groups = {
|
22
|
+
"group-name-1" => [
|
23
|
+
"vm-1",
|
24
|
+
"vm-2",
|
25
|
+
],
|
26
|
+
"group-name-2" => [
|
27
|
+
"vm-3",
|
28
|
+
"vm-4",
|
29
|
+
],
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
For example it may look like that:
|
17
34
|
```ruby
|
18
35
|
Vagrant.configure("2") do |config|
|
19
36
|
config.vm.define "web1" do |web|
|
@@ -33,31 +50,82 @@ Vagrant.configure("2") do |config|
|
|
33
50
|
end
|
34
51
|
|
35
52
|
config.group.groups = {
|
36
|
-
"webservers" => [
|
37
|
-
|
53
|
+
"webservers" => [
|
54
|
+
"web1",
|
55
|
+
"web2",
|
56
|
+
],
|
57
|
+
"databases" => [
|
58
|
+
"db1",
|
59
|
+
"db2",
|
60
|
+
],
|
38
61
|
}
|
39
62
|
end
|
40
63
|
```
|
41
64
|
|
42
65
|
## How to use
|
43
66
|
|
44
|
-
|
45
|
-
|
46
|
-
$ vagrant group
|
67
|
+
If you forgot how to use `vagrant-group` just issue below command:
|
68
|
+
```
|
69
|
+
$ vagrant group
|
47
70
|
```
|
48
71
|
|
49
|
-
|
50
|
-
|
72
|
+
Start VMs:
|
73
|
+
```
|
74
|
+
$ vagrant group up <group-name>
|
75
|
+
```
|
51
76
|
|
52
|
-
|
77
|
+
Start VMs with forced provisioning:
|
53
78
|
```
|
54
|
-
$ vagrant group
|
79
|
+
$ vagrant group up <group-name> --provision
|
55
80
|
```
|
56
81
|
|
57
|
-
|
82
|
+
Shut down VMs:
|
83
|
+
```
|
84
|
+
$ vagrant group halt <group-name>
|
85
|
+
```
|
86
|
+
|
87
|
+
Forced shut down of VMs (equivalent of pulling power):
|
88
|
+
```
|
89
|
+
$ vagrant group halt <group-name> --force
|
90
|
+
```
|
91
|
+
|
92
|
+
Destroy VMs:
|
93
|
+
```
|
94
|
+
$ vagrant group destroy <group-name>
|
95
|
+
```
|
96
|
+
|
97
|
+
Destroy VMs without asking:
|
98
|
+
```
|
99
|
+
$ vagrant group destroy <group-name> --force
|
100
|
+
```
|
101
|
+
|
102
|
+
Provision VMs:
|
103
|
+
```
|
104
|
+
$ vagrant group provision <group-name>
|
105
|
+
```
|
106
|
+
|
107
|
+
Reload VMs:
|
108
|
+
```
|
109
|
+
$ vagrant group reload <group-name>
|
110
|
+
```
|
111
|
+
|
112
|
+
Reload VMs with forced provisioning:
|
113
|
+
```
|
114
|
+
$ vagrant group reload <group-name> --provision
|
115
|
+
```
|
116
|
+
|
117
|
+
Suspend VMs:
|
118
|
+
```
|
119
|
+
$ vagrant group suspend <group-name>
|
120
|
+
```
|
121
|
+
|
122
|
+
Resume suspended VMs:
|
123
|
+
```
|
124
|
+
$ vagrant group resume <group-name>
|
125
|
+
```
|
126
|
+
|
127
|
+
List hosts associated to specific group:
|
128
|
+
```
|
129
|
+
$ vagrant group hosts <group-name>
|
130
|
+
```
|
58
131
|
|
59
|
-
1. Fork it ( https://github.com/krzysztof-magosa/vagrant-group/fork )
|
60
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
-
5. Create a new Pull Request
|
@@ -7,7 +7,7 @@ module VagrantPlugins
|
|
7
7
|
def self.synopsis
|
8
8
|
"runs vagrant command on specific group of VMs"
|
9
9
|
end # self.synopsis
|
10
|
-
|
10
|
+
|
11
11
|
def execute
|
12
12
|
options = {
|
13
13
|
:provision_ignore_sentinel => false, # otherwise reload command does provision
|
@@ -18,6 +18,7 @@ module VagrantPlugins
|
|
18
18
|
|
19
19
|
o.on('-h', '--help', 'Print this help') do
|
20
20
|
safe_puts(opts.help)
|
21
|
+
return nil
|
21
22
|
end
|
22
23
|
|
23
24
|
o.on('-f', '--force', 'Do action (destroy, halt) without confirmation.') do
|
@@ -32,37 +33,83 @@ module VagrantPlugins
|
|
32
33
|
|
33
34
|
argv = parse_options(opts)
|
34
35
|
|
35
|
-
action,
|
36
|
+
action, pattern = argv[0], argv[1]
|
36
37
|
|
37
|
-
if !
|
38
|
+
if !pattern || !action || !COMMANDS.include?(action)
|
38
39
|
safe_puts(opts.help)
|
39
40
|
return nil
|
40
41
|
end
|
41
42
|
|
43
|
+
groups = find_groups(pattern)
|
44
|
+
if groups.length == 0
|
45
|
+
@env.ui.error('No groups matched the regular expression given.')
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
|
42
49
|
if action == 'hosts'
|
43
|
-
|
44
|
-
|
45
|
-
with_target_vms() do |machine|
|
46
|
-
if machine.config.group.groups.has_key?(group)
|
47
|
-
if machine.config.group.groups[group].to_a.include? machine.name.to_s
|
48
|
-
@env.ui.info(sprintf(' - %s', machine.name))
|
49
|
-
end
|
50
|
-
elsif
|
51
|
-
@env.ui.warn('No hosts associated.')
|
52
|
-
break
|
53
|
-
end
|
50
|
+
groups.each do |group|
|
51
|
+
print_hosts(group)
|
54
52
|
end
|
55
53
|
elsif
|
56
|
-
|
57
|
-
|
58
|
-
if machine.config.group.groups[group].include? machine.name.to_s
|
59
|
-
machine.action(action, **options)
|
60
|
-
end
|
61
|
-
end
|
54
|
+
groups.each do |group|
|
55
|
+
do_action(action, options, group)
|
62
56
|
end
|
63
57
|
end
|
64
58
|
end # execute
|
65
|
-
|
59
|
+
|
60
|
+
def print_hosts(group)
|
61
|
+
@env.ui.info(sprintf('Hosts in %s group:', group))
|
62
|
+
|
63
|
+
with_target_vms() do |machine|
|
64
|
+
if machine.config.group.groups.has_key?(group)
|
65
|
+
if machine.config.group.groups[group].to_a.include? machine.name.to_s
|
66
|
+
@env.ui.info(sprintf(' - %s', machine.name))
|
67
|
+
end
|
68
|
+
elsif
|
69
|
+
@env.ui.warn('No hosts associated.')
|
70
|
+
break
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end # print_hosts
|
74
|
+
|
75
|
+
def do_action(action, options, group)
|
76
|
+
with_target_vms() do |machine|
|
77
|
+
if machine.config.group.groups.has_key?(group)
|
78
|
+
if machine.config.group.groups[group].include? machine.name.to_s
|
79
|
+
machine.action(action, **options)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end # do_action
|
84
|
+
|
85
|
+
def all_groups
|
86
|
+
groups = Set.new
|
87
|
+
|
88
|
+
with_target_vms() do |machine|
|
89
|
+
machine.config.group.groups.to_h.each do |group_name, hosts|
|
90
|
+
groups << group_name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
return groups.to_a
|
95
|
+
end # all_groups
|
96
|
+
|
97
|
+
def find_groups(pattern)
|
98
|
+
groups = []
|
99
|
+
|
100
|
+
if pattern[0] == "/" && pattern[-1] == "/"
|
101
|
+
reg = Regexp.new(pattern[1..-2])
|
102
|
+
all_groups.each do |item|
|
103
|
+
groups << item if item.match(reg)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
all_groups.each do |item|
|
107
|
+
groups << item if item == pattern
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
groups
|
112
|
+
end # find_groups
|
66
113
|
end # Command
|
67
114
|
end # Group
|
68
115
|
end # VagrantPlugins
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Magosa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|