summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
AgeCommit message (Collapse)Author
2012-11-10whitespace / indentation cleanupsScott Moser
These changes were pulled out of the previous merge (cc_yum_add_repo) as they were unrelated there. Re-applying them here.
2012-10-23use only util methods for reading/loading/appending/peekingScott Moser
Use only util methods for reading/loading/appending/peeking at files since it is likely soon that we will add a new way of adjusting the root of files read, also it is useful for debugging to track what is being read/written in a central fashion.
2012-09-28Sync with head and fix conflicts.Joshua Harlow
2012-09-28Rework the rest of the locations that usedJoshua Harlow
the previous 'user' and make those locations go through the new distros functions to select the default user or the user list (depending on usage). Adjust the tests to check the new 'default' field that signifies the default user + test the new method to extract just the default user from a normalized user dictionary.
2012-09-28add 'safeyaml' to cloudinitScott Moser
In 0.7.0 we started using yaml.safe_load to load data rather than yaml.load. Some producers (namely, ubuntu MAAS created) have produced cloud-config data in the past that included python unicode types. This creates a specialized safe_loader that is basically safe_load + support for python unicode.
2012-09-211. Cleanup the user creation so that the distro class isJoshua Harlow
responsible only for creating users and groups and normalizing a input configuration into a normalized format that splits up the user list, the group list and the default user listsand let the add user/group config module handle calling those methods to add its own users/groups and the default user (if any). 2. Also add in tests for this normalization process to ensure that it is pretty bug free and works with the different types of formats that users/groups/defaults + options can take.
2012-09-20Use only util methods for reading/loading/appending/peekingJoshua Harlow
at files since it is likely soon that we will add a new way of adjusting the root of files read, also it is useful for debugging to track what is being read/written in a central fashion.
2012-08-27For the userdata 'post-filtering' add in a new folder thatJoshua Harlow
can contain filters that serve this purpose only and add in the initial launch-index filter and replace the code in the datasource class that previously did this.
2012-08-22fix issues from 'make pylint'Scott Moser
In an effort to pylint errors about NonImlementedError and add_default_user, I moved this method to distro and genericized it. Now, assuming a sane 'create_user' for the distro, this should work. Also: * removed the unused set_configured_user method
2012-08-22fix errors from 'make pep8'Scott Moser
2012-08-22Merge with lp:cloud-initBen Howard
2012-08-22fix pep8 complaints.Scott Moser
make pep8 now is silent on precise's pep8 ( 0.6.1-2ubuntu2).
2012-08-20Dropped hidden command; replaced with logstring. Also changed useradd ↵Ben Howard
command to use log options over short
2012-08-20Added "userless" mode to cloud-init for handling the creation of theBen Howard
users and the default user on Ubuntu. cloudinit/config/cc_users_groups.py: new cloud-config module for creating users and groups on instance initialization. - Creates users and group - Sets "user" directive used in ssh_import_id cloudinit/config/cc_ssh_import_id.py: module will rely upon users_groups for setting the default user. Removed assumption of 'ubuntu' user. cloudinit/distros/__init__.py: Added new abstract methods for getting and creating the default user. cloudinit/distros/ubuntu.py: Defined abstract methods for getting and and creating the default 'ubuntu' user on Ubuntu instances. cloudinit/util.py: Added ability to hide command run through util.subp to prevent the commands from showing in the logs. Used by user_groups cloud-config module. config/cloud.cfg: Removed "user: ubuntu" directive and replaced with new user-less syntax. doc/examples/cloud-config.txt: Documented the creation of users and groups.
2012-08-06add protection against dns-redirection to is_resolvableScott Moser
In an effort to make the EC2 Datasource's search under ec2.archive.ubuntu.com resilient against dns redirection, we add some code to is_resolvable. One future enhancement for this would be to protect against server side round robin results. Ie, if 'bogus-entry' returned 10.0.1.1 one time, and then 10.0.1.2 a second time. We could check if results where within the same 3 octets, and assume invalid if they were.
2012-07-16improve debug via _CLOUD_INIT_SAVE_STDIN and _CLOUD_INIT_SAVE_STDOUTScott Moser
This does 2 things: a.) fixes broken logic in 'close_stdin' previously _CLOUD_INIT_SAVE_STDIN had to be set to false to preserve stdin. "save_stdin" should be true to indicate it should be saved. The net result is that you can stuff just add import pdb; pdb.set_trace() to code, and then run something like: sudo _CLOUD_INIT_SAVE_STDIN=1 _CLOUD_INIT_SAVE_STDOUT=1 \ cloud-init single --name=mounts --frequency=always And enter the debugger even if you had a 'output' that would redirect stdin/out by default, like: output: {all: '| tee -a /var/log/cloud-init-output.log'}
2012-07-12load_yaml: if conversion fails, but string is empty, return defaultScott Moser
the problem sovled here is that most callers of yaml_load do not pass 'None' as a allowed type. I didn't want to change all the callers. If the yaml.safe_load ended up being None we were raising a TypeError and that was getting logged (meaning output to console). Even though the this was not really bad. So, if the type is not in the list, *and* it is not empty, then log exception. If it in the list and empty, just debug. empty input was occurring when cloud-config was empty (no user-data)
2012-07-11do not capture runparts outputScott Moser
runparts output was being captured. This meant that output of user-scripts was being captured and not sent to stdout (console).
2012-07-10Fixes 1012854 by implementing file writing, adjustsJoshua Harlow
other code to have user/group parsing in util instead of in stages.py, renames decomp_str to decomp_gzip since it is more meaningful when named that (as thats all it can decompress).
2012-07-10send welcome message after logging has been appliedScott Moser
in the 'cloud-init init' stages, we want the welcome message to get to the correct output as specified by the system's configuration. Ie, if the local /etc/cloud.config.d had 'output' or 'log_cfg' settings we want those to be able to affect the welcome message also. In normal operation, nothing else will go to stdout or stderr before this, and likely/hopefully nothing terribly important to the logs.
2012-07-09Use the common 'is_false' routine for testing false here insteadharlowja
of a custom list that may confuse people trying to use this.
2012-07-09Update chownbyname to catch the key error when users/groups that are not knownJoshua Harlow
are provided and rethrow it as a OSError (which seems reasonable) and adjust its usage in the log file touching/permission modification stage to catch this error and log it.
2012-07-09fix 'make pylint' warningsScott Moser
On my system (quantal) this 'make pylint' does not complain now.
2012-07-09DataSourceEc2: only do dns check in mirror selectionScott Moser
This returns the check for an archive mirror in the DataSourceEc2 to only do so by DNS resolution. The 'rework' branch had made the check wait and timeout on attempts to reach the mirror. This resulted in 120 seconds of waiting before failure. For now, just go back to the old situation of checking by dns.
2012-07-03Add a check on 'chownbyname' that catches the keyerror and logs it (instead ↵Joshua Harlow
of failing)
2012-07-021. Move the welcome message template string to a constant at the top of the ↵Joshua Harlow
module 2. Fix the usage of multi_log to log to only one of the places (for now) 3. Update comment about multi-log and why write_file isn't used in this case
2012-07-01Merge in pending changes.harlowja
2012-07-011. Rename util functions to is_true and is_falseharlowja
2. Move the config loading functions to where they are used (in stages) 3. Adjust cc_set_passwords to use the is_true and is_false renamed functions 4. Adjust the init stage to have a _read_base_config function used to load the base 'initial' configuration from the following locations a. Kernel cmdline b. Conf.d location (+ the cloud.cfg location) c. Built-in configuration
2012-07-01Add a multi log function that can write to stderr, console and a log debug, ↵Joshua Harlow
useful in certain cases
2012-06-29Refactor the selinux guard to aid in mockingharlowja
1. Adjust the test_util after this mocking to be cleaner
2012-06-29Just log the number of commands 'shellified'Joshua Harlow
2012-06-29Don't always log stdout and stderr (exceptions will capture them if it fails)Joshua Harlow
2012-06-29Reduce the log levels by removing a few statements that happen to often (and ↵Joshua Harlow
aren't very meaningful)
2012-06-29Add the rc code for blkid '2' being valid with a note to as why.Joshua Harlow
2012-06-261. Add a chdir context managerJoshua Harlow
2. Add a abs path joining function that will return the absolute path of a combined path (where applicable)
2012-06-23Fix a bunch of == None casesharlowja
2012-06-221. Move the getkeybyid function back here but add some slight adjustmentsJoshua Harlow
a. Instead of executing a bash string, write out a temporary file and then just execute '/bin/sh' on that file with the right arguments instead. 2. Rename util.SilentTemporaryFile to util.ExtendedTemporaryFile and update the usages of the previous name accordingly, this better reflects what this temp file is. 3. More teenie pep8 line length fixings
2012-06-22Fix syntax err, grrrharlowja
2012-06-221. Add comment about conf.d overriding input configharlowja
2. For reading config from conf.d, collect all the configs then call the mergemany function
2012-06-21Fixup python selinux guards, only try to restore after we check if its ↵harlowja
useful to restore, fix test to work with selinux enabled sysystems
2012-06-211. Update the comment about fstab to just point to 'man fstab'Joshua Harlow
2. Update the mount point adding of '/' to just add it in one place if it does not already exist
2012-06-21Returning whether it was enabled, useful for unit testingJoshua Harlow
2012-06-21Use yaml safe_load just incaseJoshua Harlow
2012-06-20Massive pylint + pep8 fixups!Joshua Harlow
2012-06-191. Cleanup variable names to match more of the pythonic underscore patternJoshua Harlow
2. Seperate config loading from the actual final 'merging' process. a. A util function will now merge multiple config dictionaries after they have all been loaded instead of loading and merging at the same time, which can get confusing to follow.
2012-06-181. Allow the built-in config to be passed in when getting the base configJoshua Harlow
2. Move the cloudinit util function that writes the command line url to a file to here.
2012-06-181. Decreasing of logging in piping routingJoshua Harlow
2. Fixup of merge dict after found out that it depends on the src return for non dict types 3. Only merge kernel config if there was any kernel config
2012-06-171. Add a url response class that urlreading now returns (instead of a tuple). harlowja
a. This allows for more properties to be added as needed in the future, instead of being very restrictive. 2. Fix up all uses of the url reading to now use this new response object. 3. Also fixup user data including, such that if no response actual occurs the url content is not further processed.
2012-06-16Let read_file_or_url util function have good defaultsJoshua Harlow
2012-06-16Correct the mount options to use a comma separated list for the mount ↵Joshua Harlow
options (if any provided/selected)