vagrant-ignition 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 10c88275ae9269f72da07adabe390677180369a1
4
+ data.tar.gz: 7dbe996b07a257d0f8f259eac6e07b1d959c3745
5
+ SHA512:
6
+ metadata.gz: f53342fa9776f2a01cd07b9bc1fad15e96228caea0ec7d26f40476640f823f2249c3b38017d299da792af84926d2a02a06474c542a47b96fe97768036929d37f
7
+ data.tar.gz: '07932f791029ba6e6ea9aa94bb37daca62a1a83d552c89ebbe8eae906a163522e9fde167ad3430454c5b510dee7d025387626f98e45263677baf5e080a5c4512'
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,84 @@
1
+ # How to Contribute
2
+
3
+ CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via
4
+ GitHub pull requests. This document outlines some of the conventions on
5
+ development workflow, commit message formatting, contact points and other
6
+ resources to make it easier to get your contribution accepted.
7
+
8
+ ## Certificate of Origin
9
+
10
+ By contributing to this project you agree to the Developer Certificate of
11
+ Origin (DCO). This document was created by the Linux Kernel community and is a
12
+ simple statement that you, as a contributor, have the legal right to make the
13
+ contribution. See the [DCO](DCO) file for details.
14
+
15
+ ## Email and Chat
16
+
17
+ The project currently uses the general CoreOS email list and IRC channel:
18
+ - Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev)
19
+ - IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org
20
+
21
+ Please avoid emailing maintainers found in the MAINTAINERS file directly. They
22
+ are very busy and read the mailing lists.
23
+
24
+ ## Reporting a security vulnerability
25
+
26
+ Due to their public nature, GitHub and mailing lists are not appropriate places for reporting vulnerabilities. Please refer to CoreOS's [security disclosure][disclosure] process when reporting issues that may be security related.
27
+
28
+ ## Getting Started
29
+
30
+ - Fork the repository on GitHub
31
+ - Read the [README](README.md) for build and test instructions
32
+ - Play with the project, submit bugs, submit patches!
33
+
34
+ ### Contribution Flow
35
+
36
+ This is a rough outline of what a contributor's workflow looks like:
37
+
38
+ - Create a topic branch from where you want to base your work (usually master).
39
+ - Make commits of logical units.
40
+ - Make sure your commit messages are in the proper format (see below).
41
+ - Push your changes to a topic branch in your fork of the repository.
42
+ - Make sure the tests pass, and add any new tests as appropriate.
43
+ - Submit a pull request to the original repository.
44
+
45
+ Thanks for your contributions!
46
+
47
+ ### Coding Style
48
+
49
+ CoreOS projects written in Go follow a set of style guidelines that we've documented
50
+ [here](https://github.com/coreos/docs/tree/master/golang). Please follow them when
51
+ working on your contributions.
52
+
53
+ ### Format of the Commit Message
54
+
55
+ We follow a rough convention for commit messages that is designed to answer two
56
+ questions: what changed and why. The subject line should feature the what and
57
+ the body of the commit should describe the why.
58
+
59
+ ```
60
+ scripts: add the test-cluster command
61
+
62
+ this uses tmux to setup a test cluster that you can easily kill and
63
+ start for debugging.
64
+
65
+ Fixes #38
66
+ ```
67
+
68
+ The format can be described more formally as follows:
69
+
70
+ ```
71
+ <subsystem>: <what changed>
72
+ <BLANK LINE>
73
+ <why this change was made>
74
+ <BLANK LINE>
75
+ <footer>
76
+ ```
77
+
78
+ The first line is the subject and should be no longer than 70 characters, the
79
+ second line is always blank, and other lines should be wrapped at 80 characters.
80
+ This allows the message to be easier to read on GitHub as well as in various
81
+ git tools.
82
+
83
+
84
+ [disclosure]: https://coreos.com/security/disclosure/
data/DCO ADDED
@@ -0,0 +1,36 @@
1
+ Developer Certificate of Origin
2
+ Version 1.1
3
+
4
+ Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5
+ 660 York Street, Suite 102,
6
+ San Francisco, CA 94110 USA
7
+
8
+ Everyone is permitted to copy and distribute verbatim copies of this
9
+ license document, but changing it is not allowed.
10
+
11
+
12
+ Developer's Certificate of Origin 1.1
13
+
14
+ By making a contribution to this project, I certify that:
15
+
16
+ (a) The contribution was created in whole or in part by me and I
17
+ have the right to submit it under the open source license
18
+ indicated in the file; or
19
+
20
+ (b) The contribution is based upon previous work that, to the best
21
+ of my knowledge, is covered under an appropriate open source
22
+ license and I have the right under that license to submit that
23
+ work with modifications, whether created in whole or in part
24
+ by me, under the same open source license (unless I am
25
+ permitted to submit under a different license), as indicated
26
+ in the file; or
27
+
28
+ (c) The contribution was provided directly to me by some other
29
+ person who certified (a), (b) or (c) and I have not modified
30
+ it.
31
+
32
+ (d) I understand and agree that this project and the contribution
33
+ are public and that a record of the contribution (including all
34
+ personal information I submit with it, including my sign-off) is
35
+ maintained indefinitely and may be redistributed consistent with
36
+ this project or the open source license(s) involved.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ CoreOS Project
2
+ Copyright 2017 CoreOS, Inc
3
+
4
+ This product includes software developed at CoreOS, Inc.
5
+ (http://www.coreos.com/).
@@ -0,0 +1,35 @@
1
+ # Vagrant::Ignition
2
+ A Vagrant plugin that generates and mounts gpt partitioned drive for Ignition to use. It is only designed to work with the Virtualbox provider for now.
3
+
4
+
5
+ ## Installation
6
+ Build the app using:
7
+
8
+ $ gem build vagrant-ignition.gemspec
9
+
10
+ And install it with:
11
+
12
+ $ vagrant plugin install vagrant-ignition-0.0.1.gem
13
+
14
+ ## Usage
15
+ To use this plugin, a couple of config options must be set in a project's Vagrantfile config section.
16
+
17
+ Options:
18
+
19
+ `config.ignition.enabled`: Set to true to enable this plugin
20
+
21
+ `config.ignition.path`: Set to the path of the base ignition config (can be nil if there is no base)
22
+
23
+ `config.ignition.config_obj`: Set equal to `config.vm.provider :virtualbox`
24
+
25
+ `config.ignition.config_img`: Set to desired location of generated image (optional)
26
+
27
+ `config.ignition.config_vmdk`: Set to desired location of generated vmdk (optional)
28
+
29
+ `config.ignition.hostname`: Set to desired hostname of the machine (optional)
30
+
31
+ `config.ignition.ip`: Set to desired ip of eth1 (only applies if a private network is being created)
32
+
33
+ ## Contributing
34
+
35
+ Bug reports are welcome at https://issues.coreos.com/.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,63 @@
1
+ ## CoreOS Community Code of Conduct
2
+
3
+ ### Contributor Code of Conduct
4
+
5
+ As contributors and maintainers of this project, and in the interest of
6
+ fostering an open and welcoming community, we pledge to respect all people who
7
+ contribute through reporting issues, posting feature requests, updating
8
+ documentation, submitting pull requests or patches, and other activities.
9
+
10
+ We are committed to making participation in this project a harassment-free
11
+ experience for everyone, regardless of level of experience, gender, gender
12
+ identity and expression, sexual orientation, disability, personal appearance,
13
+ body size, race, ethnicity, age, religion, or nationality.
14
+
15
+ Examples of unacceptable behavior by participants include:
16
+
17
+ * The use of sexualized language or imagery
18
+ * Personal attacks
19
+ * Trolling or insulting/derogatory comments
20
+ * Public or private harassment
21
+ * Publishing others' private information, such as physical or electronic addresses, without explicit permission
22
+ * Other unethical or unprofessional conduct.
23
+
24
+ Project maintainers have the right and responsibility to remove, edit, or
25
+ reject comments, commits, code, wiki edits, issues, and other contributions
26
+ that are not aligned to this Code of Conduct. By adopting this Code of Conduct,
27
+ project maintainers commit themselves to fairly and consistently applying these
28
+ principles to every aspect of managing this project. Project maintainers who do
29
+ not follow or enforce the Code of Conduct may be permanently removed from the
30
+ project team.
31
+
32
+ This code of conduct applies both within project spaces and in public spaces
33
+ when an individual is representing the project or its community.
34
+
35
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
36
+ reported by contacting a project maintainer, Brandon Philips
37
+ <brandon.philips@coreos.com>, and/or Meghan Schofield
38
+ <meghan.schofield@coreos.com>.
39
+
40
+ This Code of Conduct is adapted from the Contributor Covenant
41
+ (http://contributor-covenant.org), version 1.2.0, available at
42
+ http://contributor-covenant.org/version/1/2/0/
43
+
44
+ ### CoreOS Events Code of Conduct
45
+
46
+ CoreOS events are working conferences intended for professional networking and
47
+ collaboration in the CoreOS community. Attendees are expected to behave
48
+ according to professional standards and in accordance with their employer’s
49
+ policies on appropriate workplace behavior.
50
+
51
+ While at CoreOS events or related social networking opportunities, attendees
52
+ should not engage in discriminatory or offensive speech or actions including
53
+ but not limited to gender, sexuality, race, age, disability, or religion.
54
+ Speakers should be especially aware of these concerns.
55
+
56
+ CoreOS does not condone any statements by speakers contrary to these standards.
57
+ CoreOS reserves the right to deny entrance and/or eject from an event (without
58
+ refund) any individual found to be engaging in discriminatory or offensive
59
+ speech or actions.
60
+
61
+ Please bring any concerns to the immediate attention of designated on-site
62
+ staff, Brandon Philips <brandon.philips@coreos.com>, and/or Meghan Schofield
63
+ <meghan.schofield@coreos.com>.
@@ -0,0 +1,2 @@
1
+ require "vagrant-ignition/version"
2
+ require "vagrant-ignition/plugin"
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/ruby
2
+ require 'zlib'
3
+
4
+ # Note: gpt and gpt2 are the primary and secondary headers respectively
5
+ class IgnitionDiskGenerator
6
+ # These are variables needed across both function
7
+ @@first_usable_lba
8
+ @@gpt_entrysize
9
+ @@gpt_max_entries
10
+ @@gpt_length
11
+ @@last_usable_lba
12
+
13
+ def self.create_disk(ignition_name, config_drive)
14
+ # Constants
15
+ @first_usable_lba = 2048
16
+ @gpt_entrysize = 128
17
+ @gpt_max_entries = 128
18
+ gpt_lba = 1
19
+ arr_lba = 2
20
+ lba_size = 512
21
+ pmbr_length = lba_size
22
+ @gpt_length = lba_size
23
+ arr_length = @gpt_max_entries * @gpt_entrysize
24
+ minimum_disk_size = 1536000 # ~1.5M; there are issues with udev not registering the device if it is less than this...
25
+ partitioner_reserved_space = (@first_usable_lba * lba_size) + (@gpt_length + arr_length) # this is space reserved by the partition tables and arrays
26
+ part_label = "Ignition Config Drive"
27
+ part_label_encoded = part_label.encode("utf-16le").bytes
28
+
29
+ ignition_conf = File.open(ignition_name, "r")
30
+ contents = ignition_conf.sysread(File.size?(ignition_name))
31
+ ignition_conf.close
32
+ file_size_unrounded = contents.bytesize
33
+ if file_size_unrounded < minimum_disk_size
34
+ file_size = minimum_disk_size - partitioner_reserved_space
35
+ elsif (file_size_unrounded % lba_size) != 0
36
+ file_size = lba_size * ((file_size_unrounded / lba_size) + 1)
37
+ else
38
+ file_size = file_size_unrounded
39
+ end
40
+ drive_size = file_size + partitioner_reserved_space
41
+
42
+ # Calculated variables
43
+ drive_sectors = drive_size / lba_size
44
+ gpt2_lba = drive_sectors - 1
45
+ arr2_lba = drive_sectors - 33
46
+ # This is global as gen_gpt requires it
47
+ @last_usable_lba = drive_sectors - 34
48
+
49
+ ## START PMBR ##
50
+ pmbr = ("\0".bytes) * 446 # bootloader code
51
+ pmbr += "\x00".bytes # status code
52
+ pmbr += "\x00\x01\x00".bytes # first CHS (for a protective MBR, we can just use the min value)
53
+ pmbr += "\xee".bytes # partition type
54
+ pmbr += "\xfe\xff\xff".bytes # last CHS (for a protective MBR, we can just use the max value)
55
+ pmbr += "\x01\x00\x00\x00".bytes # first LBA of first partition
56
+ pmbr += [gpt2_lba].pack('L').bytes # last LBA of first partition
57
+ pmbr += ("\x00".bytes) * 48 # other partition data
58
+ pmbr += "\x55\xaa".bytes # MBR signature
59
+ ## END PMBR ##
60
+
61
+ ## START PART ##
62
+
63
+ # UUID format on disk according to cgpt:
64
+ # typedef struct {
65
+ # UINT32 Data1;
66
+ # UINT16 Data2;
67
+ # UINT16 Data3;
68
+ # UINT8 Data4[8];
69
+ # } EFI_GUID;
70
+
71
+ # Partition Type GUID is 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux Filesystem)
72
+ part1 = [0x0FC63DAF].pack('L').bytes + [0x8483].pack('S').bytes + [0x4772].pack('S').bytes + [0x8E793D69D8477DE4].pack('Q').bytes.reverse!
73
+ # Partition GUID is 99570A8A-F826-4EB0-BA4E-9DD72D55EA13
74
+ part1 += [0x99570A8A].pack('L').bytes + [0xF826].pack('S').bytes + [0x4EB0].pack('S').bytes + [0xBA4E9DD72D55EA13].pack('Q').bytes.reverse!
75
+ part1 += [@first_usable_lba].pack('Q').bytes # first LBA of first partition
76
+ part1 += [@last_usable_lba].pack('Q').bytes # last LBA of first partition
77
+ part1 += "\0".bytes * 8 # partition attributes
78
+ part1 += part_label_encoded + ("\0".bytes * (72 - part_label_encoded.length)) # partition name (length of 72 bytes, or 36 utf16le characters)
79
+ part_others = "\0".bytes * (arr_length - part1.length) # other partition data
80
+ part_arr = part1 + part_others
81
+ part_extra_space = "\0".bytes * ((@first_usable_lba * lba_size) - (pmbr_length + @gpt_length + arr_length)) # this adds a buffer so that our partition starts at sector 2048
82
+ part_full = part_arr + part_extra_space
83
+ ## END PART ##
84
+
85
+
86
+ ## START GPT ##
87
+ gpt = gen_gpt(gpt_lba, gpt2_lba, arr_lba, part_arr)
88
+ ## END GPT ##
89
+
90
+ ## START GPT2 ##
91
+ gpt2 = gen_gpt(gpt2_lba, gpt_lba, arr2_lba, part_arr)
92
+ ## END GPT2 ##
93
+
94
+ ## START DATA ##
95
+ if file_size_unrounded < minimum_disk_size
96
+ data = contents.bytes + ("\x00".bytes * (file_size - contents.bytesize))
97
+ else
98
+ data = contents.bytes + ("\x00".bytes * (lba_size - (file_size_unrounded % lba_size)))
99
+ end
100
+ ## END DATA ##
101
+
102
+ device = pmbr + gpt + part_full + data + part1 + part_others + gpt2
103
+
104
+ File.open(config_drive, 'wb' ) do |output|
105
+ device.each do | byte |
106
+ output.print byte.chr
107
+ end
108
+ end
109
+ end
110
+
111
+ # The only thing calling this function should be self.create_disk
112
+ private_class_method def self.gen_gpt(curr_lba, other_lba, arr_lba, part_arr)
113
+ gpt_first = "\x45\x46\x49\x20\x50\x41\x52\x54".bytes # GPT signature
114
+ gpt_first += "\x00\x00\x01\x00".bytes # GPT version
115
+ gpt_first += "\x5c\x00\x00\x00".bytes # GPT header size
116
+
117
+ gpt_fakecrc = "\x00\x00\x00\x00".bytes # CRC for header must be zeroed during calculation
118
+
119
+ gpt_second = "\x00\x00\x00\x00".bytes # reserved zero bytes
120
+ gpt_second += [curr_lba].pack('Q').bytes # LBA of current table
121
+ gpt_second += [other_lba].pack('Q').bytes # LBA of backup/secondary table
122
+ gpt_second += [@first_usable_lba].pack('Q').bytes # first usable lba for partitions
123
+ gpt_second += [@last_usable_lba].pack('Q').bytes # last usable lba for partitions
124
+ # gpt uuid is C89E4452-AAF1-67D0-8299-E7651D2805A8
125
+ gpt_second += [0xC89E4452].pack('L').bytes + [0xAAF1].pack('S').bytes + [0x67D0].pack('S').bytes + [0x8299E7651D2805A8].pack('Q').bytes.reverse!
126
+ gpt_second += [arr_lba].pack('Q').bytes # LBA of this table's partition array
127
+ gpt_second += [@gpt_max_entries].pack('L').bytes # max number of entries in partition array
128
+ gpt_second += [@gpt_entrysize].pack('L').bytes # size (in bytes) of each entry in partition array
129
+ gpt_second += [Zlib::crc32((part_arr).pack('C*'))].pack('L').bytes # CRC for the partition array
130
+
131
+ gpt_intermediate = gpt_first + gpt_fakecrc + gpt_second # this is used during crc32 calculation
132
+
133
+ gpt_crc = [Zlib::crc32(gpt_intermediate.pack('C*'))].pack('L').bytes
134
+
135
+ gpt_end = ("\x00".bytes) * (@gpt_length - gpt_intermediate.length) # padding to finish LBA
136
+
137
+ # Return finished gpt
138
+ gpt_first + gpt_crc + gpt_second + gpt_end
139
+ end
140
+ end
@@ -0,0 +1,65 @@
1
+ require 'json'
2
+
3
+ def ignition_template()
4
+ {ignition: {version: "2.0.0", config: {}}, storage: {}, networkd: {}, passwd: {}}
5
+ end
6
+
7
+ def hostname_entry(hostname)
8
+ {filesystem: "root", path: "/etc/hostname", contents: {source: "data:,%s" % hostname, verification: {}}, mode: 0644, user: {id: 0}, group: {id: 0}}
9
+ end
10
+
11
+ def ip_entry(ip)
12
+ {name: "00-eth1.network", contents: "[Match]\nName=eth1\n\n[Network]\nAddress=%s" % ip}
13
+ end
14
+
15
+ # Vagrant insecure key
16
+ VAGRANT_INSECURE_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key"
17
+
18
+ def ssh_entry()
19
+ {name: "core", sshAuthorizedKeys: [VAGRANT_INSECURE_KEY]}
20
+ end
21
+
22
+ HOSTNAME_REGEX = /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/
23
+
24
+ def merge_ignition(ignition_path, hostname, ip, env)
25
+ if !ignition_path.nil?
26
+ ign_file = File.new(ignition_path, "rb")
27
+ config = JSON.parse(File.read(ign_file), :symbolize_names => true)
28
+ else
29
+ config = ignition_template()
30
+ # set this so the write function at the end can be simple
31
+ ignition_path = "config.ign"
32
+ end
33
+
34
+ # Handle hostname
35
+ if !hostname.nil?
36
+ if !(hostname =~ (HOSTNAME_REGEX)).nil?
37
+ config[:storage] ||= {:files => []}
38
+ config[:storage][:files] ||= []
39
+ config[:storage][:files] += [hostname_entry(hostname)]
40
+ else
41
+ env[:machine].ui.info "WARNING: Invalid hostname specified in config.ignition.hostname; ignoring hostname for Ignition Config Drive"
42
+ end
43
+ end
44
+
45
+ # Handle eth1
46
+ if !ip.nil?
47
+ config[:networkd] ||= {:units => []}
48
+ config[:networkd][:units] ||= []
49
+ config[:networkd][:units] += [ip_entry(ip)]
50
+ end
51
+
52
+ # Handle ssh key
53
+ config[:passwd] ||= {:users => []}
54
+ config[:passwd][:users] ||= []
55
+ if config[:passwd][:users].select {|user| user[:name] == "core"} != []
56
+ config[:passwd][:users].select{|user| user[:name] == "core"}[0][:sshAuthorizedKeys] ||= []
57
+ config[:passwd][:users].select{|user| user[:name] == "core"}[0][:sshAuthorizedKeys] += [VAGRANT_INSECURE_KEY]
58
+ else
59
+ config[:passwd][:users] += [ssh_entry()]
60
+ end
61
+
62
+ File.open(ignition_path + ".merged","w") do |f|
63
+ f.write(config.to_json)
64
+ end
65
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'vmdk_gen'
2
+
3
+ module VagrantPlugins
4
+ module Ignition
5
+ module Action
6
+ class SetupIgnition
7
+ def initialize(app, env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @env = env
13
+
14
+ if env[:machine].config.ignition.enabled == false
15
+ @app.call(env)
16
+ return
17
+ end
18
+
19
+ config_path = env[:machine].config.ignition.path
20
+ config_vmdk = env[:machine].config.ignition.config_vmdk
21
+ config_img = env[:machine].config.ignition.config_img
22
+
23
+ hostname = env[:machine].config.ignition.hostname
24
+ ip = env[:machine].config.ignition.ip
25
+
26
+ vmdk_gen(config_path, config_vmdk, config_img, hostname, ip, env)
27
+
28
+ env[:machine].ui.info "Configuring Ignition Config Drive"
29
+ env[:machine].provider.driver.execute("storageattach", "#{env[:machine].id}", "--storagectl", "IDE Controller", "--device", "0", "--port", "1", "--type", "hdd", "--medium", "#{config_vmdk}")
30
+
31
+ # Continue through the middleware chain
32
+ @app.call(env)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby
2
+ require_relative 'merge_ignition'
3
+ require_relative 'IgnitionDiskGenerator'
4
+
5
+ def vmdk_gen(ignition_path, vmdk_name, config_drive, hostname, ip, env)
6
+ merge_ignition(ignition_path, hostname, ip, env)
7
+ if !ignition_path.nil?
8
+ IgnitionDiskGenerator.create_disk(ignition_path + ".merged", config_drive)
9
+ else
10
+ IgnitionDiskGenerator.create_disk("config.ign.merged", config_drive)
11
+ end
12
+
13
+ if File.exist?(vmdk_name)
14
+ File.delete(vmdk_name)
15
+ end
16
+ env[:machine].provider.driver.execute("internalcommands", "createrawvmdk", "-filename", "#{vmdk_name}", "-rawdisk", "#{config_drive}")
17
+ end
@@ -0,0 +1,32 @@
1
+ module VagrantPlugins
2
+ module Ignition
3
+ class Config < Vagrant.plugin("2", :config)
4
+ attr_accessor :enabled
5
+ attr_accessor :path
6
+ attr_accessor :config_obj
7
+ attr_accessor :config_img
8
+ attr_accessor :config_vmdk
9
+ attr_accessor :hostname
10
+ attr_accessor :ip
11
+
12
+ def initialize
13
+ @enabled = UNSET_VALUE
14
+ @path = UNSET_VALUE
15
+ @config_obj = UNSET_VALUE
16
+ @config_img = UNSET_VALUE
17
+ @config_vmdk = UNSET_VALUE
18
+ @hostname = UNSET_VALUE
19
+ @ip = UNSET_VALUE
20
+ end
21
+
22
+ def finalize!
23
+ @enabled = false if @enabled == UNSET_VALUE
24
+ @path = nil if @path == UNSET_VALUE
25
+ @config_img = "config.img" if @config_img == UNSET_VALUE
26
+ @config_vmdk = "config.vmdk" if @config_vmdk == UNSET_VALUE
27
+ @hostname = nil if @hostname == UNSET_VALUE
28
+ @ip = nil if @ip == UNSET_VALUE
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module Ignition
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "vagrant-ignition"
7
+ description "Ignition support for the virtualbox vagrant provider"
8
+
9
+ config "ignition" do
10
+ require_relative "config"
11
+ Config
12
+ end
13
+
14
+ action_hook(:setup_ignition, :machine_action_up) do |hook|
15
+ require_relative "action/setup_ignition"
16
+ hook.after VagrantPlugins::ProviderVirtualBox::Action::Import, Action::SetupIgnition
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Ignition
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "vagrant-ignition/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-ignition"
8
+ spec.version = "0.0.1"
9
+ spec.authors = ["Alexander Pavel", "Alex Crawford"]
10
+ spec.email = ["alex.pavel@coreos.com", "alex.crawford@coreos.com"]
11
+
12
+ spec.description = %q{"A Vagrant plugin for VirtualBox based machines that creates and mounts an Ignition configuration disk for consumption by Ignition"}
13
+ spec.summary = spec.description
14
+ spec.homepage = "https://github.com/coreos/vagrant-ignition"
15
+ spec.license = "Apache-2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ignition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Pavel
8
+ - Alex Crawford
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-07-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.15'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.15'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description: '"A Vagrant plugin for VirtualBox based machines that creates and mounts
43
+ an Ignition configuration disk for consumption by Ignition"'
44
+ email:
45
+ - alex.pavel@coreos.com
46
+ - alex.crawford@coreos.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - CONTRIBUTING.md
53
+ - DCO
54
+ - Gemfile
55
+ - LICENSE
56
+ - NOTICE
57
+ - README.md
58
+ - Rakefile
59
+ - code-of-conduct.md
60
+ - lib/vagrant-ignition.rb
61
+ - lib/vagrant-ignition/action/IgnitionDiskGenerator.rb
62
+ - lib/vagrant-ignition/action/merge_ignition.rb
63
+ - lib/vagrant-ignition/action/setup_ignition.rb
64
+ - lib/vagrant-ignition/action/vmdk_gen.rb
65
+ - lib/vagrant-ignition/config.rb
66
+ - lib/vagrant-ignition/plugin.rb
67
+ - lib/vagrant-ignition/version.rb
68
+ - vagrant-ignition.gemspec
69
+ homepage: https://github.com/coreos/vagrant-ignition
70
+ licenses:
71
+ - Apache-2.0
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: '"A Vagrant plugin for VirtualBox based machines that creates and mounts
93
+ an Ignition configuration disk for consumption by Ignition"'
94
+ test_files: []