224 Commits

Author SHA1 Message Date
Claudiu Popa
afacc4881a Add the base classes for the new OS utils architecture
The base classes follows the OS utils architecture spec.

Change-Id: I1365e6c9de20dccc905e35113ccdea03f2a03f1b
2015-04-27 15:41:16 +03:00
Scott Moser
c81466ce76 initial tree for 2.0 work 2015-01-21 10:00:26 -05:00
Joshua Harlow
9a6a0d150f Pretty up the debug module
Previously the usage of the yaml_dumps module was causing
any python unicode key and value to show up as:

'item': !!python/unicode "some string"

This was not very pretty...

Fix this by using safe_dumps (which is also a good thing to
use and allow_unicode=True). Also create a tiny helper function
in the cc_debug module that does not include the yaml start and
end footers (since this module has its own footers and headers).

Also includes a basic sanity test for this module.
2014-11-21 18:10:16 -08:00
Joshua Harlow
b7bd69ab21 Increase the robustness/configurability of the chef module...
Add the following adjustments to the chef template and module:

- Make it so that the chef directories can be provided (defaults
  to the existing directories)
- Make the params much more configurable, and if a parameter is
  provided in the chef configuration it will override existing template
  parameters.
- Make the template skip lines if the values are None in the configuration
  so that template lines can be removed if/when this is desirable.
- Allow the firstboot json path to be configurable (defaults to the
  existing location).
- Adds a basic set of tests to ensure that good things are happening.
- Make a helper function to tell if already installed.
- Have the install routine not run chef after installed but have it instead
  return a result to tell the caller to run the chef program once completed.
- Use the generated_by() utility function to give the ruby template a
  better header comment.
- Set special parameters after selecting the basic chef parameters.
- Allow for the running after install and run arguments to be configured.
- Allow the omnibus url fetching retries to be configurable.
- Move the chef running to its own helper function
- Add module docs
2014-11-21 17:15:24 -08:00
Scott Moser
a33f97f744 fix bad logic resulting in failure to honor 'output' config.
This busted logic causes 'output' to not be paid any attention
to, and thus output is not written to /var/log/cloud-init-output.log.
2014-10-29 15:39:04 -04:00
Joshua Harlow
7e7ce81fb8 Pretty up the debug module
Previously the usage of the yaml_dumps module was causing
any python unicode key and value to show up as:

'item': !!python/unicode "some string"

This was not very pretty...

Fix this by using safe_dumps (which is also a good thing to
use and allow_unicode=True). Also create a tiny helper function
in the cc_debug module that does not include the yaml start and
end footers (since this module has its own footers and headers).

Also includes a basic sanity test for this module.
2014-10-18 09:27:47 -07:00
Joshua Harlow
9691d100bc Allow the omnibus url fetching retries to be configurable 2014-10-11 18:23:20 -07:00
Joshua Harlow
6fd4b89088 Fix newline added at end of file 2014-10-10 17:40:10 -07:00
Joshua Harlow
d991a9f26e Undo changes to the util file, not sure why that happened... 2014-10-10 17:34:32 -07:00
Joshua Harlow
42faf0279f Increase the robustness of the chef module
Add the following adjustments to the chef template and module

- Make it so that the chef directories can be provided (defaults
  to the existing directories)
- Make the params much more configurable, and if a parameter is
  provided in the chef configuration it will override existing template
  parameters.
- Make the template skip lines if the values are None in the configuration
  so that template lines can be removed if/when this is desirable.
- Allow the firstboot json path to be configurable (defaults to the
  existing location).
- Adds a basic set of tests to ensure that good things are happening.
2014-10-10 17:27:56 -07:00
Scott Moser
5264812bba support human2bytes, separate handling out to method 2014-09-30 16:24:54 -04:00
Scott Moser
619d76746d add code for setting up swap file 2014-09-30 16:01:00 -04:00
Scott Moser
3d1ac485ef further platform cleanup 2014-09-29 08:55:08 -04:00
Scott Moser
8a55c52441 fix re-use of 'platform' in local scope 2014-09-29 08:42:20 -04:00
Scott Moser
d0388b5500 support 'mtype' as a list, and fix up freebsd mount types
this supports a list of input, and cleans up that list
for the platform specific mount types.  Basically,
 mtype = None
 means 'mount -t auto' or the equivalent for the platform.

and 'iso9660' means "iso type".
2014-09-22 14:35:03 -04:00
Scott Moser
83f5720a31 merge from trunk 2014-09-22 14:00:39 -04:00
Scott Moser
5d28234060 merge from trunk 2014-09-15 20:13:07 -04:00
Jay Faulkner
6c278ee495 Remove pylint: lines 2014-09-15 15:10:17 -07:00
Jay Faulkner
170dbd50eb Fix bug 1338614
util.log_time()'s return value was what was being sent to fork_cb. This means
the resize ran in parallel and the call to fork_cb threw a traceback (trying
to call Nonetype).

By permitting fork_cb to take kwargs, and using the correct method syntax,
this now forks and resizes in the background as appropriate.
2014-09-15 14:39:57 -07:00
Scott Moser
6b2fc2034a further remove evidence of pylint.
This just removes comments '# pylint:' things and other code
remnents of pylint.
2014-08-26 15:53:41 -04:00
Jay Faulkner
18d1aea913 fix(pep8): Fix various pep8 violations and version-lock pep8
Fixed all complaints from running "make pep8". Also version locked
pep8 in test-requirements.txt to ensure that pep8 requirements don't
change without an explicit commit.
2014-08-26 11:50:11 -07:00
Joseph Bajin
d4f20c77ad Removed using lazy mode for umount
Safer for cloud-init to not use lazy mode for unmount
2014-08-23 14:04:00 -04:00
Joseph Bajin
f71e050f44 fix: Updated some syntax to be pep8 compliant 2014-08-18 11:16:45 -04:00
Joseph Bajin
f511595680 new: Added FreeBSD support to ConfigDrive 2014-08-18 10:32:54 -04:00
Scott Moser
bd7e0e604e SeLinuxGuard: remove invalid check for sanity around restorecon, fix test
previous commit occurred because the selinux test was failing
in a schroot where there was no /etc/hosts.

Now, fix that test more correctly, and fix some bad assumptions in
the SeLinuxGuard.
2014-07-24 19:41:10 -04:00
Scott Moser
1040327b59 fixes from testing, force symlink 2014-02-24 17:20:12 -05:00
Joshua Harlow
f6c2b3e6b5 Remerged with trunk 2014-02-07 15:14:26 -08:00
Joshua Harlow
97fe498e45 Add a openstack specific datasource
Openstack has a unique derivative datasource
that is gaining usage. Previously the config
drive datasource provided part of this functionality
as well as the ec2 datasource, but since new
functionality is being added to openstack is
seems benefical to combine the used parts into
one datasource just made for handling openstack
deployments.

This patch factors out the common logic shared
between the config drive and the openstack
metadata datasource and places that in a shared
helper file and then creates a new openstack
datasource that readers from the openstack metadata
service and refactors the config drive datasource
to use this common logic.
2014-02-01 22:48:55 -08:00
Scott Moser
a6cd0e8a3c merge from trunk 2014-01-29 14:31:47 -05:00
Scott Moser
a194a24d52 cloudinit/util.py: fix pylint complaints 2014-01-28 14:04:06 -05:00
Vlastimil Holer
76e73c9a2f Allow zeros when detecting IPv4 address (e.g. 192.168.0.1) 2014-01-28 19:09:46 +01:00
Scott Moser
20c9edf01f add 'pathprefix2dict' utility for use by DataSourceNoCloud 2014-01-27 13:05:11 -05:00
Scott Moser
2910ecb8e3 read_file_or_url: raise UrlError with 404 on ENOENT
This makes it easier to call read_file_or_url and handle file or url
errors.  Now read_file_or_url will raise a UrlError in either case
on errors.
2014-01-24 22:31:28 -05:00
Scott Moser
34490c2645 pylint and long line fixes.
This fixes up many long lines to be < 80 chars and some other
pylint issues.  pylint 1.1 (in trusty) is now complaining about
the lazy logging, so I'll clean that up when I touch things.
2014-01-24 15:29:09 -05:00
Joshua Harlow
d01bb4f143 Skip retry and continued fetch of userdata when NOT_FOUND
When a 404 http code comes back from the fetching of ec2
data, instead of retrying immediatly stop the fetching process
and in the userdata fetching function handle this case as a
special case of no userdata being fetched (an empty string
in this case).
2014-01-23 14:41:09 -08:00
Scott Moser
144fb6fe7d fix util.which if PATH is not in environment
This fixes a test case that failed because PATH was unset in the os.environ.
2014-01-23 16:48:12 -05:00
Scott Moser
d120429aa0 fix broken consumption of /proc/mounts
this was checking that the lenghth of the mount line from /proc/mounts
was 6, not the number of tokens.
2014-01-23 15:24:36 -05:00
Scott Moser
adf5fe0f3f merge from trunk 2014-01-23 15:17:17 -05:00
Scott Moser
2f38bddc4c replace get_nested_option_as_list with get_cfg_by_path, improve ruparts
this makes runparts take exe_prefix and do string to list conversion
inside. that means we don't have to do it in cc_scripts_vendor.

Also, get_nested_option_as_list was essentially get_cfg_by_path anyway.
2014-01-15 17:13:24 -05:00
Ben Howard
0d9f85fdec Merge with upstream sources 2014-01-09 08:17:41 -07:00
Ben Howard
161d6ab3eb Significant re-working of the userdata handling and introduction of
vendordata.

Vendordata is a datasource provided userdata-like blob that is parsed
similiarly to userdata, execept at the user's pleasure.


cloudinit/config/cc_scripts_vendor.py: added vendor script cloud config

cloudinit/config/cc_vendor_scripts_per_boot.py: added vendor per boot
    cloud config

cloudinit/config/cc_vendor_scripts_per_instance.py: added vendor per
    instance vendor cloud config

cloudinit/config/cc_vendor_scripts_per_once.py: added per once vendor
    cloud config script

doc/examples/cloud-config-vendor-data.txt: documentation of vendor-data
    examples

doc/vendordata.txt: documentation of vendordata for vendors

(RENAMED) tests/unittests/test_userdata.py => tests/unittests/test_userdata.py
      TO: tests/unittests/test_userdata.py => tests/unittests/test_data.py:
    userdata test cases are not expanded to confirm superiority over vendor
    data.

bin/cloud-init: change instances of 'consume_userdata' to 'consume_data'

cloudinit/handlers/cloud_config.py: Added vendor script handling to default
    cloud-config modules

cloudinit/handlers/shell_script.py: Added ability to change the path key to
    support vendor provided 'vendor-scripts'. Defaults to 'script'.

cloudinit/helpers.py:
    - Changed ConfigMerger to include handling of vendordata.
    - Changed helpers to include paths for vendordata.

cloudinit/sources/__init__.py: Added functions for helping vendordata
    - get_vendordata_raw(): returns vendordata unprocessed
    - get_vendordata(): returns vendordata through userdata processor
    - has_vendordata(): indicator if vendordata is present
    - consume_vendordata(): datasource directive for indicating explict
        user approval of vendordata consumption. Defaults to 'false'

cloudinit/stages.py: Re-jiggered for handling of vendordata
    - _initial_subdirs(): added vendor script definition
    - update(): added self._store_vendordata()
    - [ADDED] _store_vendordata(): store vendordata
    - _get_default_handlers(): modified to allow for filtering
        which handlers will run against vendordata
    - [ADDED] _do_handlers(): moved logic from consume_userdata
        to _do_handlers(). This allows _consume_vendordata() and
        _consume_userdata() to use the same code path.
    - [RENAMED] consume_userdata() to _consume_userdata()
    - [ADDED] _consume_vendordata() for handling vendordata
        - run after userdata to get user cloud-config
        - uses ConfigMerger to get the configuration from the
            instance perspective about whether or not to use
            vendordata
    - [ADDED] consume_data() to call _consume_{user,vendor}data

cloudinit/util.py:
    - [ADDED] get_nested_option_as_list() used by cc_vendor* for
        getting a nested value from a dict and returned as a list
    - runparts(): added 'exe_prefix' for running exe with a prefix,
        used by cc_vendor*

config/cloud.cfg: Added vendor script execution as default

tests/unittests/test_runs/test_merge_run.py: changed consume_userdata() to
    consume_data()

tests/unittests/test_runs/test_simple_run.py: changed consume_userdata() to
    consume_data()
2014-01-08 17:16:24 -07:00
Harm Weites
e6bf1b3b1d fix: Log the used method as well. 2013-12-14 17:38:04 +00:00
James Slagle
f5814193a2 Cast file path to string.
Before passing a path into selinux.matchpathcon, it needs to be casted
to a string, since the path could be unicode and selinux.matchpathcon
does not support unicode.

Closes-Bug: #1260072
2013-12-13 10:40:51 -05:00
Harm Weites
e4f89dcdc6 new: FreeBSD module to support cloud-init on the FBSD10 platform. In its
current form its still missing some modules though.

Supported:
-SSH-keys
-growpart
-growfs
-adduser
-powerstate
2013-12-06 21:25:04 +00:00
Tim Daly Jr.
318d527055 Fix bug lp:1248625 by reading /etc/mtab when mountinfo is not present. 2013-11-13 19:28:52 -08:00
Scott Moser
cc44ef561f try to support ephemeral0.1 in cc_mounts 2013-10-04 17:29:25 -04:00
Scott Moser
cb1dd63583 simplifications and some function renames 2013-10-04 16:16:12 -04:00
Ben Howard
798a7527c6 Make {pep8,pylint,test} pass commit. 2013-10-03 17:07:23 -06:00
Ben Howard
86287e9f8b Moved ephemeralX.Y handling from Datasource into the cc_disk_setup, which makes it cloud agnostic. 2013-10-03 16:15:56 -06:00
Ben Howard
738a3472f1 Added ability to define disks via 'ephemeralX.Y'.
Modified cc_mounts to identify whether ephermalX is partitioned.
Changed datasources for Azure and SmartOS to use 'ephemeralX.Y' format.
Added disk remove functionally
2013-10-02 15:05:15 -06:00