vagrant-cosmic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +8 -0
- data/Docker/.dockerignore +2 -0
- data/Docker/Dockerfile +48 -0
- data/Docker/Dockerfile.chefdk_0_17 +49 -0
- data/Docker/Dockerfile.latest_dependencies +49 -0
- data/Docker/README.md +95 -0
- data/Docker/vac.ps1 +29 -0
- data/Docker/vac.sh +30 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +187 -0
- data/LICENSE +8 -0
- data/README.md +409 -0
- data/Rakefile +106 -0
- data/build_rpm.sh +7 -0
- data/functional-tests/basic/Vagrantfile.basic_networking +34 -0
- data/functional-tests/basic/basic_spec.rb +15 -0
- data/functional-tests/networking/Vagrantfile.advanced_networking +106 -0
- data/functional-tests/networking/networking_spec.rb +14 -0
- data/functional-tests/rsync/Vagrantfile.advanced_networking +40 -0
- data/functional-tests/rsync/rsync_spec.rb +9 -0
- data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +64 -0
- data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +25 -0
- data/lib/vagrant-cosmic/action/connect_cosmic.rb +47 -0
- data/lib/vagrant-cosmic/action/is_created.rb +18 -0
- data/lib/vagrant-cosmic/action/is_stopped.rb +18 -0
- data/lib/vagrant-cosmic/action/message_already_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_not_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-cosmic/action/read_rdp_info.rb +42 -0
- data/lib/vagrant-cosmic/action/read_ssh_info.rb +70 -0
- data/lib/vagrant-cosmic/action/read_state.rb +38 -0
- data/lib/vagrant-cosmic/action/read_transport_info.rb +59 -0
- data/lib/vagrant-cosmic/action/read_winrm_info.rb +69 -0
- data/lib/vagrant-cosmic/action/run_instance.rb +819 -0
- data/lib/vagrant-cosmic/action/start_instance.rb +81 -0
- data/lib/vagrant-cosmic/action/stop_instance.rb +28 -0
- data/lib/vagrant-cosmic/action/terminate_instance.rb +208 -0
- data/lib/vagrant-cosmic/action/timed_provision.rb +21 -0
- data/lib/vagrant-cosmic/action/wait_for_state.rb +41 -0
- data/lib/vagrant-cosmic/action/warn_networks.rb +19 -0
- data/lib/vagrant-cosmic/action.rb +210 -0
- data/lib/vagrant-cosmic/capabilities/rdp.rb +12 -0
- data/lib/vagrant-cosmic/capabilities/winrm.rb +12 -0
- data/lib/vagrant-cosmic/config.rb +422 -0
- data/lib/vagrant-cosmic/errors.rb +27 -0
- data/lib/vagrant-cosmic/exceptions/exceptions.rb +15 -0
- data/lib/vagrant-cosmic/model/cosmic_resource.rb +51 -0
- data/lib/vagrant-cosmic/plugin.rb +82 -0
- data/lib/vagrant-cosmic/provider.rb +58 -0
- data/lib/vagrant-cosmic/service/cosmic_resource_service.rb +76 -0
- data/lib/vagrant-cosmic/util/timer.rb +17 -0
- data/lib/vagrant-cosmic/version.rb +5 -0
- data/lib/vagrant-cosmic.rb +17 -0
- data/locales/en.yml +131 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/vagrant-cosmic/action/read_ssh_info_spec.rb +80 -0
- data/spec/vagrant-cosmic/action/retrieve_public_ip_port_spec.rb +94 -0
- data/spec/vagrant-cosmic/action/run_instance_spec.rb +573 -0
- data/spec/vagrant-cosmic/action/terminate_instance_spec.rb +207 -0
- data/spec/vagrant-cosmic/config_spec.rb +340 -0
- data/spec/vagrant-cosmic/model/cosmic_resource_spec.rb +95 -0
- data/spec/vagrant-cosmic/service/cosmic_resource_service_spec.rb +43 -0
- data/spec/vagrant-cosmic/support/be_a_resource.rb +6 -0
- data/vagrant-cosmic.gemspec +59 -0
- data/vagrant-cosmic.spec +42 -0
- metadata +218 -0
data/README.md
ADDED
@@ -0,0 +1,409 @@
|
|
1
|
+
# Vagrant Cosmic Provider
|
2
|
+
|
3
|
+
This is a fork of the [CloudStack Vagrant provider](https://github.com/MissionCriticalCloud/vagrant-cloudstack).
|
4
|
+
|
5
|
+
This is a [Vagrant](http://www.vagrantup.com) 2.2+ plugin that adds a `cosmic`
|
6
|
+
provider to Vagrant for use with [Cosmic](https://github.com/MissionCriticalCloud/cosmic).
|
7
|
+
|
8
|
+
## Features
|
9
|
+
|
10
|
+
* SSH into the instances.
|
11
|
+
* Provision the instances with any built-in Vagrant provisioner.
|
12
|
+
* Minimal synced folder support via `rsync`/`winrm`.
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Install using standard Vagrant 2.2+ plugin installation methods. After
|
17
|
+
installing, `vagrant up` and specify the `cosmic` provider. An example is
|
18
|
+
shown below.
|
19
|
+
|
20
|
+
```shell
|
21
|
+
$ vagrant plugin install vagrant-cosmic
|
22
|
+
|
23
|
+
...
|
24
|
+
|
25
|
+
$ vagrant up --provider=cosmic
|
26
|
+
|
27
|
+
...
|
28
|
+
```
|
29
|
+
|
30
|
+
## Quick Start
|
31
|
+
|
32
|
+
After installing the plugin (instructions above), the quickest way to get
|
33
|
+
started is to actually make a Vagrantfile that looks like the following, filling in
|
34
|
+
your information where necessary.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Vagrant.configure("2") do |config|
|
38
|
+
config.vm.box = "${cosmic.template_name}"
|
39
|
+
|
40
|
+
config.vm.provider :cosmic do |cosmic, override|
|
41
|
+
cosmic.host = "cosmic.local"
|
42
|
+
cosmic.path = "/client/api"
|
43
|
+
cosmic.port = "8080"
|
44
|
+
cosmic.scheme = "http"
|
45
|
+
cosmic.api_key = "AAAAAAAAAAAAAAAAAAA"
|
46
|
+
cosmic.secret_key = "AAAAAAAAAAAAAAAAAAA"
|
47
|
+
|
48
|
+
cosmic.service_offering_id = "AAAAAAAAAAAAAAAAAAA"
|
49
|
+
cosmic.disk_offering_id = "AAAAAAAAAAAAAAAAAAA"
|
50
|
+
cosmic.network_id = "AAAAAAAAAAAAAAAAAAA"
|
51
|
+
cosmic.zone_id = "AAAAAAAAAAAAAAAAAAA"
|
52
|
+
cosmic.project_id = "AAAAAAAAAAAAAAAAAAA"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Or with names instead of ids:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Vagrant.configure("2") do |config|
|
61
|
+
config.vm.box = "${cosmic.template_name}"
|
62
|
+
|
63
|
+
config.vm.provider :cosmic do |cosmic, override|
|
64
|
+
cosmic.host = "cosmic.local"
|
65
|
+
cosmic.path = "/client/api"
|
66
|
+
cosmic.port = "8080"
|
67
|
+
cosmic.scheme = "http"
|
68
|
+
cosmic.api_key = "AAAAAAAAAAAAAAAAAAA"
|
69
|
+
cosmic.secret_key = "AAAAAAAAAAAAAAAAAAA"
|
70
|
+
|
71
|
+
cosmic.service_offering_name = "THE-BESTEST"
|
72
|
+
cosmic.disk_offering_name = "THE-LARGEST-OFFER-AVAILABLE"
|
73
|
+
cosmic.network_name = "WOW-SUCH-FAST-OFFERING"
|
74
|
+
cosmic.zone_name = "District-9"
|
75
|
+
cosmic.name = "doge-is-a-hostname-now"
|
76
|
+
# Sadly there is currently no support for the project API in fog.
|
77
|
+
cosmic.project_id = "AAAAAAAAAAAAAAAAAAA"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
And then run `vagrant up --provider=cosmic`.
|
83
|
+
|
84
|
+
This will start an instance in Cosmic. And assuming your template
|
85
|
+
on Cosmic is Vagrant compatible _(vagrant user with official
|
86
|
+
vagrant pub key in authorized_keys)_ SSH and provisioning will work as
|
87
|
+
well.
|
88
|
+
|
89
|
+
## Configuration
|
90
|
+
|
91
|
+
This provider exposes quite a few provider-specific configuration options. Most of the settings
|
92
|
+
have both an id and a name setting and you can chose to use either (i.e network_id or network_name).
|
93
|
+
This gives the possibility to use the easier to remember name instead of the UUID,
|
94
|
+
this will also enable you to upgrade the different settings in your cloud without having
|
95
|
+
to update UUIDs in your Vagrantfile. If both are specified, the id parameter takes precedence.
|
96
|
+
|
97
|
+
* `name` - Hostname of the created machine
|
98
|
+
* `host` - Cosmic API host
|
99
|
+
* `path` - Cosmic API path
|
100
|
+
* `port` - Cosmic API port
|
101
|
+
* `scheme` - Cosmic API scheme _(defaults: https (thanks to the resolution order in fog))_
|
102
|
+
* `api_key` - The API key for accessing Cosmic
|
103
|
+
* `secret_key` - The secret key for accessing Cosmic
|
104
|
+
* `instance_ready_timeout` - The number of seconds to wait for the instance
|
105
|
+
to become "ready" in Cosmic. Defaults to 120 seconds.
|
106
|
+
* `domain_id` - Domain id to launch the instance into
|
107
|
+
* `network_id` - Network uuid(s) that the instance should use
|
108
|
+
* `network_id` is single value (e.g. `"AAAA"`) or multiple values (e.g. `["AAAA", "BBBB"]`)
|
109
|
+
* `network_name` - Network name(s) that the instance should use
|
110
|
+
* `network_name` is single value (e.g. `"AAAA"`) or multiple values (e.g. `["AAAA", "BBBB"]`)
|
111
|
+
* `project_id` - Project uuid that the instance should belong to
|
112
|
+
* `service_offering_id`- Service offering uuid to use for the instance
|
113
|
+
* `service_offering_name`- Service offering name to use for the instance
|
114
|
+
* `template_id` - Template uuid to use for the instance
|
115
|
+
* `template_name` - Template name to use for the instance, defaults to Vagrants config.vm.box
|
116
|
+
* `zone_id` - Zone uuid to launch the instance into
|
117
|
+
* `zone_name` - Zone uuid to launch the instance into
|
118
|
+
* `keypair` - SSH keypair name, if neither'keypair' nor 'ssh_key' have been specified, a temporary keypair will be created
|
119
|
+
* `static_nat` - static nat for the virtual machine
|
120
|
+
* `pf_ip_address_id` - IP address ID for port forwarding rule
|
121
|
+
* `pf_ip_address` - IP address for port forwarding rule
|
122
|
+
* `pf_public_port` - Public Communicator port for port forwarding rule
|
123
|
+
* `pf_public_rdp_port` - Public RDP port for port forwarding rule
|
124
|
+
* `pf_public_port_randomrange` - If public port is omited, a port from this range wll be used (default `{:start=>49152, :end=>65535}`)
|
125
|
+
* `pf_private_port` - Private port for port forwarding rule (defaults to respective Communicator protocol)
|
126
|
+
* `pf_open_firewall` - Flag to enable/disable automatic open firewall rule (by Cosmic)
|
127
|
+
* `pf_trusted_networks` - Array of CIDRs or (array of) comma-separated string of CIDRs to network(s) to
|
128
|
+
* automatically (by plugin) generate firewall rules for, ignored if `pf_open_firewall` set `true`
|
129
|
+
* use as default for firewall rules where source CIDR is missing
|
130
|
+
* `port_forwarding_rules` - Port forwarding rules for the virtual machine
|
131
|
+
* `firewall_rules` - Firewall rules
|
132
|
+
* `display_name` - Display name for the instance
|
133
|
+
* `group` - Group for the instance
|
134
|
+
* `ssh_key` - Path to a private key to be used with ssh _(defaults to Vagrant's `config.ssh.private_key_path`)_
|
135
|
+
* `ssh_user` - User name to be used with ssh _(defaults to Vagrant's `config.ssh.username`)_
|
136
|
+
* `ssh_network_id` - The network_id to be used when loging in to the vm via ssh _(defaults to first nic)_
|
137
|
+
* `ssh_network_name` - The network_name to be used when loging in to the vm via ssh _(defaults to first nic)_
|
138
|
+
* Use either `ssh_network_id` or `ssh_network_name`. If specified both , use `ssh_network_id`
|
139
|
+
* `vm_user` - User name to be used with winrm _(defaults to Vagrant's `config.winrm.username`)_
|
140
|
+
* `vm_password` - Password to be used with winrm. _(If the Cosmic template is "Password Enabled", leaving this unset will trigger the plugin to retrieve and use it.)_
|
141
|
+
* `private_ip_address` - private (static)ip address to be used by the virtual machine
|
142
|
+
* `expunge_on_destroy` - Flag to enable/disable expunge vm on destroy
|
143
|
+
|
144
|
+
These can be set like typical provider-specific configuration:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
Vagrant.configure("2") do |config|
|
148
|
+
# ... other stuff
|
149
|
+
|
150
|
+
config.vm.provider :cosmic do |cosmic|
|
151
|
+
cosmic.api_key = "foo"
|
152
|
+
cosmic.secret_key = "bar"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
In addition to the above top-level configs, you can use the `region_config` method to specify region-specific overrides within your Vagrantfile. Note that the top-level `region` config must always be specified to choose which region you want to actually use, however. This looks like this:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
Vagrant.configure("2") do |config|
|
161
|
+
# ... other stuff
|
162
|
+
|
163
|
+
config.vm.provider :cosmic do |cosmic|
|
164
|
+
cosmic.api_key = "foo"
|
165
|
+
cosmic.secret_key = "bar"
|
166
|
+
cosmic.domain = "internal"
|
167
|
+
|
168
|
+
# Simple domain config
|
169
|
+
cosmic.domain_config "internal", :network_id => "AAAAAAAAAAAAAAAAAAA"
|
170
|
+
|
171
|
+
# More comprehensive region config
|
172
|
+
cosmic.domain_config "internal" do |domain|
|
173
|
+
domain.network_id = "AAAAAAAAAAAAAAAAAAA"
|
174
|
+
domain.service_offering_id = "AAAAAAAAAAAAAAAAAAA"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
180
|
+
The domain-specific configurations will override the top-level configurations when that domain is used. They otherwise inherit the top-level configurations, as you would probably expect.
|
181
|
+
|
182
|
+
## Networks
|
183
|
+
|
184
|
+
Networking features in the form of `config.vm.network` are not supported with `vagrant-cosmic`, currently. If any of these are specified, Vagrant will emit a warning, but will otherwise boot the Cosmic machine.
|
185
|
+
|
186
|
+
### Basic networking versus Advanced networking
|
187
|
+
|
188
|
+
The plugin will determine this network type dynamically from the zone. The setting `network_type` in the Vagrant file has been deprecated, and is silently ignored.
|
189
|
+
|
190
|
+
### Basic Networking
|
191
|
+
|
192
|
+
If the network type of your zone is `basic`, you can use Security Groups and associate rules in your Vagrantfile.
|
193
|
+
|
194
|
+
If you already have Security Groups, you can associate them to your instance, with their IDs:
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
Vagrant.configure("2") do |config|
|
198
|
+
# ... other stuff
|
199
|
+
|
200
|
+
config.vm.provider :cosmic do |cosmic|
|
201
|
+
cosmic.api_key = "foo"
|
202
|
+
cosmic.secret_key = "bar"
|
203
|
+
cosmic.security_group_ids = ['aaaa-bbbb-cccc-dddd', '1111-2222-3333-4444']
|
204
|
+
end
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
or their names:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
Vagrant.configure("2") do |config|
|
212
|
+
# ... other stuff
|
213
|
+
|
214
|
+
config.vm.provider :cosmic do |cosmic|
|
215
|
+
cosmic.api_key = "foo"
|
216
|
+
cosmic.secret_key = "bar"
|
217
|
+
cosmic.security_group_names = ['
|
218
|
+
min_fantastiska_security_group', 'another_security_grupp']
|
219
|
+
end
|
220
|
+
end
|
221
|
+
```
|
222
|
+
|
223
|
+
But you can also create your Security Groups in the Vagrantfile:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
Vagrant.configure("2") do |config|
|
227
|
+
# ... other stuff
|
228
|
+
|
229
|
+
config.vm.provider :cosmic do |cosmic|
|
230
|
+
cosmic.api_key = "foo"
|
231
|
+
cosmic.secret_key = "bar"
|
232
|
+
cosmic.security_groups = [
|
233
|
+
{
|
234
|
+
:name => "Awesome_security_group",
|
235
|
+
:description => "Created from the Vagrantfile",
|
236
|
+
:rules => [
|
237
|
+
{:type => "ingress", :protocol => "TCP", :startport => 22, :endport => 22, :cidrlist => "0.0.0.0/0"},
|
238
|
+
{:type => "ingress", :protocol => "TCP", :startport => 80, :endport => 80, :cidrlist => "0.0.0.0/0"},
|
239
|
+
{:type => "egress", :protocol => "TCP", :startport => 81, :endport => 82, :cidrlist => "1.2.3.4/24"},
|
240
|
+
]
|
241
|
+
}
|
242
|
+
]
|
243
|
+
end
|
244
|
+
end
|
245
|
+
```
|
246
|
+
|
247
|
+
### Static NAT, Firewall, Port forwarding
|
248
|
+
|
249
|
+
You can create your static nat, firewall and port forwarding rules in the Vagrantfile. You can use this rule to access virtual machine from an external machine.
|
250
|
+
|
251
|
+
The rules created in Vagrantfile are removed when the virtual machine is destroyed.
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
Vagrant.configure("2") do |config|
|
255
|
+
# ... other stuff
|
256
|
+
|
257
|
+
config.vm.provider :cosmic do |cosmic|
|
258
|
+
|
259
|
+
override.ssh.host = "X.X.X.X"
|
260
|
+
|
261
|
+
cosmic.static_nat = [
|
262
|
+
{ :ipaddress => "A.A.A.A"}
|
263
|
+
]
|
264
|
+
|
265
|
+
cosmic.port_forwarding_rules = [
|
266
|
+
{ :ipaddress => "X.X.X.X", :protocol => "tcp", :publicport => 22, :privateport => 22, :openfirewall => false },
|
267
|
+
{ :ipaddress => "X.X.X.X", :protocol => "tcp", :publicport => 80, :privateport => 80, :openfirewall => false }
|
268
|
+
]
|
269
|
+
|
270
|
+
cosmic.firewall_rules = [
|
271
|
+
{ :ipaddress => "A.A.A.A", :cidrlist => "1.2.3.4/24", :protocol => "icmp", :icmptype => 8, :icmpcode => 0 },
|
272
|
+
{ :ipaddress => "X.X.X.X", :cidrlist => "1.2.3.4/24", :protocol => "tcp", :startport => 22, :endport => 22 },
|
273
|
+
{ :ipaddress => "X.X.X.X", :cidrlist => "1.2.3.4/24", :protocol => "tcp", :startport => 80, :endport => 80 }
|
274
|
+
]
|
275
|
+
|
276
|
+
end
|
277
|
+
end
|
278
|
+
```
|
279
|
+
|
280
|
+
Most values in the firewall and portforwarding rules are not mandatory, except either startport/endport or privateport/publicport
|
281
|
+
|
282
|
+
* `:ipaddress` - defaults to `pf_ip_address`
|
283
|
+
* `:protocol` - defaults to `'tcp'`
|
284
|
+
* `:publicport` - defaults to `:privateport`
|
285
|
+
* `:privateport` - defaults to `:publicport`
|
286
|
+
* `:openfirewall` - defaults to `pf_open_firewall`
|
287
|
+
* `:cidrlist` - defaults to `pf_trusted_networks`
|
288
|
+
* `:startport` - defaults to `:endport`
|
289
|
+
* `:endport` - not required by Cosmic
|
290
|
+
|
291
|
+
For only allowing Vagrant to access the box for further provisioning (SSH/WinRM), and opening the Firewall for some subnets, the following config is sufficient:
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
Vagrant.configure("2") do |config|
|
295
|
+
# ... other stuff
|
296
|
+
|
297
|
+
config.vm.provider :cosmic do |cosmic|
|
298
|
+
cosmic.pf_open_firewall = "false"
|
299
|
+
cosmic.pf_ip_address = X.X.X.X
|
300
|
+
cosmic.pf_trusted_networks = [ "1.2.3.4/24" , "11.22.33.44/32" ]
|
301
|
+
end
|
302
|
+
end
|
303
|
+
```
|
304
|
+
|
305
|
+
Where X.X.X.X is the ip of the respective Cosmic network, this will automatically map the port of the used Communicator (SSH/Winrm) via a random public port, open the Firewall and set Vagrant to use it.
|
306
|
+
|
307
|
+
The plugin can also automatically generate firewall rules off of the portforwarding rules:
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
Vagrant.configure("2") do |config|
|
311
|
+
# ... other stuff
|
312
|
+
|
313
|
+
config.vm.provider :cosmic do |cosmic|
|
314
|
+
|
315
|
+
cosmic.pf_trusted_networks = "1.2.3.4/24,11.22.33.44/32"
|
316
|
+
cosmic.port_forwarding_rules = [
|
317
|
+
{ :privateport => 22, :generate_firewall => true },
|
318
|
+
{ :privateport => 80, :generate_firewall => true }
|
319
|
+
]
|
320
|
+
|
321
|
+
end
|
322
|
+
end
|
323
|
+
```
|
324
|
+
|
325
|
+
### Virtual Router versus VPC
|
326
|
+
|
327
|
+
Both Virtual Routers and VPCs are supported when using port-forwarding and firewall. This is automatically determined by the specific `pf_ip_address`.
|
328
|
+
|
329
|
+
Note that there are architectural differences in Cosmic which the configuration must adhere to.
|
330
|
+
|
331
|
+
For VPC:
|
332
|
+
|
333
|
+
* `pf_open_firewall` will be ignored as global setting and (specifically) in `port_forwarding_rules`
|
334
|
+
* for `firewall_rules` to open access for `port_forwarding_rules`, the firewall rule should allow traffic for the `:privateport` port.
|
335
|
+
|
336
|
+
For Virtual Router:
|
337
|
+
|
338
|
+
* for `firewall_rules` to open access for `port_forwarding_rules`, the firewall rule should allow traffic for the `:publicport` port.
|
339
|
+
|
340
|
+
Usage of other attributes and features work with both network types. Such as `:generate_firewall` for portforwarding rules, or `pf_trusted_networks` to automatically generate rules for the Communicator.
|
341
|
+
|
342
|
+
## Synced Folders
|
343
|
+
|
344
|
+
There is minimal support for synced folders. Upon `vagrant up`, `vagrant reload`, and `vagrant provision`, the Cosmic provider will use `rsync` (if available) to uni-directionally sync the folder to the remote machine over SSH, and use Vagrant plugin `vagrant-winrm-syncedfolders` (if available) to uni-directionally sync the folder to the remote machine over WinRM.
|
345
|
+
|
346
|
+
This is good enough for all built-in Vagrant provisioners (shell,
|
347
|
+
chef, and puppet) to work!
|
348
|
+
|
349
|
+
### User data
|
350
|
+
|
351
|
+
You can specify user data for the instance being booted.
|
352
|
+
|
353
|
+
```ruby
|
354
|
+
Vagrant.configure("2") do |config|
|
355
|
+
# ... other stuff
|
356
|
+
|
357
|
+
config.vm.provider :cosmic do |cosmic|
|
358
|
+
# Option 1: a single string
|
359
|
+
cosmic.user_data = "#!/bin/bash\necho 'got user data' > /tmp/user_data.log\necho"
|
360
|
+
|
361
|
+
# Option 2: use a file
|
362
|
+
cosmic.user_data = File.read("user_data.txt")
|
363
|
+
end
|
364
|
+
end
|
365
|
+
```
|
366
|
+
|
367
|
+
The maximum length of user_data is around 1500 bytes with Cosmic API < 4.2 (base64 encoded user_data must be < 2048 bytes)
|
368
|
+
|
369
|
+
## Development
|
370
|
+
|
371
|
+
To work on the `vagrant-cosmic` plugin, clone this repository out, and use
|
372
|
+
[Bundler](http://gembundler.com) to get the dependencies:
|
373
|
+
|
374
|
+
```shell
|
375
|
+
bundle install
|
376
|
+
```
|
377
|
+
|
378
|
+
Once you have the dependencies, verify the unit tests pass with `rake`:
|
379
|
+
|
380
|
+
```shell
|
381
|
+
bundle exec rake
|
382
|
+
```
|
383
|
+
|
384
|
+
If the unit-tests pass, verify the plugin is functionaly good by running the functional tests with bats. Before running the tests you need to export a set of variables that are used in the tests. Look at the Rake file for the required variables, or run the following Rake command to check:
|
385
|
+
|
386
|
+
```shell
|
387
|
+
bundle exec rake functional_tests:check_environment
|
388
|
+
```
|
389
|
+
|
390
|
+
Run all functional tests by executing:
|
391
|
+
|
392
|
+
```shell
|
393
|
+
bundle exec rake functional_tests:all
|
394
|
+
```
|
395
|
+
|
396
|
+
If those pass, you're ready to start developing the plugin. You can test
|
397
|
+
the plugin without installing it into your Vagrant environment by just
|
398
|
+
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
|
399
|
+
and add the following line to your `Vagrantfile`:
|
400
|
+
|
401
|
+
```ruby
|
402
|
+
Vagrant.require_plugin "vagrant-cosmic"
|
403
|
+
```
|
404
|
+
|
405
|
+
Use `bundler` to execute Vagrant:
|
406
|
+
|
407
|
+
```shell
|
408
|
+
bundle exec vagrant up --provider=cosmic
|
409
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:functionaltest) do |t|
|
6
|
+
t.pattern = "*_spec.rb"
|
7
|
+
t.rspec_opts = "-fd"
|
8
|
+
t.verbose = false
|
9
|
+
end
|
10
|
+
|
11
|
+
# Immediately sync all stdout so that tools like buildbot can
|
12
|
+
# immediately load in the output.
|
13
|
+
$stdout.sync = true
|
14
|
+
$stderr.sync = true
|
15
|
+
|
16
|
+
# Change to the directory of this file.
|
17
|
+
Dir.chdir(File.expand_path("../", __FILE__))
|
18
|
+
|
19
|
+
# This installs the tasks that help with gem creation and
|
20
|
+
# publishing.
|
21
|
+
Bundler::GemHelper.install_tasks
|
22
|
+
|
23
|
+
# Install the `spec` task so that we can run tests.
|
24
|
+
RSpec::Core::RakeTask.new
|
25
|
+
|
26
|
+
# Default task is to run the unit tests
|
27
|
+
task :default => "spec"
|
28
|
+
|
29
|
+
|
30
|
+
namespace :functional_tests do
|
31
|
+
|
32
|
+
# Name must match folder beneath functional-tests/
|
33
|
+
functional_test_names = %w(vmlifecycle networking rsync)
|
34
|
+
separate_test_names = %w(basic)
|
35
|
+
|
36
|
+
desc "Check for required enviroment variables for functional testing"
|
37
|
+
task :check_environment do
|
38
|
+
missing_env=false
|
39
|
+
[
|
40
|
+
'COSMIC_API_KEY',
|
41
|
+
'COSMIC_SECRET_KEY',
|
42
|
+
'COSMIC_HOST',
|
43
|
+
'PUBLIC_SOURCE_NAT_IP',
|
44
|
+
'NETWORK_NAME',
|
45
|
+
'SERVICE_OFFERING_NAME',
|
46
|
+
'ZONE_NAME',
|
47
|
+
'PUBLIC_WINRM_PORT',
|
48
|
+
'PRIVATE_WINRM_PORT',
|
49
|
+
'PUBLIC_SSH_PORT',
|
50
|
+
'PRIVATE_SSH_PORT',
|
51
|
+
'SOURCE_CIDR',
|
52
|
+
'LINUX_TEMPLATE_NAME',
|
53
|
+
'WINDOWS_TEMPLATE_NAME',
|
54
|
+
'VPC_PUBLIC_IP',
|
55
|
+
'VPC_TIER_NAME',
|
56
|
+
'VR_PUBLIC_IP',
|
57
|
+
'VR_NETWORK_NAME',
|
58
|
+
'DISK_OFFERING_NAME'
|
59
|
+
].each do |var|
|
60
|
+
if ENV[var].nil?
|
61
|
+
puts "Please set environment variable #{var}."
|
62
|
+
missing_env=true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
exit 1 if missing_env
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Run all functional tests"
|
69
|
+
task :all => [ :check_environment ] do
|
70
|
+
functional_test_names.each do |test_name|
|
71
|
+
Rake::Task["functional_tests:#{test_name}"].invoke
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
functional_test_names.each do |test_dir_name|
|
77
|
+
desc "Run functional test: #{test_dir_name}"
|
78
|
+
task test_dir_name => [ :check_environment ] do
|
79
|
+
Dir.chdir("#{File.expand_path('../', __FILE__)}/functional-tests/#{test_dir_name}/")
|
80
|
+
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
|
81
|
+
|
82
|
+
ENV['TEST_NAME'] = "vagrant_cosmic_functional_test-#{test_dir_name}"
|
83
|
+
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
|
84
|
+
puts "Running RSpec tests in folder : #{test_dir_name}"
|
85
|
+
puts "Using Vagrant file : #{ENV['VAGRANT_VAGRANTFILE']}"
|
86
|
+
Rake::Task[:functionaltest].execute
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
separate_test_names.each do |test_dir_name|
|
92
|
+
desc "Run functional test: #{test_dir_name}"
|
93
|
+
task test_dir_name => [ :check_environment ] do
|
94
|
+
Dir.chdir("#{File.expand_path('../', __FILE__)}/functional-tests/#{test_dir_name}/")
|
95
|
+
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
|
96
|
+
|
97
|
+
ENV['TEST_NAME'] = "vagrant_cosmic_functional_test-#{test_dir_name}"
|
98
|
+
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
|
99
|
+
puts "Running RSpec tests in folder : #{test_dir_name}"
|
100
|
+
puts "Using Vagrant file : #{ENV['VAGRANT_VAGRANTFILE']}"
|
101
|
+
Rake::Task[:functionaltest].execute
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
data/build_rpm.sh
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
VERSION=1.5.0
|
3
|
+
mkdir -p /tmp/vagrant-cosmic-build_rpm.$$/vagrant-cosmic-$VERSION
|
4
|
+
cp -r . /tmp/vagrant-cosmic-build_rpm.$$/vagrant-cosmic-$VERSION/
|
5
|
+
tar -C /tmp/vagrant-cosmic-build_rpm.$$/ -czf ~/rpmbuild/SOURCES/vagrant-cosmic-$VERSION.tar.gz vagrant-cosmic-$VERSION
|
6
|
+
rpmbuild --define "gemver $VERSION" -bb vagrant-cosmic.spec
|
7
|
+
rm -rf /tmp/vagrant-cosmic-build_rpm.$$
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = '2'
|
6
|
+
|
7
|
+
Vagrant.require_version '>= 1.5.0'
|
8
|
+
|
9
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
10
|
+
|
11
|
+
config.vm.synced_folder ".", "/vagrant", disabled: true, type: 'rsync' # if Vagrant::Util::Platform.windows?
|
12
|
+
config.vm.box = ENV['LINUX_TEMPLATE_NAME']
|
13
|
+
|
14
|
+
config.vm.provider :cosmic do |cosmic, override|
|
15
|
+
cosmic.display_name = ENV['TEST_NAME']
|
16
|
+
|
17
|
+
cosmic.host = ENV['COSMIC_HOST']
|
18
|
+
cosmic.path = '/client/api'
|
19
|
+
cosmic.port = '8080'
|
20
|
+
cosmic.scheme = 'http'
|
21
|
+
cosmic.api_key = ENV['COSMIC_API_KEY']
|
22
|
+
cosmic.secret_key = ENV['COSMIC_SECRET_KEY']
|
23
|
+
|
24
|
+
cosmic.zone_name = ENV['ZONE_NAME']
|
25
|
+
cosmic.network_name = ENV['NETWORK_NAME']
|
26
|
+
cosmic.service_offering_name = ENV['SERVICE_OFFERING_NAME']
|
27
|
+
|
28
|
+
|
29
|
+
cosmic.expunge_on_destroy = ENV['CS_EXPUNGE'] == "true"
|
30
|
+
cosmic.network_type = "Ignored"
|
31
|
+
cosmic.ssh_key = ENV['SSH_KEY'] unless ENV['SSH_KEY'].nil?
|
32
|
+
cosmic.ssh_user = ENV['SSH_USER'] unless ENV['SSH_USER'].nil?
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe 'Basic Network' do
|
2
|
+
it 'starts a Linux VM' do
|
3
|
+
expect(`vagrant up`).to include(
|
4
|
+
'Network name or id will be ignored',
|
5
|
+
'Machine is booted and ready for use!'
|
6
|
+
)
|
7
|
+
expect($?.exitstatus).to eq(0)
|
8
|
+
end
|
9
|
+
it 'destroys a Linux VM' do
|
10
|
+
expect(`vagrant destroy --force`).to include(
|
11
|
+
'Terminating the instance...'
|
12
|
+
)
|
13
|
+
expect($?.exitstatus).to eq(0)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
5
|
+
VAGRANTFILE_API_VERSION = '2'
|
6
|
+
|
7
|
+
Vagrant.require_version '>= 1.5.0'
|
8
|
+
networks = {
|
9
|
+
VR: {
|
10
|
+
network_name: ENV['VR_NETWORK_NAME'],
|
11
|
+
public_ip: ENV['VR_PUBLIC_IP']
|
12
|
+
},
|
13
|
+
VPC: {
|
14
|
+
network_name: ENV['VPC_TIER_NAME'],
|
15
|
+
public_ip: ENV['VPC_PUBLIC_IP']
|
16
|
+
}
|
17
|
+
}
|
18
|
+
machines = {}
|
19
|
+
networks.each_pair do |net_name, net_options|
|
20
|
+
box_number = 0
|
21
|
+
machines["#{net_name}box#{box_number+=1}"] = {
|
22
|
+
# Test fixed public port
|
23
|
+
pf_public_port: ENV['PUBLIC_SSH_PORT'],
|
24
|
+
# Test fixed private port
|
25
|
+
pf_private_port: ENV['PRIVATE_SSH_PORT'],
|
26
|
+
#
|
27
|
+
pf_ip_address: net_options[:public_ip],
|
28
|
+
network_name: net_options[:network_name],
|
29
|
+
firewall_rules: [
|
30
|
+
# Full Firewall rule
|
31
|
+
{:ipaddress => net_options[:public_ip], :protocol => 'tcp', :startport => 1111, :endport => 1111},
|
32
|
+
# Firewall rule without ':ipaddress' which defaults to 'cosmic_pf_ip_address'
|
33
|
+
{:protocol => 'tcp', :startport => 1122, :endport => 1122},
|
34
|
+
# Firewall rule without ':protocol', which defaults to 'tcp'
|
35
|
+
{:startport => 1133, :endport => 1133},
|
36
|
+
# Firewall rule without ':endport', which defaults to ':startport' if present
|
37
|
+
{:startport => 1144},
|
38
|
+
# Firewall rule without ':start', which defaults to ':endport' if present
|
39
|
+
{:endport => 22}
|
40
|
+
],
|
41
|
+
port_forwarding_rules: [
|
42
|
+
# Full portforwarding rule
|
43
|
+
{:ipaddress => net_options[:public_ip], :protocol => "tcp", :publicport => 1111, :privateport => 22, :openfirewall => false},
|
44
|
+
# Portforwarding rule without ':ipaddress' which defaults to 'cosmic_pf_ip_address'
|
45
|
+
{:protocol => "tcp", :publicport => 1122, :privateport => 22, :openfirewall => false},
|
46
|
+
# Portforwarding rule without ':protocol', which defaults to 'tcp'
|
47
|
+
{:publicport => 1133, :privateport => 22, :openfirewall => false},
|
48
|
+
# Portforwarding rule without ':openfirewall', which defaults to 'cosmic.pf_open_firewall'
|
49
|
+
{:publicport => 1144, :privateport => 22},
|
50
|
+
# Portforwarding rule without ':publicport', which defaults to ':privateport'
|
51
|
+
{:privateport => 22},
|
52
|
+
# Portforwarding rule with ':generate_firewall', which generates an apropriate
|
53
|
+
# Firewall rule based ':publicport' => ':startport', and other defaults
|
54
|
+
{:publicport => 1155, :privateport => 22, :generate_firewall => true},
|
55
|
+
# Portforwarding rule which instructs Cosmic to create a Firewall rule
|
56
|
+
{:publicport => 1166, :privateport => 22, :openfirewall => true},
|
57
|
+
],
|
58
|
+
# Trusted network as array, instead of string. Add some networks to make sure it's an (multi element) Array
|
59
|
+
pf_trusted_networks: [ENV['SOURCE_CIDR'], ',172.31.1.172/32', '172.31.1.173/32'],
|
60
|
+
}
|
61
|
+
|
62
|
+
machines["#{net_name}box#{box_number+=1}"] = {
|
63
|
+
network_name: net_options[:network_name],
|
64
|
+
pf_ip_address: net_options[:public_ip],
|
65
|
+
# NO pf_public_port; test auto generated public port
|
66
|
+
# NO pf_private_port; test detection of Communicator port (SSH/Winrm)
|
67
|
+
# NO firewall rules for Communicator (SSH/WinRM), test auto generation
|
68
|
+
# Trusted networks as string instead of array. Add some networks to make sure it supports multiple network-string
|
69
|
+
pf_trusted_networks: ENV['SOURCE_CIDR'] + ',172.31.1.172/32,172.31.1.173/32'
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |global_config|
|
74
|
+
machines.each_pair do |name, options|
|
75
|
+
global_config.vm.define name do |config|
|
76
|
+
config.vm.box = ENV['LINUX_TEMPLATE_NAME']
|
77
|
+
|
78
|
+
config.vm.synced_folder ".", "/vagrant", type: "rsync",
|
79
|
+
rsync__exclude: [".git/", "vendor"], disabled: true
|
80
|
+
|
81
|
+
config.vm.provider :cosmic do |cosmic, override|
|
82
|
+
cosmic.display_name = "#{name}-#{ENV['TEST_NAME']}"
|
83
|
+
|
84
|
+
cosmic.host = ENV['COSMIC_HOST']
|
85
|
+
# Use default path, port and scheme
|
86
|
+
cosmic.api_key = ENV['COSMIC_API_KEY']
|
87
|
+
cosmic.secret_key = ENV['COSMIC_SECRET_KEY']
|
88
|
+
cosmic.zone_name = ENV['ZONE_NAME']
|
89
|
+
cosmic.network_name = options[:network_name]
|
90
|
+
cosmic.service_offering_name = ENV['SERVICE_OFFERING_NAME']
|
91
|
+
cosmic.ssh_key = ENV['SSH_KEY'] unless ENV['SSH_KEY'].nil?
|
92
|
+
cosmic.ssh_user = ENV['SSH_USER'] unless ENV['SSH_USER'].nil?
|
93
|
+
cosmic.expunge_on_destroy = ENV['EXPUNGE_ON_DESTROY']=="true"
|
94
|
+
|
95
|
+
cosmic.pf_ip_address = options[:pf_ip_address]
|
96
|
+
cosmic.pf_public_port = options[:pf_public_port] unless options[:pf_public_port].nil?
|
97
|
+
cosmic.pf_private_port = options[:pf_private_port] unless options[:pf_private_port].nil?
|
98
|
+
cosmic.pf_open_firewall = false
|
99
|
+
|
100
|
+
cosmic.pf_trusted_networks = options[:pf_trusted_networks] unless options[:pf_trusted_networks].nil?
|
101
|
+
cosmic.firewall_rules = options[:firewall_rules] unless options[:firewall_rules].nil?
|
102
|
+
cosmic.port_forwarding_rules = options[:port_forwarding_rules] unless options[:port_forwarding_rules].nil?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|