summaryrefslogtreecommitdiff
path: root/cloudinit/sources/DataSourceSmartOS.py
Commit message (Collapse)AuthorAgeFilesLines
* Remove dead code (#2038)Brett Holman2023-03-031-3/+0
|
* Refactor: Drop inheritance from object (#1728)Alberto Contreras2022-09-141-1/+1
| | | As we do not support python2 anymore, we can remove those 8 chars.
* Remove xenial references (#1472)Alberto Contreras2022-06-081-2/+1
| | | | | | - Remove references and dead code to Xenial, Eoan, Python < 3.7 - cc_ubuntu_drivers: Use python3-debconf instead of shell script - add integration test for ubuntu_drivers - bump pycloudlib for OCI subnet/jammy fixes
* Drop mypy excluded files (#1454)Alberto Contreras2022-05-231-2/+4
| | | | | | | | | - Add types to let mypy pass. - Add mypy flags: - detect unused ignores - redundant casts - Drop support of `ConfigParser` in Python 2 - Harden DataSourceLXD.network_config - Convert old-style commented types to proper types.
* Adopt Black and isort (SC-700) (#1157)James Falcon2021-12-151-242/+313
| | | | | Applied Black and isort, fixed any linting issues, updated tox.ini and CI.
* Allow user control over update events (#834)James Falcon2021-05-131-2/+6
| | | | | | | | | | | | | | | | | | | Control is currently limited to boot events, though this should allow us to more easily incorporate HOTPLUG support. Disabling 'instance-first-boot' is not supported as we apply networking config too early in boot to have processed userdata (along with the fact that this would be a pretty big foot-gun). The concept of update events on datasource has been split into supported update events and default update events. Defaults will be used if there is no user-defined update events, but user-defined events won't be supplied if they aren't supported. When applying the networking config, we now check to see if the event is supported by the datasource as well as if it is enabled. Configuration looks like: updates: network: when: ['boot']
* cloudinit: move dmi functions out of util (#622)Scott Moser2020-11-021-1/+2
| | | | | | | | | This just separates the reading of dmi values into its own file. Some things of note: * left import of util in dmi.py only for 'is_container' It'd be good if is_container was not in util. * just the use of 'util.is_x86' to dmi.py * open() is used directly rather than load_file.
* tox: bump the pylint version to 2.6.0 in the default run (#544)Paride Legovini2020-08-251-1/+3
| | | | | | Changes: tox: bump the pylint version to 2.6.0 in the default run Fix pylint 2.6.0 W0707 warnings (raise-missing-from)
* Move subp into its own module. (#416)Scott Moser2020-06-081-2/+3
| | | | | | | | | | | | | | | | | This was painful, but it finishes a TODO from cloudinit/subp.py. It moves the following from util to subp: ProcessExecutionError subp which target_path I moved subp_blob_in_tempfile into cc_chef, which is its only caller. That saved us from having to deal with it using write_file and temp_utils from subp (which does not import any cloudinit things now). It is arguable that 'target_path' could be moved to a 'path_utils' or something, but in order to use it from subp and also from utils, we had to get it out of utils.
* DataSourceSmartOS: reconfigure network on each bootMike Gerdts2019-10-311-1/+7
| | | | | | | | | In typical cases, SmartOS does not use DHCP for network configuration. As such, if the network configuration changes that is reflected in metadata and will be picked up during the next boot. LP: #1765801 Joyent: OS-6902 reconfigure network on each boot
* instance-data: Add standard keys platform and subplatform. Refactor ec2.Chad Smith2018-10-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the following instance-data.json standardized keys: * v1._beta_keys: List any v1 keys in beta development, e.g. ['subplatform']. * v1.public_ssh_keys: List of any cloud-provided ssh keys for the instance. * v1.platform: String representing the cloud platform api supporting the datasource. For example: 'ec2' for aws, aliyun and brightbox cloud names. * v1.subplatform: String with more details about the source of the metadata consumed. For example, metadata uri, config drive device path or seed directory. To support the new platform and subplatform standardized instance-data, DataSource and its subclasses grew platform and subplatform attributes. The platform attribute defaults to the lowercase string datasource name at self.dsname. This method is overridden in NoCloud, Ec2 and ConfigDrive datasources. The subplatform attribute calls a _get_subplatform method which will return a string containing a simple slug for subplatform type such as metadata, seed-dir or config-drive followed by a detailed uri, device or directory path where the datasource consumed its configuration. As part of this work, DatasourceEC2 methods _get_data and _crawl_metadata have been refactored for a few reasons: - crawl_metadata is now a read-only operation, persisting no attributes on the datasource instance and returns a dictionary of consumed metadata. - crawl_metadata now closely represents the raw stucture of the ec2 metadata consumed, so that end-users can leverage public ec2 metadata documentation where possible. - crawl_metadata adds a '_metadata_api_version' key to the crawled ds.metadata to advertise what version of EC2's api was consumed by cloud-init. - _get_data now does all the processing of crawl_metadata and saves datasource instance attributes userdata_raw, metadata etc. Additional drive-bys: * unit test rework for test_altcloud and test_azure to simplify mocks and make use of existing util and test_helpers functions.
* tests: Disallow use of util.subp except for where needed.Scott Moser2018-09-051-12/+17
| | | | | | | | | | | | | | | | | | In many cases, cloud-init uses 'util.subp' to run a subprocess. This is not really desirable in our unit tests as it makes the tests dependent upon existance of those utilities. The change here is to modify the base test case class (CiTestCase) to raise exception any time subp is called. Then, fix all callers. For cases where subp is necessary or actually desired, we can use it via   a.) context hander CiTestCase.allow_subp(value)   b.) class level self.allowed_subp = value Both cases the value is a list of acceptable executable names that will be called (essentially argv[0]). Some cleanups in AltCloud were done as the code was being updated.
* pylint: Fix pylint warnings reported in pylint 2.0.0.Scott Moser2018-07-211-1/+1
| | | | | | | | | Pylint 2.0.0 was recently released and complains more about logging-not-lazy than it used to. I've fixed those warnings, here. The changes in rh_subscription are more extensive. pylint may be complaining incorrectly there, but the tests were not correctly un-doing all of their mock/patching. This cleans those up and makes pylint happy.
* Enable SmartOS network metadata to work with netplan via per-subnet routesDan McDonald2018-05-241-5/+41
| | | | | | | | | | | - Updated datadict reference URL - Store sdc:routes metadata in DatasourceSmartOS - Map sdc:routes values to per-interface subnet configuration - Added unittest Co-authored-by: Mike Gerdts <mike.gerdts@joyent.com> LP: #1763512
* openstack: Allow discovery in init-local using dhclient in a sandbox.Chad Smith2018-05-231-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Network has not yet been configured in the init-local stage so the openstack datasource will use dhcp-client to temporarily obtain an ipv4 address and query the metadata service at http://169.254.169.254 to get network_data.json configuration. If present, the datasource will return network_config version 1 config based on that network_data.json content. Previously OpenStack datasource only setup dhcp on the fallback interface so this represents a change in behavior to react to the full config provided by openstack. Also significant to OpenStack is the separation of a _crawl_data operation from get_data(). crawl_data walks the available metadata services and returns a dict of discovered content. get_data consumes the crawled_data,  caches it in the datasource and reacts to that data. /run/cloud-init/instance-data.json now published network_data.json or ec2_metadata key if that data is present on any datasource. The main reasons for the separation of crawl from get_data:  * Enable performance metrics of cloud-init's metadata crawls on each  * Enable cloud-init modules and scripts to query and consume metadata    content which may have updated/changed after cloud-init's initial cache    during instance boot. (Think hotplug) Also generalize common logic to base DataSource class/module:  * Move to a common UNSET variable up into base datasource module fix EC2,    ConfigDrive, OpenStack, SmartOS to use the global.  * Drop get_url_settings from Ec2, CloudStack and OpenStack and generalize    DataSource.get_url_params(). Allow subclasses to override url_max_wait,    url_timeout and url_retries params.  * Rename get_network_metadata bool to perform_dhcp_setup as it designates    whether EphemeralDHCPv4 setup is required before crawling metadata. LP: #1749717
* ds-identify: recognize container-other as a container, test SmartOS.Scott Moser2018-05-151-2/+2
| | | | | | | | | In playing with a SmartOS container I found that ds-identify did not identify the container there as a container. Systemd-detect-virt identifies it as 'container-other'. Also here are tests for ds-identify for the SmartOS platform identification, and some indentation fixes in ds-identify.
* DataSourceSmartOS: add locking of serial device.Mike Gerdts2018-04-231-0/+2
| | | | | | | | | | | | | | | | | | cloud-init and mdata-get each have their own implementation of the SmartOS metadata protocol. If cloud-init and other services that call mdata-get are run concurrently, crosstalk on the serial port can cause them both to become confused. This change makes it so that cloud-init uses the same cooperative locking scheme that's used by mdata-get, thus preventing cross-talk between mdata-get and cloud-init. For testing, a VM running on a SmartOS host and pyserial are required. If the tests are run on a platform other than SmartOS, those that use a real serial port are skipped. pyserial remains commented in requirements.txt because most testers will not be running atop SmartOS. LP: #1746605
* DataSourceSmartOS: sdc:hostname is ignoredMike Gerdts2018-04-201-2/+8
| | | | | | | | | | | | | | | | There are three potential sources of the hostname, one of which is documented SmartOS's vmadm(1M) via the hostname property. That property's value is retrieved via the sdc:hostname key. The other two sources for the hostname are a hostname key in customer_metadata and the VM's uuid (sdc:uuid). Of these three, the sdc:hostname value is not used in a meaningful way by DataSourceSmartOS. This fix changes the fallback mechanism when hostname is not specified in customer_metadata. The order of precedence for setting the hostname is now 1) hostname in customer_metadata, 2) sdc:hostname, then 3) sdc:uuid. LP: #1765085
* DataSourceSmartOS: list() should always return a listMike Gerdts2018-04-201-3/+3
| | | | | | | | If customer_metadata has no keys, the KEYS request returns an empty string. Callers of the list() method expect a list to be returned and will give a stack trace if this expectation is not met. LP: #1763480
* DataSourceSmartOS: fix hang when metadata service is downMike Gerdts2018-04-181-15/+102
| | | | | | | | | | | | | | | | | | | | | If the metadata service in the host is down while a guest that uses DataSourceSmartOS is booting, the request from the guest falls into the bit bucket. When the metadata service is eventually started, the guest has no awareness of this and does not resend the request. This results in cloud-init hanging forever with a guest reboot as the only recovery option. This fix updates the metadata protocol to implement the initialization phase, just as is implemented by mdata-get and related utilities. The initialization phase includes draining all pending data from the serial port, writing an empty command and getting an expected error message in reply. If the initialization phase times out, it is retried every five seconds. Each timeout results in a warning message: "Timeout while initializing metadata client. Is the host metadata service running?" By default, warning messages are logged to the console, thus the reason for a hung boot is readily apparent. LP: #1667735
* DataSourceSmartOS: change default fs on ephemeral disk from ext3 to ext4.Mike Gerdts2018-04-181-1/+1
| | | | | | | | | | ext3 is not able to support file system sizes that are needed in Joyent's cloud. For the default block size of 4k, the maximum filesystem size for ext3 is 2^32 * 4096 = 16 TiB. This changes the default file system type from ext3 to ext4. LP: #1763511
* Datasources: Formalize DataSource get_data and related properties.Chad Smith2017-12-051-1/+4
| | | | | | | | | | | | | | | | | | | | | Each DataSource subclass must define its own get_data method. This branch formalizes our DataSource class to require that subclasses define an explicit dsname for sourcing cloud-config datasource configuration. Subclasses must also override the _get_data method or a NotImplementedError is raised. The branch also writes /run/cloud-init/instance-data.json. This file contains all meta-data, user-data and vendor-data and a standardized set of metadata keys in a json blob which other utilities with root-access could make use of. Because some meta-data or user-data is potentially sensitive the file is only readable by root. Generally most metadata content types should be json serializable. If specific keys or values are not serializable, those specific values will be base64encoded and the key path will be listed under the top-level key 'base64-encoded-keys' in instance-data.json. If json writing fails due to other TypeErrors or UnicodeDecodeErrors, a warning log will be emitted to /var/log/cloud-init.log and no instance-data.json will be created.
* pylint: fix all logging warningsJoshua Powers2017-04-211-1/+1
| | | | | | | This will change all instances of LOG.warn to LOG.warning as warn is now a deprecated method. It will also make sure any logging uses lazy logging by passing string format arguments as function parameters.
* LICENSE: Allow dual licensing GPL-3 or Apache 2.0Jon Grimm2016-12-221-17/+6
| | | | | | | | | | | | | | | | | | This has been a recurring ask and we had initially just made the change to the cloud-init 2.0 codebase. As the current thinking is we'll just continue to enhance the current codebase, its desirable to relicense to match what we'd intended as part of the 2.0 plan here. - put a brief description of license in LICENSE file - put full license versions in LICENSE-GPLv3 and LICENSE-Apache2.0 - simplify the per-file header to reference LICENSE - tox: ignore H102 (Apache License Header check) Add license header to files that ship. Reformat headers, make sure everything has vi: at end of file. Non-shipping files do not need the copyright header, but at the moment tests/ have it.
* DigitalOcean: use the v1.json endpointBen Howard2016-08-121-7/+1
| | | | | | | | | | | | | | | | Per [1], DigitalOcean provides the metadata in multiple formats. The JSON document is the preferred endpoint. Changes: - Switch to the v1.json meta-data endpoint - Identify droplet identity from SMBIOS - Only poll for metadata when the instance is confirmed to be a droplet - Removal of hard-coded mirrors Additionally, centralize the gates on running 'dmidecode' on arm arches, and update tests to address. [1] https://developers.digitalocean.com/documentation/metadata/
* SmartOS: more improvements for network configurationScott Moser2016-08-101-23/+91
| | | | | | | | | | | | | This improves smart os network configuration - fix the SocketClient which was previously completely broken. - adds support for configuring dns servers and dns search (based off the sdc:dns_domain). - support 'sdc:gateways' information from the datasource for configuring default routes. - add converted network information to output when module is run as a main This does not support 'sdc:routes' as described at http://eng.joyent.com/mdata/datadict.html
* Fix SmartOS datasource usage of dict comprehensionsJoshua Harlow2016-07-131-4/+4
|
* Rebase against masterJoshua Harlow2016-06-061-165/+412
|\
| * fix untested previous change to smartosScott Moser2016-06-021-1/+0
| |
| * smartos: do not raise error when not on smartosScott Moser2016-06-021-3/+10
| | | | | | | | | | | | if get_smartos_environ() returned a None, then the datasoure would raise a ValueError when get_data was called. Fix that.
| * use constants for kvm and lx-brandScott Moser2016-05-311-2/+2
| |
| * return dict not None on get_config_objScott Moser2016-05-271-1/+1
| |
| * smartos is local, but it is named DataSourceSmartOS not DataSourceConfigDriveScott Moser2016-05-271-1/+1
| |
| * Smartos datasource is local.Scott Moser2016-05-271-1/+1
| |
| * add nicer mainScott Moser2016-05-271-1/+20
| |
| * remove debug printScott Moser2016-05-271-1/+0
| |
| * fix pyflakes and flake8Scott Moser2016-05-271-2/+1
| |
| * fix the remaining testsScott Moser2016-05-271-2/+2
| |
| * fix a bunch of the testsScott Moser2016-05-271-5/+7
| |
| * fix pyflakes and some pylint errors/warningsScott Moser2016-05-271-7/+20
| |
| * fix pyflakes, move datasources= to bottomScott Moser2016-05-271-20/+17
| |
| * Move sdc:nics to a JSON map. Add unittest for sdc:nicsRyan Harper2016-05-261-8/+11
| |
| * Add smartos sdc:nics converter and network_config property for smartos ↵Ryan Harper2016-05-261-4/+91
| | | | | | | | configdrive
| * initial commit of reworkScott Moser2016-05-011-164/+286
| |
* | Use a fake serial module that will allow tests to contineJoshua Harlow2016-05-111-3/+1
|/ | | | | | | | | | Instead of aborting all serial using tests instead just create a serial module in cloudinit that will create a fake and broken serial class when pyserial is not actually installed. This allows for using the datasource and tests that exist in a more functional and tested manner (even when pyserial is not found).
* SmartOS, CloudSigma: fix error when dmi data is not availbleScott Moser2016-04-121-1/+1
| | | | | | | In Cloudsigma, the datasource would warn if no product id was availble. SmartOS would log exception. This fixes both of those, changing the warning to a debug message. LP: #1569469
* Apply pep8, pyflakes fixes for python2 and 3Scott Moser2016-03-041-5/+4
|\ | | | | | | | | | | | | | | | | | | Update make check target to run pep8 and run pyflakes or pyflakes3 depending on the value of 'PYVER'. This way the python3 build environment does not need python2 and vice versa. Also have make check run the 'yaml' test. tox: have tox run pep8 in the pyflakes
| * Update pep8 runner and fix pep8 issuesRyan Harper2016-03-031-4/+3
|/
* SmartOS: Add support for Joyent LX-Brand Zones (LP: #1540965)Robert Jennings2016-02-041-103/+154
| | | | | | | | | LX-brand zones on Joyent's SmartOS use a different metadata source (socket file) than the KVM-based SmartOS virtualization (serial port). This patch adds support for recognizing the different flavors of virtualization on SmartOS and setting up a metadata source file object. After the file object is created, the rest of the code for the datasource LP: #1540965
* Compile SmartOS line-parsing regex once.Daniel Watkins2015-03-251-5/+5
|