mirror of
https://github.com/clearlinux/micro-config-drive.git
synced 2026-04-28 10:53:47 +00:00
Initial commit
This commit is contained in:
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
*.o
|
||||
*~
|
||||
.deps
|
||||
.dirstamp
|
||||
/Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
cloud-init
|
||||
compile
|
||||
config.*
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
missing
|
||||
stamp-h1
|
||||
data/cloud-init.service
|
||||
clr-cloud-init-*.tar.xz
|
||||
clr-cloud-init-*/
|
||||
4
AUTHORS
Normal file
4
AUTHORS
Normal file
@@ -0,0 +1,4 @@
|
||||
Auke Kok <auke-jan.h.kok@intel.com>
|
||||
Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
|
||||
Ikey Doherty <michael.i.doherty@intel.com>
|
||||
Julio Montes <julio.montes@intel.com>
|
||||
674
COPYING
Normal file
674
COPYING
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
32
LICENSE
Normal file
32
LICENSE
Normal file
@@ -0,0 +1,32 @@
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
71
Makefile.am
Normal file
71
Makefile.am
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
AM_CPPFLAGS = -I $(top_srcdir)/src -I $(top_srcdir)/src/interpreters
|
||||
AM_CFLAGS = -std=gnu99 -fstack-protector -Wall -pedantic \
|
||||
-Wstrict-prototypes -Wundef -fno-common \
|
||||
-Werror-implicit-function-declaration \
|
||||
-Wformat -Wformat-security -Werror=format-security \
|
||||
-Wconversion -Wunreachable-code
|
||||
|
||||
EXTRA_DIST = \
|
||||
LICENSE \
|
||||
COPYING \
|
||||
data/cloud-init.service.in
|
||||
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) --enable-debug
|
||||
|
||||
dist_man_MANS = \
|
||||
docs/cloud-init.1 \
|
||||
docs/cloud-config.5
|
||||
|
||||
bin_PROGRAMS = cloud-init
|
||||
cloud_init_SOURCES = \
|
||||
src/ccmodules.h \
|
||||
src/ccmodules/groups.c \
|
||||
src/ccmodules/package_upgrade.c \
|
||||
src/ccmodules/packages.c \
|
||||
src/ccmodules/service.c \
|
||||
src/ccmodules/ssh_authorized_keys.c \
|
||||
src/ccmodules/users.c \
|
||||
src/ccmodules/write_files.c \
|
||||
src/curl.c \
|
||||
src/curl.h \
|
||||
src/datasources.h \
|
||||
src/datasources/openstack.c \
|
||||
src/debug.h \
|
||||
src/default_user.h \
|
||||
src/handlers.h \
|
||||
src/interpreters.h \
|
||||
src/interpreters/cloud_config.c \
|
||||
src/interpreters/cloud_config.h \
|
||||
src/interpreters/shell_script.c \
|
||||
src/json.c \
|
||||
src/json.h \
|
||||
src/lib.c \
|
||||
src/lib.h \
|
||||
src/main.c \
|
||||
src/userdata.c \
|
||||
src/userdata.h
|
||||
|
||||
|
||||
if DEBUG
|
||||
AM_CFLAGS += -ggdb3 -O0
|
||||
cloud_init_SOURCES += src/debug.c
|
||||
endif
|
||||
|
||||
cloud_init_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS) $(YAML_CFLAGS) $(JSON_GLIB_CFLAGS)
|
||||
cloud_init_LDADD = $(GLIB_LIBS) $(YAML_LIBS) $(CURL_LIBS) $(JSON_GLIB_LIBS)
|
||||
SYSTEMD_DIR=$(prefix)/lib/systemd/system/
|
||||
systemdsystemunitdir = @SYSTEMD_SYSTEMUNITDIR@
|
||||
systemdsystemunit_DATA = data/cloud-init.service
|
||||
|
||||
systemdsystemunit-install-local:
|
||||
mkdir -p $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants/
|
||||
ln -sf ../cloud-init.service $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants/cloud-init.service
|
||||
|
||||
install-data-local: systemdsystemunit-install-local
|
||||
|
||||
systemdsystemunit-uninstall-local:
|
||||
rm -f $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants/cloud-init.service
|
||||
|
||||
uninstall-local: systemdsystemunit-uninstall-local
|
||||
92
README
Normal file
92
README
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
Contents:
|
||||
|
||||
1) Description of this project
|
||||
2) Compiling, prerequisites
|
||||
3) Bugs and feedback?
|
||||
|
||||
====
|
||||
|
||||
1. Cloud-init for Clearlinux Project for Intel Architecture
|
||||
|
||||
cloud-init is the standard way for cloud customers to initialize
|
||||
containers and virtual hosts. These virtual machines are usually
|
||||
provisioned in bulk and provided without any customization to cloud
|
||||
customers, which then require that they are customized for their
|
||||
particular purpose.
|
||||
|
||||
Several implementations exist that implement this functionality,
|
||||
and this implementation is fairly similar to the other ones. For
|
||||
reference, we're listing the other implementations here:
|
||||
|
||||
- https://launchpad.net/cloud-init
|
||||
A Python-based implementation and the "standard". Many of the
|
||||
features of this implementation are derived and benchmarked against
|
||||
this version. This implementation supports many different OS's,
|
||||
not just Ubuntu.
|
||||
- https://github.com/coreos/coreos-cloudinit
|
||||
A Go-based implementation for CoreOS.
|
||||
|
||||
While generally it's preferred to use existing implementations,
|
||||
since it reduces duplicate code and makes stronger communities, in
|
||||
this project's case it was decided to forego extending and working
|
||||
on the existing implementations. Several factors were considered, and
|
||||
a short summary of the key points of that decision are listed below.
|
||||
|
||||
Speed is a significant factor. Interpreted languages have come a long
|
||||
way and are highly performant, especially if properly used. However,
|
||||
theire is a significant cost of provisioning cloud nodes that have
|
||||
increased base storage costs due to the inclusion of libraries of
|
||||
interpreted languages. Since we expect people to prefer cloud nodes are
|
||||
minimal in size, having interpreted language libraries just for the
|
||||
sake of a cloud initialization script makes little sense, and we can
|
||||
reduce the storage need and copy times of cloud images significantly.
|
||||
|
||||
Language choice is a minor factor. Generally languages that have
|
||||
good exception handling are preferred. Since execution speed and low
|
||||
complexity are preferred for installation and boot-time critical tasks,
|
||||
lots of libraries should be avoided, as robustness is critical. Missed
|
||||
python exceptions could cause cloud-init execution to halt, resulting
|
||||
in an unusable cloud host, which is to be avoided at all cost. The
|
||||
drawbacks of C being fairly sparse are known, and debugging tools
|
||||
compensate for that.
|
||||
|
||||
We can shed additional overhead by eliminating unwanted functionality
|
||||
that a clearlinux cloud node does not need, but we can likely
|
||||
never recoup the initial cost of a base Python installation, as it
|
||||
is generally in the order of 100MB or more. Hence, we've opted to
|
||||
implement a version in C that has reduced library requrements. This
|
||||
has brought the size of this implementation down to under 1mb. Even
|
||||
considering used libraries, the resulting binary is small.
|
||||
|
||||
|
||||
====
|
||||
|
||||
2. Compiling
|
||||
|
||||
Currently, cloud-init requires the following prerequisites:
|
||||
- glib-2.0 >= 2.24.1
|
||||
- yaml-0.1 >= 0.1.4
|
||||
- libcurl
|
||||
- json-glib-1.0
|
||||
|
||||
As cloud-init is tooled with autotools, one shouldn't have to do
|
||||
more than:
|
||||
|
||||
$ sh autogen.sh
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
|
||||
====
|
||||
|
||||
3. Bugs, feedback, contact
|
||||
|
||||
cloud-init is hosted on github. You can find releases, an issue
|
||||
tracker and git sources on github.com/clearlinux/clr-cloud-init. For
|
||||
mailing lists, subscribe to dev@lists.clearlinux.org (via
|
||||
lists.clearlinux.org).
|
||||
|
||||
This project has many contributors. Not all may be mentioned in the
|
||||
AUTHORS file.
|
||||
|
||||
17
autogen.sh
Executable file
17
autogen.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
|
||||
|
||||
autoreconf --force --install --symlink --warnings=all
|
||||
|
||||
args="\
|
||||
--sysconfdir=/etc \
|
||||
--localstatedir=/var \
|
||||
--prefix=/usr \
|
||||
--enable-silent-rules"
|
||||
|
||||
set -x
|
||||
./configure CFLAGS='-g -O0' $args "$@"
|
||||
make clean
|
||||
57
configure.ac
Normal file
57
configure.ac
Normal file
@@ -0,0 +1,57 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.68])
|
||||
AC_INIT([clr-cloud-init],[0],[dev@clearlinux.org])
|
||||
AM_INIT_AUTOMAKE([foreign -Wall -Werror -Wno-portability silent-rules subdir-objects color-tests no-dist-gzip dist-xz])
|
||||
AC_CONFIG_SRCDIR([src/main.c])
|
||||
AC_CONFIG_FILES([Makefile
|
||||
data/cloud-init.service])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MKDIR_P
|
||||
|
||||
# Checks for libraries.
|
||||
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24.1])
|
||||
PKG_CHECK_MODULES([YAML], [yaml-0.1 >= 0.1.4])
|
||||
PKG_CHECK_MODULES([CURL], [libcurl])
|
||||
PKG_CHECK_MODULES([JSON_GLIB], [json-glib-1.0])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([errno.h])
|
||||
AC_CHECK_HEADERS([getopt.h])
|
||||
AC_CHECK_HEADERS([glib.h])
|
||||
AC_CHECK_HEADERS([stdarg.h])
|
||||
AC_CHECK_HEADERS([stdbool.h])
|
||||
AC_CHECK_HEADERS([stdio.h])
|
||||
AC_CHECK_HEADERS([stdlib.h])
|
||||
AC_CHECK_HEADERS([stdlib.h])
|
||||
AC_CHECK_HEADERS([sys/types.h])
|
||||
AC_CHECK_HEADERS([unistd.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_CHECK_HEADER_STDBOOL
|
||||
|
||||
AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [enable debug mode @<:@default=no@:>@]),
|
||||
[], [enable_debug=no])
|
||||
AS_IF([test "x$enable_debug" = "xyes"],
|
||||
[AC_DEFINE([DEBUG], [1], [Debugging mode enabled])],
|
||||
[AC_DEFINE([NDEBUG], [1], [Debugging and assertions disabled])])
|
||||
AM_CONDITIONAL([DEBUG], [test x$enable_debug = x"yes"])
|
||||
|
||||
# Options
|
||||
AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
|
||||
[path to systemd system service directory]), [path_systemdsystemunit=${withval}],
|
||||
[path_systemdsystemunit="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"])
|
||||
SYSTEMD_SYSTEMUNITDIR="${path_systemdsystemunit}"
|
||||
AC_SUBST(SYSTEMD_SYSTEMUNITDIR)
|
||||
AM_CONDITIONAL(SYSTEMD, test -n "${path_systemdsystemunit}")
|
||||
|
||||
|
||||
# Checks for library functions.
|
||||
|
||||
AC_OUTPUT
|
||||
19
data/cloud-init.service.in
Normal file
19
data/cloud-init.service.in
Normal file
@@ -0,0 +1,19 @@
|
||||
[Unit]
|
||||
Description=Initial cloud-init job (metadata service crawler)
|
||||
After=local-fs.target network.target
|
||||
Before=sshd.service sshd-keygen.service
|
||||
Requires=network.target
|
||||
Wants=local-fs.target sshd.service sshd-keygen.service
|
||||
ConditionFirstBoot=yes
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=@prefix@/bin/cloud-init --first-boot
|
||||
RemainAfterExit=yes
|
||||
TimeoutSec=0
|
||||
|
||||
# Output needs to appear in instance console output
|
||||
StandardOutput=journal+console
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
266
docs/cloud-config.5
Normal file
266
docs/cloud-config.5
Normal file
@@ -0,0 +1,266 @@
|
||||
'\" t
|
||||
.TH "CLOUDCONFIG" "5" "" "cloud-config 5" "cloud-config"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Define some portability stuff
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.\" http://bugs.debian.org/507673
|
||||
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * set default formatting
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" disable hyphenation
|
||||
.nh
|
||||
.\" disable justification (adjust text to left margin only)
|
||||
.ad l
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * MAIN CONTENT STARTS HERE *
|
||||
.\" -----------------------------------------------------------------
|
||||
.SH "NAME"
|
||||
cloud\-config \- User data format used by \fBcloud-init\fR(1)
|
||||
|
||||
.SH "SYNOPSIS"
|
||||
.PP
|
||||
cloud\-config data is provided by the cloud infrastructure to a cloud
|
||||
instance. This data is parsed by \fBcloud-init\fR(1) which then configures
|
||||
the cloud instance based on the information in the cloud-config.
|
||||
|
||||
.SH "DESCRIPTION"
|
||||
.PP
|
||||
The \fBcloud\-config\fR format is used to structure configuration data
|
||||
provided to the cloud instance. This data is structured in the YAML
|
||||
format (\fBhttp://yaml.org\fR). Note that \fBcloud\-init\fR(1) uses the
|
||||
libyaml library, which supports YAML version 1.1.
|
||||
|
||||
.PP
|
||||
In the YAML content, the root node (the document) contains a sequence of
|
||||
directives. These directives inform cloud-init that the content of the
|
||||
directive are processed by a directive-specific handler, or "module".
|
||||
|
||||
.PP
|
||||
cloud-init includes many modules, each expecting a specifically constructed
|
||||
content. This document lists the correct format and organization of each data
|
||||
section for the supported modules, describes their effect, and states
|
||||
various parameters for each option.
|
||||
|
||||
.PP
|
||||
Table of implemented directives. Column 3 ("Ref") and column 4 ("CoreOS")
|
||||
list whether the reference specification or the CoreOS implementation support
|
||||
these directives. Note that implementation details may differ, due to the
|
||||
underlying differences in Operating Systems.
|
||||
|
||||
.RS
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Directive Description Ref. CoreOS.
|
||||
_
|
||||
groups Configure user account groups yes no
|
||||
package_upgrade Perform a software update yes no
|
||||
packages Install additional software yes no
|
||||
runcmd Execute system commands yes no
|
||||
service Perform system service configuration no no
|
||||
ssh_authorized_keys Provision SSH public keys yes yes
|
||||
users Configure user accounts yes yes
|
||||
write_files Write content to arbitrary files yes yes
|
||||
_
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.SH "OPTIONS"
|
||||
.PP
|
||||
For each of the directives listed in the table above, zero or more options may
|
||||
be provided. The list below documents the implemented options per directive.
|
||||
The "Type" field values are:
|
||||
|
||||
.PP
|
||||
\fBTYPES\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb
|
||||
lfCW l l.
|
||||
Type Description
|
||||
_
|
||||
boolean Either true, false, yes, no, 0 or 1 (upper case and initial capitol
|
||||
letter versions treated identical)
|
||||
string A generic string encoded value. Can be multiline or YAML encoded
|
||||
content
|
||||
integer A string encoded decimal integer value
|
||||
octal A string encoded octal integer value
|
||||
hex A string encoded hexadecimal integer value
|
||||
[] if a type is listed with [] appended, it means there may be zero or
|
||||
more values, lists of values or any arbitrary depth of these nested
|
||||
* Indicates this value isn't a separate key, but directly the
|
||||
associated value of the root node. This is applicable for directives
|
||||
that only have a single configuration parameter,
|
||||
e.g. "package_upgrade"
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBgroups\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
name string[] no Create a new user account group and
|
||||
place listed user account names in
|
||||
that group
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBpackage_upgrade\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
* boolean yes Enables or disables whether software
|
||||
update is performed
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBpackages\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
name string[] no Enables installation of software bundles
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBruncmd\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
* string[] no Executes a script or program. The script
|
||||
schould be prepended with a standard
|
||||
shebang stanza to indicate interpreter
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBservice\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
start string[] no Start units
|
||||
stop string[] no Stop units
|
||||
restart string[] no Restart units
|
||||
enable string[] no Enable units to start automatically
|
||||
disable string[] no Disable units from starting automatically
|
||||
reload string[] no Reload service units
|
||||
isolate string[] no Change target to a new unit
|
||||
mask string[] no Prevent units from starting
|
||||
unmask string[] no Remove unit start prevention mask
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBssh_authorized_keys\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
* string[] no Specifies an SSH public key value, as
|
||||
string. This will be added to the default
|
||||
user account's SSH configuration
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBusers\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
* [] no This directive expects a list of user
|
||||
definitions. Each definition can
|
||||
additionally specify the following
|
||||
sub-options:
|
||||
_
|
||||
name string yes A user account name to be created
|
||||
gecos string no A real user name, can be left empty
|
||||
homedir string no A home directory path. Default under "/home"
|
||||
primary-group
|
||||
string no A group name.
|
||||
groups string no Comma-separated list of group names or
|
||||
single group name. Specifies additional
|
||||
groups to put this user account into
|
||||
lock-passwd
|
||||
boolean no Lock the user account
|
||||
inactive boolean no Mark the user account as inactive
|
||||
passwd string no Password hash for the user account
|
||||
no-create-home
|
||||
boolean no Omits creating a home directory
|
||||
no-user-group
|
||||
boolean no Omits group creating for the account
|
||||
no-log-init
|
||||
boolean no Omits this account from lastlog/faillog
|
||||
expiredate string no A date at which to expire the password
|
||||
ssh-authorized-keys
|
||||
string[] no Add SSH public keys to ssh configuration
|
||||
sudo string[] no Add sudoers lines for this account
|
||||
system boolean no Make the account a system account
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.PP
|
||||
\fBwrite_files\fR
|
||||
.RS 4
|
||||
.TS
|
||||
lb lb lb lb
|
||||
lfCW l l l l.
|
||||
Option Type Required Function
|
||||
_
|
||||
* [] no This directive expects a list of write_files
|
||||
definitions. Each definition itself contains the
|
||||
following options:
|
||||
_
|
||||
content string yes The content to write to a file
|
||||
path string yes The full path and filename of the file to
|
||||
be written out
|
||||
owner string no Username and optionally group name, separated
|
||||
by ":" or ".". Defaults to "root.root"
|
||||
permissions octal no Octal value describing the file permissions
|
||||
default value is influenced according to
|
||||
\fBumask\fR
|
||||
.TE
|
||||
.RE
|
||||
|
||||
.SH "COPYRIGHT"
|
||||
.PP
|
||||
Copyright 2015 Intel Corporation\&. License: Creative Commons
|
||||
Attribution\-ShareAlike 3.0 Unported\s-2\u[1]\d\s+2\&.
|
||||
|
||||
.SH "SEE ALSO"
|
||||
.PP
|
||||
\fBcloud-init\fB(1)
|
||||
|
||||
.SH "NOTES"
|
||||
.IP " 1." 4
|
||||
Creative Commons Attribution\-ShareAlike 3.0 Unported
|
||||
.RS 4
|
||||
\%http://creativecommons.org/licenses/by-sa/3.0/
|
||||
.RE
|
||||
96
docs/cloud-init.1
Normal file
96
docs/cloud-init.1
Normal file
@@ -0,0 +1,96 @@
|
||||
'\" t
|
||||
.TH "CLOUDINIT" "1" "" "cloud-init 1" "cloud-init"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Define some portability stuff
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.\" http://bugs.debian.org/507673
|
||||
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
|
||||
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
.ie \n(.g .ds Aq \(aq
|
||||
.el .ds Aq '
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * set default formatting
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" disable hyphenation
|
||||
.nh
|
||||
.\" disable justification (adjust text to left margin only)
|
||||
.ad l
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * MAIN CONTENT STARTS HERE *
|
||||
.\" -----------------------------------------------------------------
|
||||
.SH "NAME"
|
||||
cloud\-init \- Configures a cloud instance
|
||||
|
||||
.SH "SYNOPSIS"
|
||||
.HP \w'\fBcloud-init\fR\ 'u
|
||||
\fBcloud-init\fR [OPTIONS...]
|
||||
|
||||
.SH "DESCRIPTION"
|
||||
.PP
|
||||
\fBcloud-init\fR
|
||||
is run during first boot of a new cloud instance, with the purpose of
|
||||
configuring the cloud instance for use for the end user.
|
||||
.PP
|
||||
Various tasks can be performed, and all are optional. cloud-init parses
|
||||
the provided user-data and can create user accounds, user groups, register
|
||||
ssh keys, write content to files, perform software update or install new
|
||||
software, and more.
|
||||
.RE
|
||||
|
||||
.SH "OPTIONS"
|
||||
.PP
|
||||
The following options are understood:
|
||||
.PP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
.RS 4
|
||||
Prints a help message\&.
|
||||
.RE
|
||||
.PP
|
||||
\fB\-u\fR FILE, \fB\-\-user\-data\-file\fR FILE
|
||||
.RS 4
|
||||
Path to a cloud-config user data file\&. If omitted, \fBcloud-init\fR will
|
||||
attempt to fetch user-data from the openstack link-local connected data
|
||||
service URL.
|
||||
.RE
|
||||
.PP
|
||||
\fB\-b\fR, \fB\-\-first\-boot\fR
|
||||
.RS 4
|
||||
Performs various actions that are required to be performed during the
|
||||
first boot of the cloud instance, including (but not exclusively) the
|
||||
creation of a default user account ("clear").
|
||||
.RE
|
||||
.PP
|
||||
\fB\-v\fR, \fB\-\-version\fR
|
||||
.RS 4
|
||||
Prints version information\&.
|
||||
.RE
|
||||
|
||||
.SH "EXIT STATUS"
|
||||
.PP
|
||||
On success, 0 is returned, a non\-zero failure code otherwise\&.
|
||||
|
||||
.SH "COPYRIGHT"
|
||||
.PP
|
||||
Copyright 2015 Intel Corporation\&. License: Creative Commons
|
||||
Attribution\-ShareAlike 3.0 Unported\s-2\u[1]\d\s+2\&.
|
||||
|
||||
.SH "SEE ALSO"
|
||||
.PP
|
||||
This project is a limited-functionality implementation of the cloud-init
|
||||
specification. The full documentation of the generic implementation is
|
||||
available online and can be referenced here:
|
||||
.RS 4
|
||||
\fBhttps://cloudinit.readthedocs.org/en/latest/\fR
|
||||
.RE
|
||||
.PP
|
||||
The cloud-config format that \fBcloud-init\fR(1) supports is documented
|
||||
in \fBcloud-config\fR(5). This lists the options that are supported,
|
||||
their structure and function.
|
||||
|
||||
.SH "NOTES"
|
||||
.IP " 1." 4
|
||||
Creative Commons Attribution\-ShareAlike 3.0 Unported
|
||||
.RS 4
|
||||
\%http://creativecommons.org/licenses/by-sa/3.0/
|
||||
.RE
|
||||
109
examples/example1
Normal file
109
examples/example1
Normal file
@@ -0,0 +1,109 @@
|
||||
# Add groups to the system
|
||||
# The following example adds the ubuntu group with members foo and bar and
|
||||
# the group cloud-users.
|
||||
groups:
|
||||
- ubuntu: [foo,bar]
|
||||
- cloud-users
|
||||
|
||||
# Add users to the system. Users are added after groups are added.
|
||||
users:
|
||||
- default
|
||||
- name: foobar
|
||||
gecos: Foo B. Bar
|
||||
primary-group: foobar
|
||||
groups: users
|
||||
selinux-user: staff_u
|
||||
expiredate: 2012-09-01
|
||||
ssh-import-id: foobar
|
||||
lock-passwd: false
|
||||
passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
|
||||
- name: barfoo
|
||||
gecos: Bar B. Foo
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
groups: users, admin
|
||||
ssh-import-id: None
|
||||
lock-passwd: true
|
||||
ssh-authorized-keys:
|
||||
- <ssh pub key 1>
|
||||
- <ssh pub key 2>
|
||||
- name: cloudy
|
||||
gecos: Magic Cloud App Daemon User
|
||||
inactive: true
|
||||
system: true
|
||||
|
||||
# Valid Values:
|
||||
# name: The user's login name
|
||||
# gecos: The user name's real name, i.e. "Bob B. Smith"
|
||||
# homedir: Optional. Set to the local path you want to use. Defaults to
|
||||
# /home/<username>
|
||||
# primary-group: define the primary group. Defaults to a new group created
|
||||
# named after the user.
|
||||
# groups: Optional. Additional groups to add the user to. Defaults to none
|
||||
# selinux-user: Optional. The SELinux user for the user's login, such as
|
||||
# "staff_u". When this is omitted the system will select the default
|
||||
# SELinux user.
|
||||
# lock-passwd: Defaults to true. Lock the password to disable password login
|
||||
# inactive: Create the user as inactive
|
||||
# passwd: The hash -- not the password itself -- of the password you want
|
||||
# to use for this user. You can generate a safe hash via:
|
||||
# mkpasswd --method=SHA-512 --rounds=4096
|
||||
# (the above command would create from stdin an SHA-512 password hash
|
||||
# with 4096 salt rounds)
|
||||
#
|
||||
# Please note: while the use of a hashed password is better than
|
||||
# plain text, the use of this feature is not ideal. Also,
|
||||
# using a high number of salting rounds will help, but it should
|
||||
# not be relied upon.
|
||||
#
|
||||
# To highlight this risk, running John the Ripper against the
|
||||
# example hash above, with a readily available wordlist, revealed
|
||||
# the true password in 12 seconds on a i7-2620QM.
|
||||
#
|
||||
# In other words, this feature is a potential security risk and is
|
||||
# provided for your convenience only. If you do not fully trust the
|
||||
# medium over which your cloud-config will be transmitted, then you
|
||||
# should use SSH authentication only.
|
||||
#
|
||||
# You have thus been warned.
|
||||
# no-create-home: When set to true, do not create home directory.
|
||||
# no-user-group: When set to true, do not create a group named after the user.
|
||||
# no-log-init: When set to true, do not initialize lastlog and faillog database.
|
||||
# ssh-import-id: Optional. Import SSH ids
|
||||
# ssh-authorized-keys: Optional. [list] Add keys to user's authorized keys file
|
||||
# sudo: Defaults to none. Set to the sudo string you want to use, i.e.
|
||||
# ALL=(ALL) NOPASSWD:ALL. To add multiple rules, use the following
|
||||
# format.
|
||||
# sudo:
|
||||
# - ALL=(ALL) NOPASSWD:/bin/mysql
|
||||
# - ALL=(ALL) ALL
|
||||
# Note: Please double check your syntax and make sure it is valid.
|
||||
# cloud-init does not parse/check the syntax of the sudo
|
||||
# directive.
|
||||
# system: Create the user as a system user. This means no home directory.
|
||||
#
|
||||
|
||||
# Default user creation:
|
||||
#
|
||||
# Unless you define users, you will get a 'ubuntu' user on ubuntu systems with the
|
||||
# legacy permission (no password sudo, locked user, etc). If however, you want
|
||||
# to have the 'ubuntu' user in addition to other users, you need to instruct
|
||||
# cloud-init that you also want the default user. To do this use the following
|
||||
# syntax:
|
||||
# users:
|
||||
# - default
|
||||
# - bob
|
||||
# - ....
|
||||
# foobar: ...
|
||||
#
|
||||
# users[0] (the first user in users) overrides the user directive.
|
||||
#
|
||||
# The 'default' user above references the distro's config:
|
||||
# system_info:
|
||||
# default_user:
|
||||
# name: Ubuntu
|
||||
# plain_text_passwd: 'ubuntu'
|
||||
# home: /home/ubuntu
|
||||
# shell: /bin/bash
|
||||
# lock_passwd: True
|
||||
# gecos: Ubuntu
|
||||
# groups: [adm, audio, cdrom, dialout, floppy, video, plugdev, dip, netdev]
|
||||
32
examples/example2
Normal file
32
examples/example2
Normal file
@@ -0,0 +1,32 @@
|
||||
#cloud-config
|
||||
# vim: syntax=yaml
|
||||
#
|
||||
# This is the configuration syntax that the write_files module
|
||||
# will know how to understand. encoding can be given b64 or gzip or (gz+b64).
|
||||
# The content will be decoded accordingly and then written to the path that is
|
||||
# provided.
|
||||
#
|
||||
# Note: Content strings here are truncated for example purposes.
|
||||
write_files:
|
||||
- encoding: b64
|
||||
content: CiMgVGhpcyBmaWxlIGNvbnRyb2xzIHRoZSBzdGF0ZSBvZiBTRUxpbnV4...
|
||||
owner: root:root
|
||||
path: /etc/sysconfig/selinux
|
||||
permissions: '0644'
|
||||
- content: |
|
||||
# My new /etc/sysconfig/samba file
|
||||
|
||||
SMBDOPTIONS="-D"
|
||||
path: /etc/sysconfig/samba
|
||||
- content: !!binary |
|
||||
f0VMRgIBAQAAAAAAAAAAAAIAPgABAAAAwARAAAAAAABAAAAAAAAAAJAVAAAAAAAAAAAAAEAAOAAI
|
||||
AEAAHgAdAAYAAAAFAAAAQAAAAAAAAABAAEAAAAAAAEAAQAAAAAAAwAEAAAAAAADAAQAAAAAAAAgA
|
||||
AAAAAAAAAwAAAAQAAAAAAgAAAAAAAAACQAAAAAAAAAJAAAAAAAAcAAAAAAAAABwAAAAAAAAAAQAA
|
||||
....
|
||||
path: /bin/arch
|
||||
permissions: '0555'
|
||||
- encoding: gzip
|
||||
content: !!binary |
|
||||
H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA=
|
||||
path: /usr/bin/hello
|
||||
permissions: '0755'
|
||||
20
examples/example3
Normal file
20
examples/example3
Normal file
@@ -0,0 +1,20 @@
|
||||
#cloud-config
|
||||
# vim: syntax=yaml
|
||||
#
|
||||
# Add yum repository configuration to the system
|
||||
#
|
||||
# The following example adds the file /etc/yum.repos.d/epel_testing.repo
|
||||
# which can then subsequently be used by yum for later operations.
|
||||
yum_repos:
|
||||
# The name of the repository
|
||||
epel-testing:
|
||||
# Any repository configuration options
|
||||
# See: man yum.conf
|
||||
#
|
||||
# This one is required!
|
||||
baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch
|
||||
enabled: false
|
||||
failovermethod: priority
|
||||
gpgcheck: true
|
||||
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
|
||||
name: Extra Packages for Enterprise Linux 5 - Testing
|
||||
30
examples/example4
Normal file
30
examples/example4
Normal file
@@ -0,0 +1,30 @@
|
||||
#cloud-config
|
||||
#
|
||||
# This is an example file to configure an instance's trusted CA certificates
|
||||
# system-wide for SSL/TLS trust establishment when the instance boots for the
|
||||
# first time.
|
||||
#
|
||||
# Make sure that this file is valid yaml before starting instances.
|
||||
# It should be passed as user-data when starting the instance.
|
||||
|
||||
ca-certs:
|
||||
# If present and set to True, the 'remove-defaults' parameter will remove
|
||||
# all the default trusted CA certificates that are normally shipped with
|
||||
# Ubuntu.
|
||||
# This is mainly for paranoid admins - most users will not need this
|
||||
# functionality.
|
||||
remove-defaults: true
|
||||
|
||||
# If present, the 'trusted' parameter should contain a certificate (or list
|
||||
# of certificates) to add to the system as trusted CA certificates.
|
||||
# Pay close attention to the YAML multiline list syntax. The example shown
|
||||
# here is for a list of multiline certificates.
|
||||
trusted:
|
||||
- |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
YOUR-ORGS-TRUSTED-CA-CERT-HERE
|
||||
-----END CERTIFICATE-----
|
||||
- |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
YOUR-ORGS-TRUSTED-CA-CERT-HERE
|
||||
-----END CERTIFICATE-----
|
||||
20
examples/example5
Normal file
20
examples/example5
Normal file
@@ -0,0 +1,20 @@
|
||||
#cloud-config
|
||||
#
|
||||
# This is an example file to automatically configure resolv.conf when the
|
||||
# instance boots for the first time.
|
||||
#
|
||||
# Ensure that your yaml is valid and pass this as user-data when starting
|
||||
# the instance. Also be sure that your cloud.cfg file includes this
|
||||
# configuration module in the appropirate section.
|
||||
#
|
||||
manage-resolv-conf: true
|
||||
|
||||
resolv_conf:
|
||||
nameservers: ['8.8.4.4', '8.8.8.8']
|
||||
searchdomains:
|
||||
- foo.example.com
|
||||
- bar.example.com
|
||||
domain: example.com
|
||||
options:
|
||||
rotate: true
|
||||
timeout: 1
|
||||
1
examples/example6
Normal file
1
examples/example6
Normal file
@@ -0,0 +1 @@
|
||||
package_upgrade: True
|
||||
60
src/ccmodules.h
Normal file
60
src/ccmodules.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
/*
|
||||
* List existing modules so they can be registered from main.c
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern struct cc_module_handler_struct package_upgrade_cc_module;
|
||||
extern struct cc_module_handler_struct write_files_cc_module;
|
||||
extern struct cc_module_handler_struct packages_cc_module;
|
||||
extern struct cc_module_handler_struct groups_cc_module;
|
||||
extern struct cc_module_handler_struct users_cc_module;
|
||||
extern struct cc_module_handler_struct ssh_authorized_keys_cc_module;
|
||||
extern struct cc_module_handler_struct service_cc_module;
|
||||
|
||||
struct cc_module_handler_struct *cc_module_structs[] = {
|
||||
&package_upgrade_cc_module,
|
||||
&write_files_cc_module,
|
||||
&packages_cc_module,
|
||||
&groups_cc_module,
|
||||
&users_cc_module,
|
||||
&ssh_authorized_keys_cc_module,
|
||||
&service_cc_module,
|
||||
NULL
|
||||
};
|
||||
|
||||
82
src/ccmodules/groups.c
Normal file
82
src/ccmodules/groups.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "groups: "
|
||||
#define COMMAND_SIZE 256
|
||||
|
||||
static gboolean groups_item(GNode* node, gpointer data) {
|
||||
gchar command_groupadd[COMMAND_SIZE];
|
||||
gchar command_usermod[COMMAND_SIZE];
|
||||
|
||||
if (!node->data) {
|
||||
/* null placeholder */
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL,
|
||||
(GNodeForeachFunc)groups_item, NULL);
|
||||
} else if (!data) {
|
||||
/* add new group */
|
||||
LOG(MOD "Adding %s group...\n", (char*)node->data);
|
||||
g_snprintf(command_groupadd, COMMAND_SIZE, "groupadd -f %s",
|
||||
(char*)node->data);
|
||||
exec_task(command_groupadd);
|
||||
g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES, -1,
|
||||
groups_item, node->data);
|
||||
} else {
|
||||
/* add user to new group */
|
||||
LOG(MOD "Adding %s to %s group...\n", (char*)node->data, (char*)data);
|
||||
g_snprintf(command_usermod, COMMAND_SIZE, "usermod -a -G %s %s",
|
||||
(char*)data, (char*)node->data);
|
||||
exec_task(command_usermod);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void groups_handler(GNode *node) {
|
||||
LOG(MOD "Groups Handler running...\n");
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL,
|
||||
(GNodeForeachFunc)groups_item, NULL);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct groups_cc_module = {
|
||||
.name = "groups",
|
||||
.handler = &groups_handler
|
||||
};
|
||||
70
src/ccmodules/package_upgrade.c
Normal file
70
src/ccmodules/package_upgrade.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "package_upgrade: "
|
||||
|
||||
void package_upgrade_handler(GNode *node) {
|
||||
bool do_upgrade;
|
||||
|
||||
LOG(MOD "System Software Update Handler running...\n");
|
||||
GNode* val = g_node_first_child(node);
|
||||
if (!val) {
|
||||
LOG(MOD "Corrupt userdata!\n");
|
||||
return;
|
||||
}
|
||||
if (!cloud_config_bool(val, &do_upgrade)) {
|
||||
return;
|
||||
}
|
||||
if (do_upgrade) {
|
||||
LOG(MOD "Performing system software update.\n");
|
||||
exec_task("/usr/bin/swupd_update");
|
||||
} else {
|
||||
LOG(MOD "Skipping system software update.\n");
|
||||
}
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct package_upgrade_cc_module = {
|
||||
.name = "package_upgrade",
|
||||
.handler = &package_upgrade_handler
|
||||
};
|
||||
|
||||
68
src/ccmodules/packages.c
Normal file
68
src/ccmodules/packages.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "packages: "
|
||||
#define COMMAND_SIZE 256
|
||||
|
||||
static gboolean packages_item(GNode* node, gpointer data) {
|
||||
gchar command[COMMAND_SIZE];
|
||||
g_snprintf(command, COMMAND_SIZE, "/usr/bin/clr_bundle_add %s",
|
||||
(char*)node->data);
|
||||
LOG(MOD "Installing %s..\n", (char*)node->data);
|
||||
exec_task(command);
|
||||
return false;
|
||||
}
|
||||
|
||||
void packages_handler(GNode *node) {
|
||||
LOG(MOD "Packages Handler running...\n");
|
||||
/*
|
||||
* due to node possibly being a list of lists, just ignore all
|
||||
* non-leave nodes.
|
||||
*/
|
||||
g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, packages_item, NULL);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct packages_cc_module = {
|
||||
.name = "packages",
|
||||
.handler = &packages_handler
|
||||
};
|
||||
90
src/ccmodules/service.c
Normal file
90
src/ccmodules/service.c
Normal file
@@ -0,0 +1,90 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "service: "
|
||||
#define COMMAND_SIZE 2048
|
||||
|
||||
|
||||
static gboolean service_action(GNode* node, gpointer data) {
|
||||
gchar c[COMMAND_SIZE];
|
||||
g_snprintf(c, COMMAND_SIZE, "systemctl %s %s", (char*)data, (char*)node->data);
|
||||
exec_task(c);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void service_item(GNode* node, gpointer data) {
|
||||
if (!node->data) {
|
||||
node = node->children;
|
||||
} else {
|
||||
LOG(MOD "Unexpected non-sequence data at %s!\n", (char*)node->data);
|
||||
}
|
||||
|
||||
if (!node->children) {
|
||||
LOG(MOD "service action %s provided but no service name to apply action to\n!", (char*)node->data);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((g_strcmp0(node->data, "enable") != 0) &&
|
||||
(g_strcmp0(node->data, "disable") != 0) &&
|
||||
(g_strcmp0(node->data, "start") != 0) &&
|
||||
(g_strcmp0(node->data, "stop") != 0) &&
|
||||
(g_strcmp0(node->data, "restart") != 0) &&
|
||||
(g_strcmp0(node->data, "reload") != 0) &&
|
||||
(g_strcmp0(node->data, "isolate") != 0) &&
|
||||
(g_strcmp0(node->data, "mask") != 0) &&
|
||||
(g_strcmp0(node->data, "unmask") != 0)) {
|
||||
LOG(MOD "service action %s is not a valid service action\n", (char*)node->data);
|
||||
return;
|
||||
}
|
||||
|
||||
g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES, -1, service_action, node->data);
|
||||
}
|
||||
|
||||
void service_handler(GNode *node) {
|
||||
LOG(MOD "Service Handler running...\n");
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL, service_item, NULL);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct service_cc_module = {
|
||||
.name = "service",
|
||||
.handler = &service_handler
|
||||
};
|
||||
|
||||
116
src/ccmodules/ssh_authorized_keys.c
Normal file
116
src/ccmodules/ssh_authorized_keys.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
#include "default_user.h"
|
||||
|
||||
#define MOD "SSH authorized keys: "
|
||||
|
||||
|
||||
gboolean ssh_authorized_keys_write_ssh_key(const gchar* ssh_key, const gchar* username) {
|
||||
int fd;
|
||||
gchar auth_keys_path[PATH_MAX];
|
||||
struct passwd *pw;
|
||||
|
||||
pw = getpwnam(username);
|
||||
|
||||
if (pw && pw->pw_dir) {
|
||||
g_snprintf(auth_keys_path, PATH_MAX, "%s/.ssh", pw->pw_dir);
|
||||
|
||||
if (make_dir(auth_keys_path, S_IRWXU) != 0) {
|
||||
LOG(MOD "Cannot create %s.\n", auth_keys_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chown_path(auth_keys_path, username, username) != 0) {
|
||||
LOG(MOD "Cannot change the owner and group of %s.\n", auth_keys_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
g_strlcat(auth_keys_path, "/authorized_keys", PATH_MAX);
|
||||
fd = open(auth_keys_path, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
||||
if (-1 == fd) {
|
||||
LOG(MOD "Cannot open %s.\n", auth_keys_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG(MOD "Using %s\n", auth_keys_path);
|
||||
LOG(MOD "Writing %s\n", ssh_key);
|
||||
write(fd, ssh_key, strlen(ssh_key));
|
||||
write(fd, "\n", 1);
|
||||
close(fd);
|
||||
|
||||
if (chown_path(auth_keys_path, username, username) != 0) {
|
||||
LOG(MOD "Cannot change the owner and group of %s.\n", auth_keys_path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
gboolean ssh_authorized_keys_item(GNode* node, gpointer username) {
|
||||
if (ssh_authorized_keys_write_ssh_key(node->data, username)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ssh_authorized_keys_handler(GNode *node) {
|
||||
LOG(MOD "SSH authorized keys Handler running...\n");
|
||||
gchar *username = cloud_config_get_global("first_user");
|
||||
if (!username) {
|
||||
username = DEFAULT_USER_USERNAME;
|
||||
}
|
||||
|
||||
LOG(MOD "User %s\n", (char*)username);
|
||||
g_node_traverse(node, G_IN_ORDER, G_TRAVERSE_LEAVES,
|
||||
-1, ssh_authorized_keys_item, username);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct ssh_authorized_keys_cc_module = {
|
||||
.name = "ssh_authorized_keys",
|
||||
.handler = &ssh_authorized_keys_handler
|
||||
};
|
||||
224
src/ccmodules/users.c
Normal file
224
src/ccmodules/users.c
Normal file
@@ -0,0 +1,224 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "users: "
|
||||
#define COMMAND_SIZE 2048
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
static void users_add_username(GNode* node, char* command, gpointer data);
|
||||
static void users_add_option_format(GNode* node, char* command, gpointer data);
|
||||
static void users_add_option(GNode* node, char* command, gpointer data);
|
||||
static gboolean users_write_sudo(GNode* node, gpointer data);
|
||||
extern gboolean ssh_authorized_keys_item(GNode* node, gpointer username);
|
||||
|
||||
struct users_options_data {
|
||||
const gchar* key;
|
||||
void (*func)(GNode* node, char* command, gpointer data);
|
||||
gpointer data;
|
||||
};
|
||||
|
||||
static gchar users_current_username[LOGIN_NAME_MAX];
|
||||
|
||||
static struct users_options_data users_options[] = {
|
||||
{"name", users_add_username, " %s " },
|
||||
{"gecos", users_add_option_format, " -c '%s' " },
|
||||
{"homedir", users_add_option_format, " -d %s " },
|
||||
{"primary-group", users_add_option_format, " -g %s " },
|
||||
{"groups", users_add_option_format, " -G %s " },
|
||||
{"lock-passwd", NULL, NULL },
|
||||
{"inactive", NULL, NULL },
|
||||
{"passwd", users_add_option_format, " -p %s " },
|
||||
{"no-create-home", users_add_option, " -M , -m " },
|
||||
{"no-user-group", users_add_option, " -N , -U " },
|
||||
{"no-log-init", users_add_option, " -l ," },
|
||||
{"expiredate", users_add_option_format, " -e %s " },
|
||||
{"ssh-authorized-keys", NULL, NULL },
|
||||
{"sudo", NULL, NULL },
|
||||
{"system", users_add_option_format, " -r " },
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static void users_add_username(GNode* node, char* command, gpointer data) {
|
||||
char buffer[BUFFER_SIZE];
|
||||
g_snprintf(buffer, BUFFER_SIZE, data, node->data);
|
||||
g_strlcat(command, buffer, COMMAND_SIZE);
|
||||
|
||||
g_strlcpy(users_current_username, node->data, LOGIN_NAME_MAX);
|
||||
|
||||
if (!cloud_config_get_global("first_user")) {
|
||||
cloud_config_set_global("first_user", g_strdup(users_current_username));
|
||||
}
|
||||
}
|
||||
|
||||
static void users_add_option_format(GNode* node, char* command, gpointer data) {
|
||||
char buffer[BUFFER_SIZE];
|
||||
g_snprintf(buffer, BUFFER_SIZE, data, node->data);
|
||||
g_strlcat(command, buffer, COMMAND_SIZE);
|
||||
}
|
||||
|
||||
static void users_add_option(GNode* node, char* command, gpointer data) {
|
||||
bool b;
|
||||
gchar** tokens = g_strsplit(data, ",", 2);
|
||||
guint len = g_strv_length(tokens);
|
||||
cloud_config_bool(node, &b);
|
||||
if (b) {
|
||||
if (len > 0) {
|
||||
g_strlcat(command, tokens[0], COMMAND_SIZE);
|
||||
}
|
||||
} else {
|
||||
if (len > 1) {
|
||||
g_strlcat(command, tokens[1], COMMAND_SIZE);
|
||||
}
|
||||
}
|
||||
g_strfreev(tokens);
|
||||
}
|
||||
|
||||
static gboolean users_write_sudo(GNode* node, gpointer data) {
|
||||
int fd;
|
||||
gchar sudoers_file[PATH_MAX];
|
||||
g_snprintf(sudoers_file, PATH_MAX, "/etc/sudoers.d");
|
||||
if (make_dir(sudoers_file, S_IRUSR|S_IWUSR) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
g_strlcat(sudoers_file, "/cloud-init", PATH_MAX);
|
||||
fd = open(sudoers_file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
||||
if (-1 == fd) {
|
||||
LOG(MOD "Cannot open %s\n", sudoers_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
write(fd, node->data, strlen(node->data));
|
||||
write(fd, "\n", 1);
|
||||
|
||||
close(fd);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void users_item(GNode* node, gpointer data) {
|
||||
if (node->data) {
|
||||
/* to avoid bugs with key(gecos, etc) as username */
|
||||
if (node->children) {
|
||||
for (size_t i = 0; users_options[i].key != NULL; ++i) {
|
||||
if (0 == g_strcmp0(node->data, users_options[i].key)) {
|
||||
if (users_options[i].func) {
|
||||
users_options[i].func(node->children, data,
|
||||
users_options[i].data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG(MOD "No handler for %s.\n", (char*)node->data);
|
||||
return;
|
||||
}
|
||||
users_add_username(node, data, "%s");
|
||||
} else {
|
||||
bool b;
|
||||
gchar command[COMMAND_SIZE] = "useradd ";
|
||||
memset(users_current_username, 0, LOGIN_NAME_MAX);
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL, users_item, command);
|
||||
if (0 == strlen(users_current_username)) {
|
||||
LOG(MOD "Missing username.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(MOD "Adding %s user...\n", users_current_username);
|
||||
LOGD("Command: %s", command);
|
||||
exec_task(command);
|
||||
|
||||
CLOUD_CONFIG_KEY(LOCK_PASSWD, "lock-passwd");
|
||||
CLOUD_CONFIG_KEY(INACTIVE, "inactive");
|
||||
CLOUD_CONFIG_KEY(SSH_AUTH_KEYS, "ssh-authorized-keys");
|
||||
CLOUD_CONFIG_KEY(SUDO, "sudo");
|
||||
|
||||
GNode *item = cloud_config_find(node, LOCK_PASSWD);
|
||||
if (item) {
|
||||
cloud_config_bool(item, &b);
|
||||
if (b) {
|
||||
LOG(MOD "Locking %s user.\n", users_current_username);
|
||||
g_snprintf(command, COMMAND_SIZE, "passwd -l %s",
|
||||
users_current_username);
|
||||
LOGD("Command: %s\n", command);
|
||||
exec_task(command);
|
||||
}
|
||||
}
|
||||
|
||||
item = cloud_config_find(node, INACTIVE);
|
||||
if (item) {
|
||||
cloud_config_bool(item, &b);
|
||||
if (b) {
|
||||
LOG(MOD "Deactivating %s user...\n", users_current_username);
|
||||
g_snprintf(command, COMMAND_SIZE, "usermod --expiredate 1 %s",
|
||||
users_current_username);
|
||||
LOGD("Command: %s\n", command);
|
||||
exec_task(command);
|
||||
}
|
||||
}
|
||||
|
||||
item = cloud_config_find(node, SSH_AUTH_KEYS);
|
||||
if (item) {
|
||||
g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES,
|
||||
-1, ssh_authorized_keys_item, users_current_username);
|
||||
}
|
||||
|
||||
item = cloud_config_find(node, SUDO);
|
||||
if (item) {
|
||||
g_node_traverse(item->parent, G_IN_ORDER, G_TRAVERSE_LEAVES,
|
||||
-1, users_write_sudo, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void users_handler(GNode *node) {
|
||||
LOG(MOD "Users Handler running...\n");
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL, users_item, NULL);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct users_cc_module = {
|
||||
.name = "users",
|
||||
.handler = &users_handler
|
||||
};
|
||||
|
||||
122
src/ccmodules/write_files.c
Normal file
122
src/ccmodules/write_files.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "cloud_config.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "write_files: "
|
||||
|
||||
static void write_files_item(GNode* node, gpointer data) {
|
||||
const GNode* content;
|
||||
const GNode* path;
|
||||
const GNode* permissions;
|
||||
const GNode* owner;
|
||||
gchar **tokens;
|
||||
guint tokens_size;
|
||||
mode_t mode;
|
||||
const gchar* username = "";
|
||||
const gchar* groupname = "";
|
||||
|
||||
CLOUD_CONFIG_KEY(CONTENT, "content");
|
||||
CLOUD_CONFIG_KEY(PATH, "path");
|
||||
CLOUD_CONFIG_KEY(OWNER, "owner");
|
||||
CLOUD_CONFIG_KEY(PERMISSIONS, "permissions");
|
||||
|
||||
content = cloud_config_find(node, CONTENT);
|
||||
if (!content) {
|
||||
LOG(MOD "Unable to write file without \"content\" value.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
path = cloud_config_find(node, PATH);
|
||||
if (!path) {
|
||||
LOG(MOD "Unable to write file without \"path\" value.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
permissions = cloud_config_find(node, PERMISSIONS);
|
||||
owner = cloud_config_find(node, OWNER);
|
||||
|
||||
LOG(MOD "Writing to file %s: %s\n", (char*)path->data, (char*)content->data);
|
||||
|
||||
const int fd = open(path->data, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
if (fd == -1) {
|
||||
LOG(MOD "Cannot open %s.\n", (char*)path->data);
|
||||
return;
|
||||
}
|
||||
|
||||
write(fd, content->data, strlen(content->data));
|
||||
|
||||
if (permissions) {
|
||||
if (cloud_config_int_base(permissions, (int *)&mode, 8)) {
|
||||
fchmod(fd, mode);
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
if (owner) {
|
||||
tokens = g_strsplit_set(owner->data, ":.", 2);
|
||||
tokens_size = g_strv_length(tokens);
|
||||
if (tokens_size > 0) {
|
||||
username = tokens[0];
|
||||
if (tokens_size > 1) {
|
||||
groupname = tokens[1];
|
||||
}
|
||||
chown_path(path->data, username, groupname);
|
||||
}
|
||||
g_strfreev(tokens);
|
||||
}
|
||||
}
|
||||
|
||||
void write_files_handler(GNode *node) {
|
||||
LOG(MOD "Write Files Handler running...\n");
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL, write_files_item, NULL);
|
||||
}
|
||||
|
||||
struct cc_module_handler_struct write_files_cc_module = {
|
||||
.name = "write_files",
|
||||
.handler = &write_files_handler
|
||||
};
|
||||
|
||||
120
src/curl.c
Normal file
120
src/curl.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "curl.h"
|
||||
|
||||
#define MOD "curl: "
|
||||
|
||||
#ifdef DEBUG
|
||||
#define CURL_VERBOSE 1
|
||||
#define CURL_NO_PROGRESS 0
|
||||
#else
|
||||
#define CURL_VERBOSE 0
|
||||
#define CURL_NO_PROGRESS 1
|
||||
#endif /* DEBUG */
|
||||
|
||||
|
||||
gboolean curl_common_init(CURL** curl) {
|
||||
*curl = curl_easy_init();
|
||||
|
||||
if (!*curl) {
|
||||
LOG(MOD "Curl easy init failed\n");
|
||||
goto fail1;
|
||||
}
|
||||
if (curl_easy_setopt(*curl, CURLOPT_VERBOSE, CURL_VERBOSE) != CURLE_OK) {
|
||||
goto fail2;
|
||||
}
|
||||
if (curl_easy_setopt(*curl, CURLOPT_NOPROGRESS, CURL_NO_PROGRESS) != CURLE_OK) {
|
||||
goto fail2;
|
||||
}
|
||||
if (curl_easy_setopt(*curl, CURLOPT_PROXY, "") != CURLE_OK) {
|
||||
goto fail2;
|
||||
}
|
||||
if (curl_easy_setopt(*curl, CURLOPT_FAILONERROR, 1) != CURLE_OK) {
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
fail2:
|
||||
curl_easy_cleanup(*curl);
|
||||
fail1:
|
||||
return false;
|
||||
}
|
||||
|
||||
gchar* curl_fetch_file(CURL* curl, gchar* url, int attempts, useconds_t u_sleep) {
|
||||
int fd;
|
||||
FILE* file;
|
||||
gchar *filename;
|
||||
filename = g_strdup("/tmp/cloud-init-XXXXXX");
|
||||
fd = mkstemp(filename);
|
||||
file = fdopen(fd, "w");
|
||||
|
||||
if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK) {
|
||||
LOG(MOD "set url failed");
|
||||
goto fail1;
|
||||
}
|
||||
if (curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) != CURLE_OK) {
|
||||
LOG(MOD "set write data failed");
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < attempts; ++i) {
|
||||
LOG(MOD "%s attempt %d\n", url, i);
|
||||
if (curl_easy_perform(curl) == CURLE_OK) {
|
||||
fclose(file);
|
||||
return filename;
|
||||
}
|
||||
usleep(u_sleep);
|
||||
}
|
||||
|
||||
fail2:
|
||||
fclose(file);
|
||||
fail1:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
51
src/curl.h
Normal file
51
src/curl.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
/*
|
||||
* common initialization for CURL structures
|
||||
*/
|
||||
gboolean curl_common_init(CURL** curl);
|
||||
|
||||
/*
|
||||
* On success, the function returns a path to the file downloaded,
|
||||
* otherwise NULL is returned.
|
||||
*/
|
||||
gchar* curl_fetch_file(CURL* curl, gchar* url, int attempts, useconds_t u_sleep);
|
||||
42
src/datasources.h
Normal file
42
src/datasources.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern struct datasource_handler_struct openstack_datasource;
|
||||
|
||||
struct datasource_handler_struct *cloud_structs[] = {
|
||||
&openstack_datasource,
|
||||
NULL
|
||||
};
|
||||
215
src/datasources/openstack.c
Normal file
215
src/datasources/openstack.c
Normal file
@@ -0,0 +1,215 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "curl.h"
|
||||
#include "lib.h"
|
||||
#include "userdata.h"
|
||||
#include "json.h"
|
||||
#include "default_user.h"
|
||||
|
||||
#define MOD "openstack: "
|
||||
#define USERDATA_URL "http://169.254.169.254/openstack/latest/user_data"
|
||||
#define METADATA_URL "http://169.254.169.254/openstack/latest/meta_data.json"
|
||||
|
||||
int openstack_main(bool first_boot);
|
||||
|
||||
static int openstack_metadata(CURL* curl);
|
||||
static int openstack_userdata(CURL* curl);
|
||||
|
||||
static void openstack_item(GNode* node, gpointer data);
|
||||
|
||||
static void openstack_metadata_not_implemented(GNode* node);
|
||||
static void openstack_metadata_keys(GNode* node);
|
||||
static void openstack_metadata_hostname(GNode* node);
|
||||
static void openstack_metadata_public_keys(GNode* node);
|
||||
static void openstack_metadata_name(GNode* node);
|
||||
|
||||
|
||||
extern gboolean ssh_authorized_keys_write_ssh_key(const gchar* node, const gchar* username);
|
||||
|
||||
struct openstack_metadata_data {
|
||||
const gchar* key;
|
||||
void (*func)(GNode* node);
|
||||
};
|
||||
|
||||
static struct openstack_metadata_data openstack_metadata_options[] = {
|
||||
{"random_seed", openstack_metadata_not_implemented },
|
||||
{"uuid", openstack_metadata_not_implemented },
|
||||
{"availability_zone", openstack_metadata_not_implemented },
|
||||
{"keys", openstack_metadata_keys },
|
||||
{"hostname", openstack_metadata_hostname },
|
||||
{"launch_index", openstack_metadata_not_implemented },
|
||||
{"public_keys", openstack_metadata_public_keys },
|
||||
{"project_id", openstack_metadata_not_implemented },
|
||||
{"name", openstack_metadata_name },
|
||||
{"files", openstack_metadata_not_implemented },
|
||||
{"meta", openstack_metadata_not_implemented },
|
||||
{NULL}
|
||||
};
|
||||
|
||||
struct datasource_handler_struct openstack_datasource = {
|
||||
.datasource="openstack",
|
||||
.handler=&openstack_main
|
||||
};
|
||||
|
||||
int openstack_main(bool first_boot) {
|
||||
int result_code = EXIT_FAILURE;
|
||||
CURL* curl = NULL;
|
||||
|
||||
if (!curl_common_init(&curl)) {
|
||||
LOG(MOD "Curl initialize failed\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (first_boot) {
|
||||
if (openstack_metadata(curl) != EXIT_SUCCESS) {
|
||||
LOG(MOD "Get and process metadata fail\n");
|
||||
goto clean;
|
||||
}
|
||||
}
|
||||
|
||||
result_code = EXIT_SUCCESS;
|
||||
|
||||
if (openstack_userdata(curl) != EXIT_SUCCESS) {
|
||||
LOG(MOD "No userdata provided to this machine\n");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
clean:
|
||||
curl_easy_cleanup(curl);
|
||||
return result_code;
|
||||
}
|
||||
|
||||
static int openstack_userdata(CURL* curl) {
|
||||
int result_code;
|
||||
gchar* data_filename = NULL;
|
||||
|
||||
LOG(MOD "Fetching userdata file URL %s\n", USERDATA_URL );
|
||||
data_filename = curl_fetch_file(curl, USERDATA_URL, 1, 0);
|
||||
if (!data_filename) {
|
||||
LOG(MOD "Fetch userdata failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result_code = userdata_process_file(data_filename);
|
||||
g_free(data_filename);
|
||||
return result_code;
|
||||
}
|
||||
|
||||
static int openstack_metadata(CURL* curl) {
|
||||
GError* error = NULL;
|
||||
JsonParser* parser = NULL;
|
||||
gchar* data_filename = NULL;
|
||||
GNode* node = NULL;
|
||||
int result_code = EXIT_FAILURE;
|
||||
|
||||
parser = json_parser_new();
|
||||
LOG(MOD "Fetching metadata file URL %s\n", METADATA_URL );
|
||||
data_filename = curl_fetch_file(curl, METADATA_URL, 10, 300000);
|
||||
if (!data_filename) {
|
||||
LOG(MOD "Fetch metadata failed\n");
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
json_parser_load_from_file(parser, data_filename, &error);
|
||||
if (error) {
|
||||
LOG(MOD "Unable to parse '%s': %s\n", data_filename, error->message);
|
||||
g_error_free(error);
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
node = g_node_new(g_strdup(data_filename));
|
||||
json_parse(json_parser_get_root(parser), node, false);
|
||||
cloud_config_dump(node);
|
||||
|
||||
g_node_children_foreach(node, G_TRAVERSE_ALL, openstack_item, NULL);
|
||||
|
||||
result_code = EXIT_SUCCESS;
|
||||
|
||||
fail2:
|
||||
g_object_unref(parser);
|
||||
g_node_destroy(node);
|
||||
fail1:
|
||||
return result_code;
|
||||
}
|
||||
|
||||
static void openstack_item(GNode* node, gpointer data) {
|
||||
size_t i;
|
||||
if (node->data) {
|
||||
for (i = 0; openstack_metadata_options[i].key != NULL; ++i) {
|
||||
if (g_strcmp0(node->data, openstack_metadata_options[i].key) == 0) {
|
||||
LOG(MOD "Metadata using %s handler\n", (char*)node->data);
|
||||
openstack_metadata_options[i].func(node->children);
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG(MOD "Metadata no handler for %s.\n", (char*)node->data);
|
||||
}
|
||||
}
|
||||
|
||||
static void openstack_metadata_not_implemented(GNode* node) {
|
||||
LOG(MOD "Not implemented yet\n");
|
||||
}
|
||||
|
||||
static void openstack_metadata_keys(GNode* node) {
|
||||
while (node) {
|
||||
if (g_strcmp0("data", node->data) == 0) {
|
||||
LOG(MOD "keys processing %s\n", (char*)node->data);
|
||||
ssh_authorized_keys_write_ssh_key(node->children->data, DEFAULT_USER_USERNAME);
|
||||
} else {
|
||||
LOG(MOD "keys nothing to do with %s\n", (char*)node->data);
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void openstack_metadata_hostname(GNode* node) {
|
||||
LOG(MOD "Metadata hostname not implemented yet\n");
|
||||
}
|
||||
|
||||
static void openstack_metadata_public_keys(GNode* node) {
|
||||
LOG(MOD "Metadata public_keys not implemented yet\n");
|
||||
}
|
||||
|
||||
static void openstack_metadata_name(GNode* node) {
|
||||
LOG(MOD "Metadata name not implemented yet\n");
|
||||
}
|
||||
|
||||
59
src/debug.c
Normal file
59
src/debug.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
static gboolean node_dump(GNode *node, gpointer data) {
|
||||
fprintf(stderr, "debug: ");
|
||||
for (guint i = 0; i < g_node_depth(node); i++)
|
||||
fprintf(stderr, " ");
|
||||
fprintf(stderr, "[%d]:%s\n", g_node_depth(node), node ? (char*)node->data : "(null)");
|
||||
return(false);
|
||||
}
|
||||
|
||||
void cloud_config_dump(GNode *node) {
|
||||
fprintf(stderr, "debug: " "======== Dumping userdata GNode: ========\n");
|
||||
g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, node_dump, NULL);
|
||||
}
|
||||
#else
|
||||
void cloud_config_dump(GNode* node) {}
|
||||
#endif /* DEBUG */
|
||||
43
src/debug.h
Normal file
43
src/debug.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
void cloud_config_dump(GNode* node);
|
||||
71
src/default_user.h
Normal file
71
src/default_user.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef DEFAULT_USER_HOME_DIR
|
||||
#define DEFAULT_USER_HOME_DIR "/home/clear"
|
||||
#endif /* DEFAULT_USER_HOME_DIR */
|
||||
|
||||
#ifndef DEFAULT_USER_INACTIVE
|
||||
#define DEFAULT_USER_INACTIVE "-1"
|
||||
#endif /* DEFAULT_USER_INACTIVE */
|
||||
|
||||
#ifndef DEFAULT_USER_EXPIREDATE
|
||||
#define DEFAULT_USER_EXPIREDATE ""
|
||||
#endif /* DEFAULT_USER_EXPIREDATE */
|
||||
|
||||
#ifndef DEFAULT_USER_SHELL
|
||||
#define DEFAULT_USER_SHELL "/bin/bash"
|
||||
#endif /* DEFAULT_USER_SHELL */
|
||||
|
||||
#ifndef DEFAULT_USER_USERNAME
|
||||
#define DEFAULT_USER_USERNAME "clear"
|
||||
#endif /* DEFAULT_USER_USERNAME */
|
||||
|
||||
#ifndef DEFAULT_USER_GECOS
|
||||
#define DEFAULT_USER_GECOS "Clear Linux"
|
||||
#endif /* DEFAULT_USER_GECOS */
|
||||
|
||||
#ifndef DEFAULT_USER_PASSWORD
|
||||
#define DEFAULT_USER_PASSWORD ""
|
||||
#endif /* DEFAULT_USER_PASSWORD */
|
||||
|
||||
#ifndef DEFAULT_USER_SUDO
|
||||
#define DEFAULT_USER_SUDO "[\"ALL=(ALL) NOPASSWD:ALL\"]"
|
||||
#endif /* DEFAULT_USER_SUDO */
|
||||
53
src/handlers.h
Normal file
53
src/handlers.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct cc_module_handler_struct {
|
||||
gchar *name;
|
||||
void (*handler)(GNode *node);
|
||||
};
|
||||
|
||||
struct interpreter_handler_struct {
|
||||
gchar *shebang;
|
||||
int (*handler)(const gchar* filename);
|
||||
};
|
||||
|
||||
struct datasource_handler_struct {
|
||||
gchar *datasource;
|
||||
int (*handler)(bool first_boot);
|
||||
};
|
||||
44
src/interpreters.h
Normal file
44
src/interpreters.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern struct interpreter_handler_struct cloud_config_interpreter;
|
||||
extern struct interpreter_handler_struct shell_script_interpreter;
|
||||
|
||||
struct interpreter_handler_struct *interpreter_structs[] = {
|
||||
&cloud_config_interpreter,
|
||||
&shell_script_interpreter,
|
||||
NULL
|
||||
};
|
||||
312
src/interpreters/cloud_config.c
Normal file
312
src/interpreters/cloud_config.c
Normal file
@@ -0,0 +1,312 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <yaml.h>
|
||||
|
||||
#include "cloud_config.h"
|
||||
#include "handlers.h"
|
||||
#include "ccmodules.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define SEQ 1
|
||||
#define MAP 2
|
||||
#define VAL 4
|
||||
|
||||
static GHashTable *cloud_config_global_data = NULL;
|
||||
|
||||
static bool cloud_config_parse(yaml_parser_t *parser, GNode *data, int state);
|
||||
static gboolean cloud_config_simplify(GNode *node, gpointer data);
|
||||
static gboolean cloud_config_free(GNode *node, gpointer data);
|
||||
static void cloud_config_process(GNode *userdata, GList *handlers);
|
||||
|
||||
int cloud_config_main(const gchar* filename) {
|
||||
yaml_parser_t parser;
|
||||
GList* handlers = NULL;
|
||||
int i;
|
||||
|
||||
cloud_config_global_data = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
|
||||
LOG("Parsing user data file %s\n", filename);
|
||||
GNode* userdata = g_node_new(g_strdup(filename));
|
||||
FILE* cloud_config_file = fopen(filename, "rb");
|
||||
|
||||
yaml_parser_initialize(&parser);
|
||||
yaml_parser_set_input_file(&parser, cloud_config_file);
|
||||
cloud_config_parse(&parser, userdata, 0);
|
||||
yaml_parser_delete(&parser);
|
||||
fclose(cloud_config_file);
|
||||
|
||||
g_node_traverse(userdata, G_POST_ORDER, G_TRAVERSE_ALL, -1, cloud_config_simplify, NULL);
|
||||
|
||||
cloud_config_dump(userdata);
|
||||
|
||||
/* built-in handlers */
|
||||
for (i = 0; cc_module_structs[i] != NULL; ++i) {
|
||||
LOG("Loaded handler for block \"%s\"\n", cc_module_structs[i]->name);
|
||||
handlers = g_list_prepend(handlers, cc_module_structs[i]);
|
||||
}
|
||||
|
||||
cloud_config_process(userdata, handlers);
|
||||
|
||||
g_node_traverse(userdata, G_POST_ORDER, G_TRAVERSE_ALL, -1, cloud_config_free, NULL);
|
||||
g_node_destroy(userdata);
|
||||
|
||||
g_list_free(handlers);
|
||||
g_hash_table_destroy(cloud_config_global_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool cloud_config_bool(GNode* node, bool *b) {
|
||||
int i;
|
||||
const gchar *true_values[] = {"1", "true", "yes", "y", "on", NULL};
|
||||
const gchar *false_values[] = {"0", "false", "no", "n", "off", NULL};
|
||||
|
||||
for (i=0; true_values[i] != NULL; ++i) {
|
||||
if (g_ascii_strncasecmp(node->data, true_values[i],
|
||||
strlen(true_values[i])) == 0) {
|
||||
*b = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; false_values[i] != NULL; ++i) {
|
||||
if (g_ascii_strncasecmp(node->data, false_values[i],
|
||||
strlen(false_values[i])) == 0) {
|
||||
*b = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* unknown values: consider as "false" */
|
||||
LOG("Unknown bool string (\"%s\") interpreted as \"false\"\n", (char*)node->data);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cloud_config_int_base(const GNode* node, int *i, int base) {
|
||||
char *endptr;
|
||||
*i = (int)strtol(node->data, &endptr, base);
|
||||
if (errno == ERANGE) {
|
||||
fprintf(stderr, "Number %s is out of range.\n", (char*)node->data);
|
||||
return false;
|
||||
}
|
||||
if (strlen( endptr ) > 0) {
|
||||
fprintf(stderr, "String %s is not a valid number.\n", (char*)endptr);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cloud_config_int(const GNode* node, int *i) {
|
||||
return cloud_config_int_base(node, i, 10);
|
||||
}
|
||||
|
||||
GNode *cloud_config_find(GNode* node, gchar** path) {
|
||||
GNode* child;
|
||||
|
||||
if (!path) {
|
||||
if (g_node_depth(node) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
/* reached the end of our search, so return this node as value */
|
||||
return g_node_first_child(node);
|
||||
}
|
||||
|
||||
child = g_node_first_child(node);
|
||||
while (child) {
|
||||
if (g_strcmp0(child->data, path[0]) == 0) {
|
||||
/* recurse */
|
||||
return cloud_config_find(child, (gchar**)path[1]);
|
||||
}
|
||||
child = g_node_next_sibling(child);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cloud_config_set_global(gpointer key, gpointer value) {
|
||||
g_hash_table_insert(cloud_config_global_data, key, value);
|
||||
}
|
||||
|
||||
gpointer cloud_config_get_global(gpointer key) {
|
||||
return g_hash_table_lookup(cloud_config_global_data, key);
|
||||
}
|
||||
|
||||
static bool cloud_config_parse(yaml_parser_t *parser, GNode *node, int state) {
|
||||
GNode *last_leaf = node;
|
||||
yaml_event_t event;
|
||||
bool finished = 0;
|
||||
|
||||
while (!finished) {
|
||||
if (!yaml_parser_parse(parser, &event)) {
|
||||
LOG("An error occurred while the yaml file was parsed.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
|
||||
case YAML_SCALAR_EVENT:
|
||||
if (state & SEQ) {
|
||||
last_leaf = g_node_append(node, g_node_new(g_strdup((gchar*) event.data.scalar.value)));
|
||||
} else if (state & VAL) {
|
||||
g_node_append_data(last_leaf, g_strdup((gchar*) event.data.scalar.value));
|
||||
state &= MAP | SEQ;
|
||||
} else {
|
||||
last_leaf = g_node_append(node, g_node_new(g_strdup((gchar*) event.data.scalar.value)));
|
||||
state |= VAL;
|
||||
}
|
||||
break;
|
||||
|
||||
case YAML_SEQUENCE_START_EVENT:
|
||||
/* remove VAL bit if it's set */
|
||||
if (state & MAP)
|
||||
state = MAP;
|
||||
if (state & SEQ) {
|
||||
last_leaf = g_node_append(node, g_node_new(NULL));
|
||||
} else {
|
||||
last_leaf = g_node_append(last_leaf, g_node_new(NULL));
|
||||
}
|
||||
if (!cloud_config_parse(parser, last_leaf, SEQ)) {
|
||||
return false;
|
||||
}
|
||||
last_leaf = last_leaf->parent;
|
||||
break;
|
||||
|
||||
case YAML_SEQUENCE_END_EVENT:
|
||||
finished = true;
|
||||
break;
|
||||
|
||||
case YAML_MAPPING_START_EVENT:
|
||||
last_leaf = g_node_append(node, g_node_new(NULL));
|
||||
if (!cloud_config_parse(parser, last_leaf, MAP)) {
|
||||
return false;
|
||||
}
|
||||
last_leaf = last_leaf->parent;
|
||||
break;
|
||||
|
||||
case YAML_MAPPING_END_EVENT:
|
||||
last_leaf = last_leaf->parent;
|
||||
finished = true;
|
||||
break;
|
||||
|
||||
case YAML_STREAM_END_EVENT:
|
||||
finished = true;
|
||||
break;
|
||||
|
||||
case YAML_NO_TOKEN:
|
||||
LOG("Unexpectedly reached end of YAML input!");
|
||||
finished = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Ignore these for now */
|
||||
break;
|
||||
}
|
||||
|
||||
if (!finished) {
|
||||
yaml_event_delete(&event);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static gboolean cloud_config_free(GNode *node, gpointer data) {
|
||||
if (node->data) {
|
||||
g_free(node->data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void cloud_config_process(GNode *userdata, GList *handlers) {
|
||||
/* toplevel node is always a sequence, so skip over that sequence */
|
||||
userdata = g_node_first_child(userdata);
|
||||
|
||||
/* loop over all toplevel elements and find modules to handle them */
|
||||
for (guint i = 0; i < g_node_n_children(userdata); i++) {
|
||||
GNode *node = g_node_nth_child(userdata, i);
|
||||
struct cc_module_handler_struct* h;
|
||||
bool found = false;
|
||||
|
||||
for (guint j = 0; j < g_list_length(handlers); j++) {
|
||||
h = g_list_nth_data(handlers, j);
|
||||
if (g_strcmp0(h->name, node->data) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
LOG("Executing handler for block \"%s\"\n", (char*)node->data);
|
||||
h->handler(node);
|
||||
} else {
|
||||
LOG("No handler found for block \"%s\"\n", (char*)node->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean cloud_config_simplify(GNode *node, gpointer data) {
|
||||
if (node->data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GNode *child = g_node_last_child(node);
|
||||
while (child) {
|
||||
if (child->data) {
|
||||
child = g_node_prev_sibling(child);
|
||||
continue;
|
||||
}
|
||||
GNode *remove = child;
|
||||
child = g_node_prev_sibling(child);
|
||||
g_node_append(node->parent, g_node_copy(remove));
|
||||
g_node_unlink(remove);
|
||||
}
|
||||
|
||||
if (g_node_n_children(node) == 0) {
|
||||
g_node_unlink(node);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct interpreter_handler_struct cloud_config_interpreter = {
|
||||
.shebang = "#cloud-config",
|
||||
.handler = &cloud_config_main
|
||||
};
|
||||
57
src/interpreters/cloud_config.h
Normal file
57
src/interpreters/cloud_config.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <yaml.h>
|
||||
#include <glib.h>
|
||||
|
||||
/*
|
||||
* Macro helper - allows for easy retrieval of node data.
|
||||
* Use as follows:
|
||||
* CLOUD_CONFIG_KEY(NAME_OF_KEY, "PATHPART1", "PATHPART2" ......)
|
||||
*/
|
||||
#define CLOUD_CONFIG_KEY(name, ...) gchar* name[] = { __VA_ARGS__, 0}
|
||||
|
||||
bool cloud_config_bool(GNode* node, bool *b);
|
||||
|
||||
bool cloud_config_int(const GNode* node, int *i);
|
||||
|
||||
bool cloud_config_int_base(const GNode* node, int *i, int base);
|
||||
|
||||
GNode *cloud_config_find(GNode* node, gchar** path);
|
||||
|
||||
void cloud_config_set_global(gpointer key, gpointer value);
|
||||
gpointer cloud_config_get_global(gpointer option);
|
||||
66
src/interpreters/shell_script.c
Normal file
66
src/interpreters/shell_script.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <yaml.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "lib.h"
|
||||
|
||||
#define MOD "shell_script: "
|
||||
|
||||
int shell_script_main(const gchar* filename) {
|
||||
gchar full_path[PATH_MAX];
|
||||
if (!realpath(filename, full_path)) {
|
||||
LOG(MOD "Cannot get real path file %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (chmod(full_path, S_IRUSR|S_IWUSR|S_IXUSR) != 0) {
|
||||
LOG(MOD "Cannot execute file %s\n", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
exec_task(full_path);
|
||||
return 0; //FIXME replace with defined constants
|
||||
}
|
||||
|
||||
struct interpreter_handler_struct shell_script_interpreter = {
|
||||
.shebang = "#!",
|
||||
.handler = &shell_script_main
|
||||
};
|
||||
123
src/json.c
Normal file
123
src/json.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
|
||||
gchar* json_string(JsonNode* node) {
|
||||
gchar buffer[64];
|
||||
GType valueType = json_node_get_value_type(node);
|
||||
|
||||
switch (valueType) {
|
||||
case G_TYPE_STRING:
|
||||
return json_node_dup_string(node);
|
||||
|
||||
case G_TYPE_INT:
|
||||
sprintf(buffer, "%d", (int)json_node_get_int(node));
|
||||
break;
|
||||
|
||||
case G_TYPE_DOUBLE:
|
||||
sprintf(buffer, "%f", json_node_get_double(node));
|
||||
break;
|
||||
|
||||
case G_TYPE_BOOLEAN:
|
||||
if (json_node_get_boolean(node)) {
|
||||
sprintf(buffer, "%s", "true");
|
||||
} else {
|
||||
sprintf(buffer, "%s", "false");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
sprintf(buffer, "%s", "Unknown type");
|
||||
break;
|
||||
}
|
||||
|
||||
return g_strdup(buffer);
|
||||
}
|
||||
|
||||
void json_parse(JsonNode* root, GNode* node, bool parsing_array) {
|
||||
if (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT) {
|
||||
JsonObject *object = json_node_get_object(root);
|
||||
|
||||
if (object) {
|
||||
int j;
|
||||
guint size;
|
||||
GList* keys, *key = NULL;
|
||||
GList* values, *value = NULL;
|
||||
|
||||
size = json_object_get_size(object);
|
||||
keys = json_object_get_members(object);
|
||||
values = json_object_get_values(object);
|
||||
node = g_node_append(node, g_node_new(NULL));
|
||||
|
||||
for (j = 0, key = keys, value = values; j < size; j++) {
|
||||
if (key) {
|
||||
node = g_node_append(node->parent, g_node_new(g_strdup(key->data)));
|
||||
}
|
||||
if (value) {
|
||||
json_parse(value->data, node, false);
|
||||
}
|
||||
|
||||
key = g_list_next(key);
|
||||
value = g_list_next(value);
|
||||
}
|
||||
|
||||
if (keys) {
|
||||
g_list_free(keys);
|
||||
}
|
||||
if (values) {
|
||||
g_list_free(values);
|
||||
}
|
||||
}
|
||||
} else if (JSON_NODE_TYPE(root) == JSON_NODE_ARRAY) {
|
||||
JsonArray* array = json_node_get_array(root);
|
||||
guint array_size = json_array_get_length (array);
|
||||
JsonNode *array_element;
|
||||
|
||||
for (guint i = 0; i < array_size; i++) {
|
||||
array_element = json_array_get_element(array, i);
|
||||
json_parse(array_element, node, true);
|
||||
}
|
||||
} else if (JSON_NODE_TYPE(root) == JSON_NODE_VALUE) {
|
||||
node = g_node_append(node, g_node_new(json_string(root)));
|
||||
|
||||
if (parsing_array) {
|
||||
node = g_node_append(node, g_node_new(NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/json.h
Normal file
40
src/json.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
|
||||
void json_parse(JsonNode* root, GNode* node, bool parsing_array);
|
||||
98
src/lib.c
Normal file
98
src/lib.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
/*
|
||||
* lib.c - collection of misc functions for modules to do work
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#define MOD "lib: "
|
||||
|
||||
void LOG(const char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void exec_task(const gchar* task) {
|
||||
/*
|
||||
* execute a process externally in a secured and limited enviroment,
|
||||
* handle return values gracefully
|
||||
*/
|
||||
LOG(MOD "Executing: %s\n", task);
|
||||
system(task);
|
||||
}
|
||||
|
||||
int make_dir(const char* pathname, mode_t mode) {
|
||||
struct stat stats;
|
||||
if (stat(pathname, &stats) != 0) {
|
||||
if (mkdir(pathname, mode) != 0) {
|
||||
LOG(MOD "Cannot create directory %s\n", pathname);
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR (stats.st_mode)) {
|
||||
LOG(MOD "%s already exists and is not a directory.\n",
|
||||
pathname);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chown_path(const char* pathname, const char* ownername, const char* groupname) {
|
||||
uid_t owner_id;
|
||||
gid_t group_id;
|
||||
struct passwd *pw;
|
||||
struct group *grp;
|
||||
|
||||
pw = getpwnam(ownername);
|
||||
owner_id = pw ? pw->pw_uid : (uid_t) - 1;
|
||||
grp = getgrnam(groupname);
|
||||
group_id = grp ? grp->gr_gid : (gid_t) - 1;
|
||||
|
||||
return chown(pathname, owner_id, group_id);
|
||||
}
|
||||
54
src/lib.h
Normal file
54
src/lib.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define STRINGIZE_DETAIL(x) #x
|
||||
#define STRINGIZE(x) STRINGIZE_DETAIL(x)
|
||||
#define LOGD(...) LOG(__BASE_FILE__":"STRINGIZE(__LINE__)" - "__VA_ARGS__)
|
||||
#else
|
||||
#define LOGD(...)
|
||||
#define cloud_config_dump(...)
|
||||
#endif /* DEBUG */
|
||||
|
||||
void exec_task(const gchar* task);
|
||||
void LOG(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
int make_dir(const char* pathname, mode_t mode);
|
||||
int chown_path(const char* pathname, const char* ownername, const char* groupname);
|
||||
142
src/main.c
Normal file
142
src/main.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Auke-jan H. Kok <auke-jan.h.kok@intel.com>
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "handlers.h"
|
||||
#include "lib.h"
|
||||
#include "userdata.h"
|
||||
#include "datasources.h"
|
||||
#include "default_user.h"
|
||||
|
||||
static struct option opts[] = {
|
||||
{ "user-data-file", 1, NULL, 'u' },
|
||||
{ "help", 0, NULL, 'h' },
|
||||
{ "version", 0, NULL, 'v' },
|
||||
{ "first-boot", 0, NULL, 'b' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int result_code = EXIT_SUCCESS;
|
||||
gchar *userdata_filename = NULL;
|
||||
bool first_boot = false;
|
||||
int c;
|
||||
int i;
|
||||
|
||||
while (true) {
|
||||
c = getopt_long(argc, argv, "u:hvb", opts, &i);
|
||||
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
|
||||
case 'u':
|
||||
userdata_filename = g_strdup(optarg);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
LOG("Usage: %s [options]\n", argv[0]);
|
||||
LOG("-u, --user-data-file [file] specify a custom user data file\n");
|
||||
LOG("-h, --help display this help message\n");
|
||||
LOG("-v, --version display the version number of this program\n");
|
||||
LOG("-b, --first-boot set up the system in its first boot (create default user, etc)\n");
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
fprintf(stdout, PACKAGE_NAME " " PACKAGE_VERSION "\n");
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
first_boot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
LOG("clr-cloud-init version: %s\n", PACKAGE_VERSION);
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
/* at one point in time this should likely be a fatal error */
|
||||
if (geteuid() != 0) {
|
||||
LOG("%s isn't running as root, this will most likely fail!\n", argv[0]);
|
||||
}
|
||||
|
||||
if (first_boot) {
|
||||
/* default user will be used by ccmodules and datasources */
|
||||
char useradd_command[LINE_MAX] = { 0 };
|
||||
snprintf(useradd_command, LINE_MAX, "useradd"
|
||||
" -U -d '%s' -f '%s' -e '%s' -s '%s' -c '%s' -p '%s' '%s'"
|
||||
, DEFAULT_USER_HOME_DIR
|
||||
, DEFAULT_USER_INACTIVE
|
||||
, DEFAULT_USER_EXPIREDATE
|
||||
, DEFAULT_USER_SHELL
|
||||
, DEFAULT_USER_GECOS
|
||||
, DEFAULT_USER_PASSWORD
|
||||
, DEFAULT_USER_USERNAME);
|
||||
|
||||
exec_task(useradd_command);
|
||||
|
||||
//FIXME: implement sudo (DEFAULT_USER_SUDO)
|
||||
}
|
||||
|
||||
if (!userdata_filename) {
|
||||
/* get/process userdata and metadata from datasources */
|
||||
for (i = 0; cloud_structs[i] != NULL; ++i) {
|
||||
result_code = cloud_structs[i]->handler(first_boot);
|
||||
if (EXIT_SUCCESS == result_code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result_code = userdata_process_file(userdata_filename);
|
||||
}
|
||||
|
||||
exit(result_code);
|
||||
}
|
||||
67
src/userdata.c
Normal file
67
src/userdata.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "interpreters.h"
|
||||
#include "handlers.h"
|
||||
|
||||
#define MOD "userdata: "
|
||||
|
||||
int userdata_process_file(const gchar* filename) {
|
||||
char shebang[LINE_MAX] = { 0 };
|
||||
|
||||
LOG(MOD "Looking for shebang file %s\n", filename);
|
||||
FILE *userdata_file = fopen(filename, "rb");
|
||||
fgets(shebang, LINE_MAX, userdata_file);
|
||||
fclose(userdata_file);
|
||||
LOG(MOD "Shebang found %s\n", shebang);
|
||||
|
||||
/* built-in interpreters */
|
||||
for (int i = 0; interpreter_structs[i] != NULL; ++i) {
|
||||
if (g_str_has_prefix(shebang, interpreter_structs[i]->shebang)) {
|
||||
return interpreter_structs[i]->handler(filename);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(MOD "No interpreter found for %s\n", shebang);
|
||||
//FIXME define return codes, not use magic numbers
|
||||
return 1;
|
||||
}
|
||||
39
src/userdata.h
Normal file
39
src/userdata.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/***
|
||||
Copyright (C) 2015 Intel Corporation
|
||||
|
||||
Author: Julio Montes <julio.montes@intel.com>
|
||||
|
||||
This file is part of clr-cloud-init.
|
||||
|
||||
clr-cloud-init is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
clr-cloud-init is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with clr-cloud-init. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
In addition, as a special exception, the copyright holders give
|
||||
permission to link the code of portions of this program with the
|
||||
OpenSSL library under certain conditions as described in each
|
||||
individual source file, and distribute linked combinations
|
||||
including the two.
|
||||
You must obey the GNU General Public License in all respects
|
||||
for all of the code used other than OpenSSL. If you modify
|
||||
file(s) with this exception, you may extend this exception to your
|
||||
version of the file(s), but you are not obligated to do so. If you
|
||||
do not wish to do so, delete this exception statement from your
|
||||
version. If you delete this exception statement from all source
|
||||
files in the program, then also delete it here.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
int userdata_process_file(const gchar* filename);
|
||||
62
test.yaml
Normal file
62
test.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
#cloud-config
|
||||
package_upgrade: true
|
||||
package_upgrade: false
|
||||
apt_upgrade: false
|
||||
write_files:
|
||||
-
|
||||
content: |
|
||||
A test file
|
||||
path: /tmp/cloud-init-test-1
|
||||
owner: nobody.nogroup
|
||||
permissions: 0644
|
||||
-
|
||||
content: |
|
||||
Another test file
|
||||
path: /tmp/cloud-init-test-2
|
||||
owner: root.root
|
||||
permissions: 0600
|
||||
packages:
|
||||
- openstack-configure
|
||||
- perl-basic
|
||||
- os-core-dev
|
||||
- [kernel-kvm, kvm-host]
|
||||
groups:
|
||||
- cloud-init: [nobody, games]
|
||||
runcmd:
|
||||
- [ ls, -l, / ]
|
||||
- [ sh, -xc, "echo $(date) ': hello world!'" ]
|
||||
- [ sh, -c, echo "=========hello world'=========" ]
|
||||
- ls -l /root
|
||||
- [ wget, "http://slashdot.org", -O, /tmp/index.html ]
|
||||
users:
|
||||
- name: foobar
|
||||
gecos: Foo B. Bar
|
||||
homedir: /home/foobar
|
||||
primary-group: foobar
|
||||
groups: users
|
||||
selinux-user: staff_u
|
||||
lock-passwd: false
|
||||
ssh-import-id: foobar
|
||||
inactive: true
|
||||
passwd: $6$j212wezy$7H/1LT4f9/N3wpgNunhsIqtMj62OKiS3nyNwuizouQc3u7MbYCarYeAHWYPYb2FT.lbioDm2RrkJPb9BZMN1O/
|
||||
no-create-home: true
|
||||
no-user-group: true
|
||||
no-log-init: true
|
||||
expiredate: 2015-12-31
|
||||
ssh-authorized-keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmHRP+1o+vBSg+ej714Y3iO5Osbr29dHL/WZQlsj
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9GNA2I6IU+II1qoKP1Ttn/eNv8zquEDNii+EA5m
|
||||
sudo:
|
||||
- [ "ALL=(ALL) NOPASSWD:ALL", "ALL=(ALL) NOPASSWD:/bin/mysql" ]
|
||||
- ALL=(ALL) NOPASSWD:ALL
|
||||
system: true
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa BBBBB3NzaC1yc2EAAAADAQABAAABAQDmHRP+0000000000000000000000000000000000
|
||||
- ssh-rsa BBBBB3NzaC1yc2EAAAADAQABAAABAQC9GNA21111111111111111111111111111111111
|
||||
service:
|
||||
- start: dbus0
|
||||
- start: [ foo1, bar2 ]
|
||||
- stop:
|
||||
- foo3
|
||||
- bar4
|
||||
- [ foo5, bar6 ]
|
||||
Reference in New Issue
Block a user