├── .gitignore ├── CONTRIBUTING.md ├── LICENSE.txt ├── MANIFEST.in ├── NEWS ├── PKG-INFO ├── README.md ├── SECURITY.md ├── __init__.py ├── bin ├── oci-attached-volumes ├── oci-compartmentid ├── oci-image-migrate ├── oci-image-migrate-import ├── oci-image-migrate-upload ├── oci-instanceid ├── oci-iscsi-config ├── oci-kvm ├── oci-metadata ├── oci-network-config ├── oci-network-inspector ├── oci-notify ├── oci-public-ip ├── oci-show-config ├── oci-test-ip-auth └── oci-volume-data ├── buildrpm └── oci-utils.spec ├── contrib └── oracle_virt_manager │ ├── README │ ├── instance.tf │ └── userdata │ ├── oci-tests-env │ └── ovirt-engine-setup-answers.conf ├── data ├── 00-oci-utils.conf ├── 10-oci-kvm.conf ├── 91-oci-kvm.preset ├── 91-oci-utils.preset ├── oci-image-cleanup.conf ├── oci-kvm-config.service ├── oci-migrate-conf.yaml ├── oci-vmnet.service └── ocid.service ├── doc ├── dev-notes └── oci_api.md ├── lib └── oci_utils │ ├── __init__.py │ ├── cache.py │ ├── impl │ ├── __init__.py │ ├── auth_helper.py │ ├── init_script_helpers.py │ ├── init_script_templates.py │ ├── migrate │ │ ├── __init__.py │ │ ├── oci_image_migrate_import_main.py │ │ ├── oci_image_migrate_main.py │ │ └── oci_image_migrate_upload_main.py │ ├── network_helpers.py │ ├── network_interface.py │ ├── oci_attached_volumes_main.py │ ├── oci_growfs_main.py │ ├── oci_iscsi_config_main.py │ ├── oci_metadata_main.py │ ├── oci_network_config_main.py │ ├── oci_network_inspector_main.py │ ├── oci_notify_main.py │ ├── oci_public_ip_main.py │ ├── oci_resources.py │ ├── oci_show_config_main.py │ ├── oci_test_ip_auth_main.py │ ├── oci_volume_data.py │ ├── ocid_main.py │ ├── platform_helpers.py │ ├── resources.py │ ├── row_printer.py │ ├── row_printer_helpers.py │ ├── sudo_utils.py │ └── virt │ │ ├── __init__.py │ │ ├── oci_kvm_main.py │ │ ├── sysconfig.py │ │ ├── virt_check.py │ │ └── virt_utils.py │ ├── iscsiadm.py │ ├── kvm │ ├── __init__.py │ ├── utils.py │ └── virt.py │ ├── lsblk.py │ ├── metadata.py │ ├── migrate │ ├── __init__.py │ ├── decorators.py │ ├── doc │ │ ├── oci_image_migrate.md │ │ ├── oci_image_migrate_import.md │ │ └── oci_image_migrate_upload.md │ ├── exception.py │ ├── image_types │ │ ├── __init__.py │ │ ├── qcow2.py │ │ ├── template_img_type.py │ │ └── vmdk.py │ ├── imgdevice.py │ ├── migrate_data.py │ ├── migrate_tools.py │ ├── oci_cli_tools.py │ ├── os_types │ │ ├── __init__.py │ │ ├── ol_type_os.py │ │ ├── template_type_os.py │ │ └── ubuntu_type_os.py │ ├── readme.txt │ ├── reconfigure_network.py │ └── system_tools.py │ ├── oci_api.py │ ├── packages │ ├── __init__.py │ └── stun │ │ ├── LICENSE │ │ ├── README │ │ └── __init__.py │ └── vnicutils.py ├── libexec ├── oci-growfs ├── oci-growfs-bash ├── oci-image-cleanup ├── oci-kvm-config.sh ├── oci-kvm-network-script ├── oci-kvm-upgrade ├── oci-utils-config-helper ├── oci_vcn_iface.awk └── ocid ├── man ├── man1 │ ├── oci-attached-volumes.1 │ ├── oci-compartmentid.1 │ ├── oci-image-migrate-import.1 │ ├── oci-image-migrate-upload.1 │ ├── oci-image-migrate.1 │ ├── oci-instanceid.1 │ ├── oci-iscsi-config.1 │ ├── oci-kvm.1 │ ├── oci-metadata.1 │ ├── oci-network-config.1 │ ├── oci-network-inspector.1 │ ├── oci-notify.1 │ ├── oci-public-ip.1 │ └── oci-volume-data.1 ├── man5 │ └── oci-utils.conf.d.5 └── man8 │ ├── oci-growfs.8 │ ├── oci-image-cleanup.8 │ └── ocid.8 ├── requirements.txt ├── setup.cfg ├── setup.py ├── tests ├── __init__.py ├── automation │ ├── Makefile │ ├── __init__.py │ ├── configuration │ │ ├── BUILD.txt │ │ ├── README.txt │ │ ├── RPM-GPG-KEY-oracle-7 │ │ ├── RPM-GPG-KEY-oracle-8 │ │ ├── oci-utils-automation.repo-7 │ │ ├── oci-utils-automation.repo-8 │ │ └── oci-utils-automation.spec │ ├── create_lvm │ ├── create_user │ ├── create_volume │ ├── data │ │ ├── LICENSE.txt │ │ ├── README.md │ │ ├── base_instance │ │ │ ├── data.tf │ │ │ ├── main.tf │ │ │ └── output.tf │ │ ├── scripts │ │ │ ├── install_oci_utils_automation.sh │ │ │ └── install_oci_utils_kvm_automation.sh │ │ ├── test_iscsi │ │ │ ├── data.tf │ │ │ ├── main.tf │ │ │ └── terraform_version.tf │ │ ├── test_metadata │ │ │ ├── data.tf │ │ │ ├── main.tf │ │ │ └── terraform_version.tf │ │ ├── test_various │ │ │ ├── data.tf │ │ │ ├── main.tf │ │ │ └── terraform_version.tf │ │ └── userdata │ │ │ ├── tests-env │ │ │ └── tests-resolve │ ├── oci_utils_configure_tests.py │ ├── oci_utils_iscsi_data.py │ ├── oci_utils_network_data.py │ ├── oci_utils_pool_data.py │ ├── oci_utils_test_instance.py │ └── templates │ │ ├── tf_apikey │ │ ├── tf_data │ │ ├── tf_main │ │ ├── tf_output │ │ ├── tf_test │ │ └── tf_version ├── common.py ├── data │ ├── properties.cfg │ └── tests │ │ ├── test_cli_iscsi_config │ │ └── properties.cfg │ │ ├── test_cli_iscsi_config_create │ │ └── properties.cfg │ │ ├── test_cli_iscsi_config_createattachdetachattachdetachdestroy │ │ └── properties.cfg │ │ ├── test_cli_iscsi_config_more │ │ └── properties.cfg │ │ ├── test_cli_kvm │ │ └── properties.cfg │ │ ├── test_cli_network_config │ │ └── properties.cfg │ │ ├── test_cli_network_config_attach │ │ └── properties.cfg │ │ ├── test_cli_network_config_configure │ │ └── properties.cfg │ │ ├── test_exec_helpers │ │ └── properties.cfg │ │ ├── test_exec_ocid │ │ └── properties.cfg │ │ ├── test_iscsiadm │ │ └── properties.cfg │ │ ├── test_network_helpers │ │ └── properties.cfg │ │ └── test_oci_notify │ │ └── properties.cfg ├── templates │ └── instance.tfvars.json ├── test_auth_helper.py ├── test_cache.py ├── test_cli_iscsi_config.py ├── test_cli_iscsi_config_create.py ├── test_cli_iscsi_config_createattachdetachattachdetachdestroy.py ├── test_cli_iscsi_config_more.py ├── test_cli_kvm.py ├── test_cli_metadata.py ├── test_cli_metadata_bugs.py ├── test_cli_network_config.py ├── test_cli_network_config_attach.py ├── test_cli_network_config_configure.py ├── test_cli_network_inspector.py ├── test_cli_public_ip.py ├── test_exec_helpers.py ├── test_exec_ocid.py ├── test_exec_utils-config-helper.py ├── test_iscsiadm.py ├── test_lsblk.py ├── test_mig_import.py ├── test_mig_migrate.py ├── test_mig_upload.py ├── test_mig_yaml_config.py ├── test_network_helpers.py ├── test_oci_growfs.py ├── test_oci_metadata.py ├── test_oci_notify.py ├── test_oci_session.py ├── test_oci_volume.py ├── test_platform_helpers.py ├── test_row_printer.py ├── test_virt_helpers.py └── test_vnicutils.py └── tools ├── __init__.py ├── decorators.py ├── execution ├── __init__.py ├── command.py ├── storable.py └── store.py ├── kvm-schema.yaml_save ├── kvm_image ├── build_image │ ├── Makefile │ ├── README.md │ ├── bin │ │ ├── configure_image.py │ │ ├── create_imagebuild │ │ ├── install_packer.py │ │ └── upload_image.py │ ├── scripts │ │ ├── custom_firstboot.sh │ │ ├── custom_install.sh │ │ └── custom_post_install_task.sh │ └── templates │ │ ├── al-kvm-image-template.json │ │ └── ol-kvm-image-template.json └── test_image │ ├── Makefile │ ├── README.md │ ├── bin │ └── create_kvmhost_user │ ├── create_kvm_instance.0.11_May_05_2022.bz2 │ ├── guest_instance │ ├── bin │ │ ├── create_guest_vm │ │ └── create_guest_vm.py │ └── templates │ │ ├── kickstart_bridge_template_ol7 │ │ ├── kickstart_bridge_template_ol8 │ │ ├── kickstart_bridge_template_ol9 │ │ ├── kickstart_direct_template_ol7 │ │ ├── kickstart_direct_template_ol8 │ │ └── kickstart_direct_template_ol9 │ └── host_instance │ ├── base_instance │ ├── data.tf │ ├── main.tf │ └── output.tf │ ├── bin │ ├── create_kvm_host │ └── create_kvm_host.py │ ├── sh_scripts │ └── initial_config.sh │ └── tf_scripts │ ├── api_key.tf │ ├── data.tf │ ├── main.tf │ ├── output.tf │ ├── rsa_key.tf │ ├── rsa_pub_key.tf │ └── version.tf ├── oci_test_case.py ├── provisioning ├── dev_instance │ └── dev-instance.tf ├── gen_instance │ ├── Makefile │ ├── README.md │ ├── base_instance │ │ ├── data.tf │ │ ├── main.tf │ │ └── output.tf │ ├── bin │ │ ├── create_instance │ │ └── create_instance.py │ ├── gen_scripts │ │ └── initial_config.sh │ └── tf_scripts │ │ ├── api_key.tf │ │ ├── data.tf │ │ ├── main.tf │ │ ├── output.tf │ │ ├── rsa_key.tf │ │ ├── rsa_pub_key.tf │ │ └── version.tf ├── kvm_instance │ ├── Makefile │ ├── README.md │ ├── base_instance │ │ ├── data.tf │ │ ├── main.tf │ │ └── output.tf │ ├── bin │ │ ├── create_kvm_instance │ │ └── create_kvm_instance.py │ ├── gen_scripts │ │ └── initial_config.sh │ └── tf_scripts │ │ ├── api_key.tf │ │ ├── data.tf │ │ ├── main.tf │ │ ├── output.tf │ │ └── version.tf └── test_instance │ ├── instance.tf │ └── userdata │ ├── oci-tests-env │ └── oci_resolver_config ├── snooppopen.py ├── test_runnner.py └── tree_config.py /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | .pytest_cache/ 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | rpmbuild/ 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .coverage.* 40 | nosetests.xml 41 | coverage.xml 42 | .cache 43 | *.cover 44 | .hypothesis/ 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | .static_storage/ 53 | .media/ 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # Jupyter Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # SageMath parsed files 79 | *.sage.py 80 | 81 | # Environments 82 | .env 83 | .venv 84 | env/ 85 | venv/ 86 | ENV/ 87 | env.bak/ 88 | venv.bak/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # IDEs 104 | .vscode 105 | 106 | Notes 107 | 108 | # terraform 109 | .terraform 110 | terraform.tfstate 111 | terraform.tfstate.backup 112 | 113 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | Oracle welcomes contributions to this repository from anyone. 3 | 4 | If you want to submit a pull request to fix a bug or add an enhancement, 5 | please first open an issue and link to that issue when you 6 | submit your pull request. 7 | 8 | If you have any questions about a possible submission, feel free to open 9 | an issue too. 10 | 11 | ## Contributing to the Oracle oci-utils repository 12 | 13 | Pull requests can be made under 14 | [The Oracle Contributor Agreement](https://www.oracle.com/technetwork/community/oca-486395.html) (OCA). 15 | 16 | For pull requests to be accepted, the bottom of your commit message must have 17 | the following line using your name and e-mail address as it appears in the 18 | OCA Signatories list. 19 | 20 | ``` 21 | Signed-off-by: Your Name 22 | ``` 23 | 24 | This can be automatically added to pull requests by committing with: 25 | 26 | ``` 27 | git commit --signoff 28 | ``` 29 | 30 | Only pull requests from committers that can be verified as having 31 | signed the OCA can be accepted. 32 | 33 | 34 | ### Pull request process 35 | 36 | 1. Fork this repository 37 | 1. Create a branch in your fork to implement the changes. We recommend using 38 | the issue number as part of your branch name, e.g. `1234-fixes` 39 | 1. Ensure that any documentation is updated with the changes that are required 40 | by your fix. 41 | 1. Ensure that any samples are updated if the base image has been changed. 42 | 1. Submit the pull request. *Do not leave the pull request blank*. Explain exactly 43 | what your changes are meant to do and provide simple steps on how to validate 44 | your changes. Ensure that you reference the issue you created as well. 45 | We will assign the pull request to 2-3 people for review before it is merged. 46 | 47 | 48 | *Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.* 49 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. 2 | 3 | The Universal Permissive License (UPL), Version 1.0 4 | 5 | Subject to the condition set forth below, permission is hereby granted to any person obtaining a copy of this software, associated documentation and/or data (collectively the "Software"), free of charge and under any and all copyright rights in the Software, and any and all patent rights owned or freely licensable by each licensor hereunder covering either (i) the unmodified Software as contributed to or provided by such licensor, or (ii) the Larger Works (as defined below), to deal in both 6 | 7 | (a) the Software, and 8 | (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if one is included with the Software (each a “Larger Work” to which the Software is contributed by such licensors), 9 | 10 | without restriction, including without limitation the rights to copy, create derivative works of, display, perform, and distribute the Software and make, use, sell, offer for sale, import, export, have made, and have sold the Software and the Larger Work(s), and to sublicense the foregoing rights on either these or other terms. 11 | 12 | This license is subject to the following condition: 13 | 14 | The above copyright notice and either this complete permission notice or at a minimum a reference to the UPL must be included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE.txt 2 | include *.txt 3 | include libexec/ocid 4 | include libexec/oci-growfs 5 | include libexec/oci_vcn_iface.awk 6 | include libexec/oci-image-cleanup 7 | include libexec/oci-utils-config-helper 8 | include libexec/oci-kvm-upgrade 9 | include libexec/oci-kvm-config.sh 10 | include libexec/oci-kvm-network-script 11 | include tests/*.py 12 | include tests/data/*.cfg 13 | include tests/data/tests/createattachdetachattachdetachdestroy/*.cfg 14 | include tests/data/tests/test_cli_kvm/*.cfg 15 | include tests/data/tests/test_cli_network_config/*.cfg 16 | include tests/data/tests/test_cli_network_config_attach/*.cfg 17 | include tests/data/tests/test_cli_network_config_configure/*.cfg 18 | include tests/data/tests/test_exec_helpers/*.cfg 19 | include tests/data/tests/test_exec_ocid/*.cfg 20 | include tests/data/tests/test_iscsiadm/*.cfg 21 | include tests/data/tests/test_network_helpers/*.cfg 22 | include tests/data/tests/test_oci_notify/*.cfg 23 | include data/*.service 24 | include data/oci-image-cleanup.conf 25 | include data/00-oci-utils.conf 26 | include data/10-oci-kvm.conf 27 | include data/91-oci-kvm.preset 28 | include data/91-oci-utils.preset 29 | include data/oci-image-cleanup.conf 30 | include data/oci-migrate-conf.yaml 31 | include tools/build_image/bin/* 32 | include tools/build_image/scripts/* 33 | include tools/build_image/templates/* 34 | include tools/build_image/Makefile 35 | include tools/build_image/README.md 36 | include tools/*.py 37 | include tools/execution/* 38 | include buildrpm/*.spec 39 | include man/man?/*.[158] 40 | -------------------------------------------------------------------------------- /PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.1 2 | Name: oci-utils 3 | Version: 0.14.0 4 | Summary: Oracle Cloud Infrastructure utilities 5 | Home-page: http://github.com/oracle/oci-utils/ 6 | Author: Laszlo Peter 7 | Author-email: laszlo.peter@oracle.com 8 | License: UPL 9 | Description: Oracle Cloud Infrastructure utilities 10 | Keywords: Oracle Cloud Infrastructure 11 | Platform: UNKNOWN 12 | Classifier: Development Status :: 3 - Alpha 13 | Classifier: Environment :: Console 14 | Classifier: Intended Audience :: Developers 15 | Classifier: Intended Audience :: Information Technology 16 | Classifier: Intended Audience :: System Administrators 17 | Classifier: Natural Language :: English 18 | Classifier: Operating System :: POSIX 19 | Classifier: Programming Language :: Python :: 3.6 20 | Classifier: Topic :: System :: Installation/Setup 21 | Classifier: Topic :: System :: Systems Administration 22 | Classifier: Topic :: Utilities 23 | Classifier: License :: OSI Approved :: Universal Permissive License (UPL) 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OCI Utilities 2 | 3 | Instances created using Oracle-Provided Images based on Oracle Linux include a pre-installed set of utilities that are designed 4 | to make it easier to work with Oracle Linux images. 5 | 6 | 7 | These utilities consist of a service component and related command line tools that can help with managing 8 | - block volumes (attach, remove, and automatic discovery); 9 | - secondary VNIC configuration; 10 | - discovering the public IP address of an instance; 11 | - retrieving instance metadata; 12 | - sending notification messages. 13 | 14 | The following list summarizes the components that are included in the OCI utilities. 15 | 16 | - `ocid` The service component of oci-utils. This normally runs as a daemon started via systemd. This service scans for changes in the iSCSI and VNIC device configurations and caches the OCI metadata and public IP address of the instance. 17 | - `oci-growfs` Expands the root filesystem of the instance to its configured size. 18 | - `oci-iscsi-config` Used to display and configure iSCSI devices attached to a compute instance. 19 | - `oci-metadata` Displays metadata for the compute instance. 20 | - `oci-network-config` Lists or configures virtual network interface cards (VNICs) attached to the Compute instance. 21 | - `oci-network-inspector` Displays a detailed report for a given compartment or network. 22 | - `oci-public-ip` Displays the public IP address of the current system in either human-readable or JSON format. 23 | - `oci-notify` Sends a message to an OCI notification service. 24 | 25 | For usage details, see the [OCI Utilities section of the Oracle Cloud Infrastructure documentation](https://docs.oracle.com/en-us/iaas/Content/Compute/References/ociutilities.htm). 26 | 27 | ## Contributing 28 | 29 | This project welcomes contributions from the community. Before submitting a pull request, please [review our contribution guide](./CONTRIBUTING.md) 30 | 31 | ## Security 32 | 33 | Please consult the [security guide](./SECURITY.md) for our responsible security vulnerability disclosure process 34 | 35 | ## License 36 | 37 | Copyright (c) 2019, 2024 Oracle and/or its affiliates. 38 | 39 | Released under the Universal Permissive License v1.0 as shown at 40 | . 41 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting security vulnerabilities 2 | 3 | Oracle values the independent security research community and believes that 4 | responsible disclosure of security vulnerabilities helps us ensure the security 5 | and privacy of all our users. 6 | 7 | Please do NOT raise a GitHub Issue to report a security vulnerability. If you 8 | believe you have found a security vulnerability, please submit a report to 9 | [secalert_us@oracle.com][1] preferably with a proof of concept. Please review 10 | some additional information on [how to report security vulnerabilities to Oracle][2]. 11 | We encourage people who contact Oracle Security to use email encryption using 12 | [our encryption key][3]. 13 | 14 | We ask that you do not use other channels or contact the project maintainers 15 | directly. 16 | 17 | Non-vulnerability related security issues including ideas for new or improved 18 | security features are welcome on GitHub Issues. 19 | 20 | ## Security updates, alerts and bulletins 21 | 22 | Security updates will be released on a regular cadence. Many of our projects 23 | will typically release security fixes in conjunction with the 24 | Oracle Critical Patch Update program. Additional 25 | information, including past advisories, is available on our [security alerts][4] 26 | page. 27 | 28 | ## Security-related information 29 | 30 | We will provide security related information such as a threat model, considerations 31 | for secure use, or any known security issues in our documentation. Please note 32 | that labs and sample code are intended to demonstrate a concept and may not be 33 | sufficiently hardened for production use. 34 | 35 | [1]: mailto:secalert_us@oracle.com 36 | [2]: https://www.oracle.com/corporate/security-practices/assurance/vulnerability/reporting.html 37 | [3]: https://www.oracle.com/security-alerts/encryptionkey.html 38 | [4]: https://www.oracle.com/security-alerts/ 39 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/oci-utils/fb5634c3550fa42484ed3560b2c901dd8db6e949/__init__.py -------------------------------------------------------------------------------- /bin/oci-attached-volumes: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility verifies if instance principal authentication with OCI is 8 | # configured correctly to create a working oci session. 9 | 10 | _PY3=/usr/bin/python3 11 | _PY_CMD=oci_attached_volumes_main.py 12 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 13 | 14 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 15 | 16 | -------------------------------------------------------------------------------- /bin/oci-compartmentid: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2021-2022 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown at 4 | # http://oss.oracle.com/licenses/upl. 5 | 6 | # shortcut to this compartment ocid 7 | 8 | METADATA=/usr/bin/oci-metadata 9 | THISOCID=$("${METADATA}" --get compartmentid --value-only) 10 | echo "${THISOCID}" 11 | -------------------------------------------------------------------------------- /bin/oci-image-migrate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | _PY3=/usr/bin/python3 12 | _PY_CMD=oci_image_migrate_main.py 13 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 14 | 15 | 16 | exec ${_PY3} ${s_dir}/migrate/${_PY_CMD} "$@" 17 | -------------------------------------------------------------------------------- /bin/oci-image-migrate-import: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | _PY3=/usr/bin/python3 12 | _PY_CMD=oci_image_migrate_import_main.py 13 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 14 | 15 | 16 | exec ${_PY3} ${s_dir}/migrate/${_PY_CMD} "$@" 17 | -------------------------------------------------------------------------------- /bin/oci-image-migrate-upload: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | _PY3=/usr/bin/python3 12 | _PY_CMD=oci_image_migrate_upload_main.py 13 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 14 | 15 | 16 | exec ${_PY3} ${s_dir}/migrate/${_PY_CMD} "$@" 17 | -------------------------------------------------------------------------------- /bin/oci-instanceid: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown at 4 | # http://oss.oracle.com/licenses/upl. 5 | 6 | # shortcut to this compartment ocid 7 | 8 | METADATA=/usr/bin/oci-metadata 9 | THISOCID=$("${METADATA}" --get id --value-only) 10 | echo "${THISOCID}" 11 | -------------------------------------------------------------------------------- /bin/oci-kvm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | 12 | _PY3=/usr/bin/python3 13 | _PY_CMD=oci_kvm_main.py 14 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 15 | 16 | 17 | exec ${_PY3} ${s_dir}/virt/${_PY_CMD} "$@" 18 | 19 | 20 | -------------------------------------------------------------------------------- /bin/oci-metadata: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | 9 | # utility assists with configuring iscsi storage on Oracle Cloud 10 | # Infrastructure instances. See the manual page for more information. 11 | 12 | _PY3=/usr/bin/python3 13 | _PY_CMD=oci_metadata_main.py 14 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 15 | 16 | 17 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 18 | 19 | 20 | -------------------------------------------------------------------------------- /bin/oci-network-inspector: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | _PY3=/usr/bin/python3 12 | _PY_CMD=oci_network_inspector_main.py 13 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 14 | 15 | 16 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 17 | -------------------------------------------------------------------------------- /bin/oci-notify: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | 9 | # utility assists with configuring iscsi storage on Oracle Cloud 10 | # Infrastructure instances. See the manual page for more information. 11 | 12 | 13 | _PY3=/usr/bin/python3 14 | _PY_CMD=oci_notify_main.py 15 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 16 | 17 | declare COMMAND 18 | declare -A TOPICOCID 19 | declare -A MSGDATA 20 | declare -A MSGTITLE 21 | declare notify_exec="${s_dir}/${_PY_CMD}" 22 | 23 | if [ "${1:0:1}" != '-' ] 24 | then 25 | # execute as is as the command line do not start with an option dash- 26 | exec ${_PY3} $notify_exec "$@" 27 | exit 0 28 | fi 29 | 30 | PARSED_ARGUMENTS=$(getopt --alternative --quiet --options c:t:f:h --longoptions config:,title:,file:,help -- "$@") 31 | eval set -- "$PARSED_ARGUMENTS" 32 | 33 | while : 34 | do 35 | case "$1" in 36 | -c|--config) 37 | COMMAND='config'; TOPICOCID=${2}; shift 2 38 | ;; 39 | -t|--title) 40 | COMMAND='message'; MSGTITLE=${2}; shift 2 41 | ;; 42 | -f|--file) 43 | COMMAND='message'; MSGDATA=${2}; shift 2 44 | ;; 45 | -h|--help) 46 | COMMAND='--help'; shift 47 | ;; 48 | --) 49 | shift; break 50 | ;; 51 | *) 52 | COMMAND='--help' 53 | ;; 54 | esac 55 | done 56 | 57 | if [ ${COMMAND} == '--help' ]; then 58 | exec ${_PY3} ${notify_exec} --help 59 | elif [ -z "${TOPICOCID+x}" ]; then 60 | # no topic, must be message. 61 | if [ -z "${MSGTITLE+x}" -o -z "${MSGDATA+x}" ]; then 62 | exec ${_PY3} ${notify_exec} --help 63 | else 64 | exec ${_PY3} ${notify_exec} message --title "${MSGTITLE}" --file "${MSGDATA}" 65 | fi 66 | else 67 | # topic is defined, must be config 68 | exec ${_PY3} ${notify_exec} config "$TOPICOCID" 69 | fi 70 | exit 0 71 | -------------------------------------------------------------------------------- /bin/oci-public-ip: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | 9 | # utility assists with configuring iscsi storage on Oracle Cloud 10 | # Infrastructure instances. See the manual page for more information. 11 | 12 | 13 | _PY3=/usr/bin/python3 14 | _PY_CMD=oci_public_ip_main.py 15 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 16 | 17 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 18 | 19 | -------------------------------------------------------------------------------- /bin/oci-show-config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # utility shows the configuration file data 9 | 10 | 11 | _PY3=/usr/bin/python3 12 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 13 | _PY_CMD=oci_show_config_main.py 14 | 15 | for ARG in "$@"; do 16 | if [[ "${ARG}" == *"help"* ]]; then 17 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 18 | exit 1 19 | fi 20 | done 21 | 22 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" | jq 23 | -------------------------------------------------------------------------------- /bin/oci-test-ip-auth: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility verifies if instance principal authentication with OCI is 8 | # configured correctly to create a working oci session. 9 | 10 | _PY3=/usr/bin/python3 11 | _PY_CMD=oci_test_ip_auth_main.py 12 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 13 | 14 | exec ${_PY3} ${s_dir}/${_PY_CMD} 15 | 16 | -------------------------------------------------------------------------------- /bin/oci-volume-data: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility to collect metadata of an iscsi volume. 8 | 9 | _PY3=/usr/bin/python3 10 | _PY_CMD=oci_volume_data.py 11 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 12 | 13 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 14 | 15 | -------------------------------------------------------------------------------- /contrib/oracle_virt_manager/README: -------------------------------------------------------------------------------- 1 | This host the terraform template file which can be used 2 | to deploy the Oracle Linux Virtualization Manager on top of an OCI KVM image 3 | 4 | expected variables : 5 | "tenancy_ocid": tenacy OCID to deploy the instance in 6 | "user_ocid": user ocid to remote connection 7 | "fingerprint": see https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 8 | "private_key_path": see https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 9 | "region": the region to use 10 | "compartment_id": compartment OCID to deploy the instance in 11 | "availability_domain_id": OCI availability domain to spawn the instance to 12 | "subnet_id": subnet ocid for the instance vNICs 13 | "instance_shape": OCI instance shape to use 14 | "instance_image_ocid": KVM image ocid 15 | "ssh_private_key_path": see https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 16 | "ssh_public_key_path": see https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 17 | "ssh_authorized_key_path": see https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 18 | "ssh_user": remote use to use for connection 19 | "http_proxy_url": http proxy url, 20 | "https_proxy_url": https proxy url 21 | 22 | References: 23 | KVM Image : https://www.oracle.com/linux/technologies/ol-kvm-image.html 24 | Virtualization manager : https://docs.oracle.com/en/virtualization/oracle-linux-virtualization-manager/index.html 25 | 26 | -------------------------------------------------------------------------------- /contrib/oracle_virt_manager/userdata/oci-tests-env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This file contains environement variables and script commands 9 | # to be push on remote instance within /etc/profile.d 10 | 11 | export http_proxy=${http_proxy_url} 12 | export https_proxy=${https_proxy_url} 13 | export no_proxy=169.254.169.254,.oraclecloud.com,.oraclecorp.com,.us.oracle.com,uk.oracle.com,yum-london.oracle.com 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /contrib/oracle_virt_manager/userdata/ovirt-engine-setup-answers.conf: -------------------------------------------------------------------------------- 1 | [environment:default] 2 | QUESTION/1/OVESETUP_APACHE_CONFIG_ROOT_REDIRECTION=str:yes 3 | QUESTION/1/OVESETUP_APACHE_CONFIG_SSL=str:automatic 4 | QUESTION/1/OVESETUP_CONFIG_ADMIN_SETUP=str:oracle 5 | QUESTION/1/OVESETUP_CONFIG_APPLICATION_MODE=str:virt 6 | QUESTION/1/OVESETUP_CONFIG_IMAGEIO_PROXY=str:yes 7 | QUESTION/1/OVESETUP_CONFIG_SAN_WIPE_AFTER_DELETE=str:no 8 | QUESTION/1/OVESETUP_CONFIG_VMCONSOLE_PROXY=str:yes 9 | QUESTION/1/OVESETUP_CONFIG_WEAK_ENGINE_PASSWORD=str:yes 10 | QUESTION/1/OVESETUP_CONFIG_WEBSOCKET_PROXY=str:yes 11 | QUESTION/1/OVESETUP_DIALOG_CONFIRM_SETTINGS=str:ok 12 | QUESTION/1/OVESETUP_DWH_ENABLE=str:yes 13 | QUESTION/1/OVESETUP_DWH_PROVISIONING_POSTGRES_ENABLED=str:automatic 14 | QUESTION/1/OVESETUP_DWH_PROVISIONING_POSTGRES_LOCATION=str:local 15 | QUESTION/1/OVESETUP_DWH_SCALE=str:2 16 | QUESTION/1/OVESETUP_ENGINE_ENABLE=str:yes 17 | QUESTION/1/OVESETUP_PROVISIONING_POSTGRES_ENABLED=str:automatic 18 | QUESTION/1/OVESETUP_PROVISIONING_POSTGRES_LOCATION=str:local 19 | QUESTION/1/OVESETUP_UPDATE_FIREWALL=str:yes 20 | QUESTION/1/ovirt-cinderlib-enable=str:no 21 | QUESTION/1/ovirt-provider-ovn=str:no 22 | QUESTION/2/OVESETUP_CONFIG_ADMIN_SETUP=str:oracle 23 | -------------------------------------------------------------------------------- /data/00-oci-utils.conf: -------------------------------------------------------------------------------- 1 | [auth] 2 | ; How root can authenticate to OCI services. 3 | ; auto - detect a method that works 4 | ; direct - use the root user's own .oci/config only 5 | ; proxy - use another user's .oci/config, see oci_sdk_user below 6 | ; ip - use instance principals 7 | ; auth_method = auto 8 | ; 9 | ; Use the oci_sdk_user's OCI configuration to authenticate to OCI services. 10 | ; This user must have a valid SDK config file and the corresponding API key 11 | ; must be set up in the OCI Console. 12 | ; For more information about configuring the OCI Python SDK see: 13 | ; https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/sdkconfig.htm 14 | ; oci_sdk_user = opc 15 | ; 16 | [network] 17 | ; Use these proxy settings if you require a proxy to access the OCI service 18 | ; endpoints 19 | ; 20 | ; http_proxy=http://myproxy:80/ 21 | ; https_proxy=https://myproxy:80/ 22 | ; 23 | [iscsi] 24 | ; Attach/detach iSCSI volumes automatically. Set to false to disable this 25 | ; function of ocid; default = true 26 | ; enabled=true 27 | 28 | ; Resize boot and iSCSI volumes automatically. Set to false to disable this 29 | ; function of ocid; default = true 30 | ; auto_resize=true 31 | ; 32 | ; Number of seconds to sleep between scans; default = 60 33 | ; scan_interval=60 34 | ; 35 | ; Increase if you wish to connect more than 8 volumes to the instance 36 | ; the maximum value is 32; the default = 8 37 | ; max_volumes=8 38 | ; 39 | ; Automatically detach iSCSI volumes that are not available (e.g. disconnected 40 | ; from the instance); the default = true 41 | ; auto_detach=true 42 | 43 | [vnic] 44 | ; Automatically configure/deconfigure network interfaces 45 | ; Set to false to disable this function of ocid 46 | ; enabled=true 47 | ; 48 | ; Number of seconds to sleep between scans 49 | ; scan_interval=60 50 | ; 51 | ; create virtual functions for configured nics in lieu of autoconfiguring vnics 52 | ; vf_net=false 53 | [public_ip] 54 | ; Attempt to detect the public IP address of the instance 55 | ; enabled=true 56 | ; 57 | ; Number of seconds to sleep between refresh attempts 58 | ; refresh_interval=600 59 | [ocid] 60 | ; Enables debug logging for the ocid service and implicitly for all oci-utils commands. 61 | ; The default is false. 62 | ; debug=true 63 | -------------------------------------------------------------------------------- /data/10-oci-kvm.conf: -------------------------------------------------------------------------------- 1 | [vnic] 2 | ; create virtual functions for configured nics in lieu of autoconfiguring vnics 3 | vf_net = true 4 | -------------------------------------------------------------------------------- /data/91-oci-kvm.preset: -------------------------------------------------------------------------------- 1 | # Also see: 2 | # https://fedoraproject.org/wiki/Starting_services_by_default 3 | 4 | # oci-kvm-config 5 | enable oci-kvm-config.service 6 | -------------------------------------------------------------------------------- /data/91-oci-utils.preset: -------------------------------------------------------------------------------- 1 | # Also see: 2 | # https://fedoraproject.org/wiki/Starting_services_by_default 3 | 4 | # ocid 5 | enable ocid.service 6 | -------------------------------------------------------------------------------- /data/oci-image-cleanup.conf: -------------------------------------------------------------------------------- 1 | # The following items will be deleted if they set to yes or y. 2 | # If the answer is not set, it will prompt user to answer. 3 | 4 | CLEAN_NET_CONFIG_FILES=No 5 | CLEAN_ETC_HOSTS=NO 6 | CLEAN_HOST_SSH_KEYS=No 7 | CLEAN_ROOT_PASSWD=No 8 | CLEAN_USER_SSH_KEYS=No 9 | CLEAN_HISTORY_DATA_LOG=YES 10 | -------------------------------------------------------------------------------- /data/oci-kvm-config.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=OCI KVM config 3 | Before=network-pre.target 4 | 5 | [Service] 6 | Type=oneshot 7 | TimeoutStartSec=120 8 | RemainAfterExit=yes 9 | ExecStart=/usr/libexec/oci-kvm-config.sh 10 | 11 | [Install] 12 | WantedBy=network-pre.target 13 | -------------------------------------------------------------------------------- /data/oci-vmnet.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Oracle Cloud Infrastructure virtual machine setup 3 | Requires=ocid.service 4 | Requires=network.service 5 | After=ocid.service 6 | After=network.service 7 | Before=libvirtd.service 8 | 9 | [Service] 10 | ExecStart=/usr/libexec/oci-vmnet 11 | Type=oneshot 12 | Restart=no 13 | StandardOutput=syslog 14 | StandardError=syslog 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | RequiredBy=libvirtd.service 19 | -------------------------------------------------------------------------------- /data/ocid.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Oracle Cloud Infrastructure utilities daemon 3 | After=iscsid.service 4 | 5 | [Service] 6 | Type=notify 7 | NotifyAccess=all 8 | ExecStart=/usr/libexec/ocid --no-daemon 9 | ExecStop=/usr/libexec/ocid --stop-all 10 | TimeoutStopSec=5 11 | PIDFile=/var/run/ocid.pid 12 | Restart=always 13 | StandardOutput=syslog 14 | StandardError=syslog 15 | TimeoutStartSec=300 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /lib/oci_utils/impl/init_script_templates.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | __all__ = ['_kvm_network_script_tmpl'] 8 | 9 | 10 | _kvm_network_script_tmpl = """ 11 | KVM_NETWORK_NAME=${__KVM_NETWORK_NAME__} 12 | KVM_NET_ADDRESS_SPACE=${__KVM_NET_ADDRESS_SPACE__} 13 | KVM_NET_BRIDGE_NAME=${__KVM_NET_BRIDGE_NAME__} 14 | VNIC_DEFAULT_GW=${__VNIC_DEFAULT_GW__} 15 | NET_DEV=${__NET_DEV__} 16 | RT_TABLE_NAME=${__RT_TABLE_NAME__} 17 | VNIC_PRIVATE_IP=${__VNIC_PRIVATE_IP__} 18 | 19 | start() { 20 | echo "Adding default route to ${VNIC_DEFAULT_GW}" 21 | /usr/sbin/ip route add default via ${VNIC_DEFAULT_GW} dev ${NET_DEV} table ${RT_TABLE_NAME} 22 | if [ $? -ne 0 ] 23 | then 24 | echo "Cannot add route : default ${VNIC_DEFAULT_GW} via dev ${NET_DEV} table ${RT_TABLE_NAME}" 25 | return 1 26 | fi 27 | echo "Adding rule for ${VNIC_PRIVATE_IP}" 28 | /usr/sbin/ip rule add from ${VNIC_PRIVATE_IP} lookup ${RT_TABLE_NAME} 29 | if [ $? -ne 0 ] 30 | then 31 | echo "Cannot add rule : from ${VNIC_PRIVATE_IP} lookup ${RT_TABLE_NAME}" 32 | return 1 33 | fi 34 | # Start the KVM network 35 | echo "Starting the network" 36 | /bin/virsh net-start --network ${KVM_NETWORK_NAME} 37 | if [ $? -ne 0 ] 38 | then 39 | echo "Cannot start kvm network" 40 | return 1 41 | fi 42 | echo "network started" 43 | 44 | # Add routes for KVM 45 | echo "Adding routes for KVM network" 46 | /usr/sbin/ip route add ${KVM_NET_ADDRESS_SPACE} dev ${KVM_NET_BRIDGE_NAME} scope link proto kernel table ${RT_TABLE_NAME} 47 | if [ $? -ne 0 ] 48 | then 49 | echo "Cannot add route : ${KVM_NET_ADDRESS_SPACE} dev ${KVM_NET_BRIDGE_NAME} scope link proto kernel table ${RT_TABLE_NAME}" 50 | return 1 51 | fi 52 | /usr/sbin/ip rule add from ${KVM_NET_ADDRESS_SPACE} lookup ${RT_TABLE_NAME} 53 | # Add firewall rules 54 | echo "Adding iptables rules routes for KVM network" 55 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${KVM_NET_ADDRESS_SPACE} -d 224.0.0.0/24 -j ACCEPT 56 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${KVM_NET_ADDRESS_SPACE} -d 255.255.255.255/32 -j ACCEPT 57 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${KVM_NET_ADDRESS_SPACE} ! -d ${KVM_NET_ADDRESS_SPACE} -j MASQUERADE 58 | return 0 59 | } 60 | 61 | stop() { 62 | /usr/bin/virsh net-destroy --network ${KVM_NETWORK_NAME} 63 | return $? 64 | } 65 | 66 | status() { 67 | /usr/bin/virsh net-info --network ${KVM_NETWORK_NAME} 68 | /usr/bin/virsh net-dhcp-leases --network ${KVM_NETWORK_NAME} 69 | } 70 | 71 | 72 | """ 73 | -------------------------------------------------------------------------------- /lib/oci_utils/impl/migrate/__init__.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | pass 8 | -------------------------------------------------------------------------------- /lib/oci_utils/impl/oci_show_config_main.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | """ Read the OCI SDK config and return the config data through stdout. 8 | """ 9 | 10 | import argparse 11 | import json 12 | import sys 13 | 14 | from oci_utils import oci_api 15 | 16 | debug = False 17 | 18 | 19 | def parse_args(): 20 | """ 21 | Define the args parser 22 | 23 | 24 | Returns 25 | ------- 26 | ArgumentParser: the parser. 27 | """ 28 | parser = argparse.ArgumentParser(prog='show_config', 29 | description='Utility to show oci config file for 1 profile') 30 | parser.add_argument('-c', '--config', 31 | action='store', 32 | dest='configfile', 33 | default='~/.oci/config', 34 | help='The cli/sdk config file, default is ~/.oci/config.') 35 | parser.add_argument('-p', '--profile', 36 | action='store', 37 | dest='profile', 38 | default='DEFAULT', 39 | help='The profile, default is DEFAULT') 40 | args = parser.parse_args() 41 | return args 42 | 43 | 44 | def response(status, **kwargs): 45 | """ 46 | Send a json formatted response to stdout, jdata is already json formatted. 47 | 48 | Parameters 49 | ---------- 50 | status: str 51 | The status. 52 | kwargs: key,value 53 | The data to convert to json. 54 | 55 | Returns 56 | ------- 57 | str 58 | The json formatted version of **kwargs 59 | """ 60 | resp = {'status': status} 61 | for key, val in kwargs.items(): 62 | resp[key] = val 63 | sys.stdout.write(json.dumps(resp) + '\n') 64 | sys.stdout.flush() 65 | 66 | 67 | def main(): 68 | """ 69 | Main program 70 | 71 | Returns 72 | ------- 73 | int 74 | 0 75 | """ 76 | args = parse_args() 77 | 78 | try: 79 | session = oci_api.OCISession(config_file=args.configfile, config_profile=args.profile, authentication_method=oci_api.DIRECT) 80 | except Exception as e: 81 | response('*** ERROR ***', data=str(e)) 82 | return 1 83 | 84 | response('OK', data=session.oci_config) 85 | return 0 86 | 87 | 88 | if __name__ == "__main__": 89 | sys.exit(main()) 90 | -------------------------------------------------------------------------------- /lib/oci_utils/impl/platform_helpers.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | import logging 8 | import os 9 | import re 10 | 11 | from oci_utils.metadata import InstanceMetadata 12 | from . import IP_CMD 13 | from . import sudo_utils 14 | 15 | _logger = logging.getLogger('oci-utils.impl.platform-helpers') 16 | 17 | 18 | def get_phys_device(): 19 | """ 20 | Find the primary ethernet device interface name. 21 | 22 | Returns 23 | ------- 24 | str 25 | The primary ethernet device name. 26 | """ 27 | try: 28 | # TODO : it seems that it is private_ip now 29 | private_ip = InstanceMetadata().refresh()['vnics'][0]['privateIp'] 30 | except Exception as e: 31 | _logger.debug('error checking metadata: %s', str(e)) 32 | return None 33 | phys_dev = None 34 | output = sudo_utils.call_output([IP_CMD, '-o', '-4', 'addr', 'show']) 35 | lines = output.splitlines() 36 | for line in lines: 37 | _l = line.decode().strip() 38 | if private_ip in _l: 39 | phys_dev = _l.split()[1] 40 | _logger.debug('%s physical devices found', len(phys_dev)) 41 | return phys_dev 42 | 43 | 44 | def get_block_devices(): 45 | """ 46 | Get all block devices. 47 | 48 | Returns 49 | ------- 50 | dict 51 | Dictionary of {'/dev/sbX': '/dev/disk/by-path/XXX'}, where the value 52 | of the key-value pair is a symlink to the key, if successful, 53 | None otherwise 54 | """ 55 | path_prefix = '/dev/disk/by-path' 56 | ret = {} 57 | try: 58 | dev_test = re.compile(r'/dev/[a-zA-Z]+$') 59 | for ent in os.listdir(path_prefix): 60 | path = '{}/{}'.format(path_prefix, ent) 61 | dev = os.path.abspath(os.path.join(path_prefix, os.readlink(path))) 62 | # Only include entries that point to a block device, 63 | # rather than a partition 64 | if dev_test.match(dev): 65 | ret[dev] = path 66 | except OSError as e: 67 | print(e) 68 | return None 69 | return ret 70 | -------------------------------------------------------------------------------- /lib/oci_utils/impl/virt/__init__.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | def block_device_has_mounts(device): 9 | """ 10 | Determines if a block device has filesystems mounted on any of its 11 | partitions. 12 | 13 | Parameters 14 | ---------- 15 | device: str 16 | The block device. 17 | 18 | Returns 19 | ------- 20 | bool: 21 | True if at least one partitions is mounted; 22 | False under any other conditions. 23 | """ 24 | parts = device.get('partitions') 25 | if not parts: 26 | return False 27 | return sum([len(x['mountpoint']) for x in list(parts.values())]) != 0 28 | -------------------------------------------------------------------------------- /lib/oci_utils/kvm/__init__.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | -------------------------------------------------------------------------------- /lib/oci_utils/kvm/utils.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | import subprocess 9 | 10 | 11 | def _call(cmd, log_output=True): 12 | """ 13 | Executes a comand and returns the exit code 14 | """ 15 | cmd.insert(0, 'sudo') 16 | try: 17 | subprocess.check_call(cmd, stderr=subprocess.STDOUT) 18 | except OSError as e: 19 | return 404 20 | except subprocess.CalledProcessError as e: 21 | if log_output: 22 | print("Error executing {}: {}\n{}\n".format(cmd, e.returncode, e.output)) 23 | return e.returncode 24 | return 0 25 | 26 | 27 | def _call_output(cmd, log_output=True): 28 | """ 29 | Executes a command and returns stdout and stderr in a single string 30 | """ 31 | cmd.insert(0, 'sudo') 32 | try: 33 | return subprocess.check_output(cmd, stderr=subprocess.STDOUT) 34 | except OSError as e: 35 | return 404 36 | except subprocess.CalledProcessError as e: 37 | if log_output: 38 | print("Error execeuting {}: {}\n{}\n".format(cmd, e.returncode, e.output)) 39 | return None 40 | return None 41 | 42 | 43 | def _call_popen_output(cmd, log_output=True): 44 | """ 45 | Executes a command and returns stdout and stderr in a single string 46 | """ 47 | cmd.insert(0, 'sudo') 48 | try: 49 | p = subprocess.Popen(' '.join(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 50 | return p.communicate()[0] 51 | except OSError as e: 52 | return 404 53 | except subprocess.CalledProcessError as e: 54 | if log_output: 55 | print("Error executing {}: {}\n{}\n".format(cmd, e.returncode, e.output)) 56 | return None 57 | return None 58 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/decorators.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | """ Module with oci image migrate related decorators. 8 | """ 9 | 10 | import time 11 | from functools import wraps 12 | 13 | from oci_utils.migrate.exception import OciMigrateException 14 | 15 | 16 | def state_loop(maxloop, intsec=1): 17 | """ 18 | Decorator to allow a function to retry maxloop times with an interval of 19 | intsec before failing. 20 | 21 | Parameters 22 | ---------- 23 | maxloop: int 24 | Maximum tries. 25 | intsec: int 26 | Interval in seconds. 27 | 28 | Returns 29 | ------- 30 | Method return value. 31 | """ 32 | def wrap(func): 33 | @wraps(func) 34 | def loop_func(*args, **kwargs): 35 | funcret = False 36 | for i in range(0, maxloop): 37 | # _logger.debug('State loop %d' % i) 38 | try: 39 | funcret = func(*args, **kwargs) 40 | return funcret 41 | except Exception as e: 42 | # _logger.debug('Failed, sleeping for %d sec: %s' 43 | # % (intsec, str(e))) 44 | if i == maxloop - 1: 45 | raise OciMigrateException('State Loop exhausted:') from e 46 | time.sleep(intsec) 47 | return loop_func 48 | return wrap 49 | 50 | 51 | def is_an_os_specific_method(some_method): 52 | """ 53 | A decorator to mark methods in the class OsSpecificOps as to be executed. 54 | 55 | Returns 56 | ------- 57 | Adds an attribute to the method. 58 | """ 59 | some_method._execute_as_os_specific = True 60 | return some_method 61 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/doc/oci_image_migrate_import.md: -------------------------------------------------------------------------------- 1 | # oci-utils.oci-image-migrate-import 2 | 3 | ## Introduction 4 | 5 | oci-image-migrate-import imports an image from the object storage to the 6 | custom images repository in teh Oracle Cloud Infrastructure. 7 | 8 | ## Usage 9 | 10 | # oci-image-migrate-import --help 11 | usage: oci-image-migrate-import.py -i IMAGENAME -b BUCKETNAME 12 | -c COMPARTMENTNAME 13 | [-d DISPLAYNAME] 14 | [-l {PARAVIRTUALIZED,EMULATED,NATIVE}] 15 | [--verbose] [--yes] [--help] 16 | 17 | Utility to import a (verified and modified) on-premise legacy images which 18 | was uploaded to object storage in the custom images folderof the Oracle 19 | Cloud Infrastructure. 20 | 21 | Arguments: 22 | -i IMAGENAME, --image-name IMAGENAME 23 | The name of the object representing the uploaded 24 | image. 25 | -b BUCKETNAME, --bucket-name BUCKETNAME 26 | The name of the object storage. 27 | -c COMPARTMENTNAME, --compartment-name COMPARTMENTNAME 28 | The name of the destination compartment. 29 | -d DISPLAYNAME, --display-name DISPLAYNAME 30 | Image name as it will show up in the custom images; 31 | the default is the image name. 32 | -l {PARAVIRTUALIZED,EMULATED,NATIVE}, --launch-mode {PARAVIRTUALIZED 33 | ,EMULATED,NATIVE} 34 | The mode the instance created from the custom image 35 | will be started; the default is PARAVIRTUALIZED. 36 | -v, --verbose Show verbose information. 37 | -y, --yes The answer on Yes/No questions is supposed to be yes. 38 | --help Display this help 39 | 40 | The environment variable _OCI_UTILS_DEBUG changes the logging level of 41 | the python code. 42 | 43 | ## Installation 44 | 45 | ### Prerequisites 46 | 47 | 1. The git package is installed. 48 | 49 | 1. The oci cli package is installed and configured. 50 | 51 | ### The install 52 | 53 | 1. Pull the software from github: 54 | 55 | # git clone https://github.com/guidotijskens/oci-utils.git 56 | 57 | 1. Checkout the migrate branch: 58 | 59 | # git checkout migrate 60 | 61 | 1. Build the rpm: 62 | 63 | # cd oci-utils 64 | # python3 ./setup.py -c create-rpm 65 | 66 | 1. Install the rpm: 67 | 68 | # yum localinstall oci-utils/rpmbuild/RPMS/noarch/oci-utils-migrate 69 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/doc/oci_image_migrate_upload.md: -------------------------------------------------------------------------------- 1 | # oci-utils.oci-image-migrate-upload 2 | 3 | ## Introduction 4 | 5 | oci-image-migrate-upload uploads an on-premise image to an object storage 6 | of the Oracle Cloud Infrastructure. 7 | 8 | ## Usage 9 | ``` 10 | $ oci-image-migrate-upload --help 11 | usage: oci-image-migrate-upload-main.py -i INPUT_IMAGE 12 | -b BUCKET_NAME 13 | [-o OUTPUT_NAME] 14 | [--verbose] 15 | [--yes] 16 | [--help] 17 | 18 | Utility to upload on-premise legacy images to object storage of the Oracle 19 | Cloud Infrastructure. 20 | 21 | Arguments: 22 | -i INPUT_IMAGE, --image-name INPUT_IMAGE 23 | The on-premise image name uploaded image. 24 | -b BUCKET_NAME, --bucket-name BUCKET_NAME 25 | The name of the object storage. 26 | -o OUTPUT_NAME, --output-name OUTPUT_NAME 27 | The name the image will be stored in the object 28 | storage. 29 | --verbose, -v Show verbose information. 30 | -y, --yes The answer on Yes/No questions is supposed to be yes. 31 | --help Display this help 32 | ``` 33 | 34 | The environment variable _OCI_UTILS_DEBUG changes the logging level of 35 | the python code. 36 | 37 | ## Installation 38 | 39 | ### Prerequisites 40 | 41 | 1. The git package is installed. 42 | 43 | 1. The oci cli package is installed and configured. 44 | 45 | ### The install 46 | 47 | 1. Pull the software from github: 48 | 49 | # git clone https://github.com/guidotijskens/oci-utils.git 50 | 51 | 1. Checkout the migrate branch: 52 | 53 | # git checkout migrate 54 | 55 | 1. Build the rpm: 56 | 57 | # cd oci-utils 58 | # python3 ./setup.py -c create-rpm 59 | 60 | 1. Install the rpm: 61 | 62 | # yum localinstall oci-utils/rpmbuild/RPMS/noarch/oci-utils-migrate 63 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/exception.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | """ Module with oci migrate related exceptions. 8 | """ 9 | 10 | 11 | class OciMigrateException(Exception): 12 | """ Exceptions for the Image Migrate to OCI context. 13 | """ 14 | __args = None 15 | 16 | def __init__(self, message=None): 17 | """ 18 | Initialisation of the Oci Migrate Exception. 19 | 20 | Parameters 21 | ---------- 22 | message: str 23 | The exception message. 24 | """ 25 | self._message = message 26 | assert (self._message is not None), 'No exception message given' 27 | 28 | if self._message is None: 29 | self._message = 'An exception occurred, no further information' 30 | 31 | def __str__(self): 32 | """ 33 | Get this OciMigrateException representation. 34 | 35 | Returns 36 | ------- 37 | str 38 | The error message. 39 | """ 40 | return str(self._message) 41 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/image_types/__init__.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | pass -------------------------------------------------------------------------------- /lib/oci_utils/migrate/migrate_data.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | """ Module containing data. 8 | """ 9 | from datetime import datetime 10 | 11 | # 12 | # some numbers. 13 | gigabyte = 2**30 14 | rmmod_max_count = 4 15 | qemu_max_count = 2 16 | # 17 | # the root for loopback mounts of partitions and logical volumes. 18 | loopback_root = '/mnt' 19 | # 20 | # the root of the migrate related packages. 21 | module_home = 'oci_utils.migrate.os_types' 22 | # 23 | # some flags. 24 | verbose_flag = False 25 | yes_flag = False 26 | # 27 | # time of execution. 28 | current_time = datetime.now().strftime('%Y%m%d%H%M') 29 | # 30 | # last resort nameserver. 31 | nameserver = '8.8.8.8' 32 | # 33 | # location of the configuration file 34 | oci_migrate_conf_file = '/etc/oci-utils/oci-migrate-conf.yaml' 35 | # 36 | # will be set to False is the image is not fit to migrate to OCI for whatever 37 | # reason. 38 | migrate_preparation = True 39 | # 40 | # the reason why the image is not fit for migration to OCI. 41 | migrate_non_upload_reason = '' 42 | # 43 | # it the migrate platform has logical volumes in use, a conflict is possible and 44 | # the local volume groups can be renamed; the default is no. 45 | local_volume_group_rename = False 46 | local_volume_groups = list() 47 | # 48 | # the migrate util configuration is saved here for use while in chroot jail. 49 | oci_image_migrate_config = dict() 50 | # 51 | # the os version information is saved here for use while in chroot jail. 52 | os_version_id = 'X' 53 | oracle_cloud_agent_location = None 54 | # 55 | # resolv.conf path 56 | resolv_conf_path = '' 57 | # 58 | # full path for the (verbose) results. 59 | result_filepath = '' 60 | result_filename = '' 61 | -------------------------------------------------------------------------------- /lib/oci_utils/migrate/os_types/__init__.py: -------------------------------------------------------------------------------- 1 | # oci-utils 2 | # 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | 7 | pass -------------------------------------------------------------------------------- /lib/oci_utils/packages/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/oci-utils/fb5634c3550fa42484ed3560b2c901dd8db6e949/lib/oci_utils/packages/__init__.py -------------------------------------------------------------------------------- /lib/oci_utils/packages/stun/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 pystun Developers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/oci_utils/packages/stun/README: -------------------------------------------------------------------------------- 1 | pystun from https://github.com/jtriley/pystun 2 | -------------------------------------------------------------------------------- /libexec/oci-growfs: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility to expand a partition or lvm and the filesystem. 8 | 9 | _PY3=/usr/bin/python3 10 | _PY_CMD=oci_growfs_main.py 11 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 12 | 13 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 14 | 15 | -------------------------------------------------------------------------------- /libexec/oci-kvm-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # /usr/libexec/oci-kvm-config.sh 4 | 5 | # Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. 6 | # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. 7 | 8 | defaultMTU=9000 9 | defaultMaxWait=240 10 | 11 | # To get the default number of VFs we use the number of CPU siblings which 12 | # corresponds to the BM model 13 | # BM.Standard1.36 have 36 siblings: 1 + 35 = 36 total allowable vNics 14 | # BM.Standard1.52 have 52 siblings: 2 + 25 = 52 total allowable vNics 15 | # (NOTE: Above is PhysicalNics + vNics) 16 | # Since we do not support assigning the vNic on the physical Nic to guests 17 | # the number of VFs end up being 35 on 1.36 and 50 on 2.52 18 | declare -i siblings=$(head -11 /proc/cpuinfo \ 19 | | grep 'siblings' \ 20 | | awk -F: '{print $2}' \ 21 | | sed 's/ //g') 22 | defaultNumVFs=$((siblings - 1)) 23 | ((siblings > 36)) && defaultNumVFs=$((siblings / 2 - 1)) 24 | [[ -z "${defaultNumVFs}" ]] && defaultNumVFs=16 25 | 26 | declare -i numVFs=${NUM_VFS:-${defaultNumVFs}} 27 | ((numVFs == 0)) && numVFs=${defaultNumVFs} 28 | 29 | declare -i vfMTU=${MTU:-${defaultMTU}} 30 | ((vfMTU < 1280)) && vfMTU=${defaultMTU} 31 | 32 | declare -i maxWait=${MAX_WAIT:-${defaultMaxWait}} 33 | ((maxWait < 5)) && maxWait=${defaultmaxWait} 34 | 35 | echo "Default MTU for interfaces: ${vfMTU}" 36 | echo "Default max virtual function count for interfaces: ${numVFs}" 37 | 38 | netSysPath=/sys/class/net 39 | for nic in ${netSysPath}/* 40 | do 41 | numVFDevPath=${nic}/device/sriov_numvfs 42 | if test -f "${numVFDevPath}" 43 | then 44 | nic_name=$(basename ${nic}) 45 | is_up=`/bin/cat ${nic}/carrier 2>/dev/null` 46 | if [ $? -ne 0 ] || [ "is_up" == 0 ] 47 | then 48 | # we have failed to open or content is '0', this means down 49 | echo "Bringing ${nic_name} link up" 50 | /sbin/ip link set ${nic_name} up 51 | if [ $? -ne 0 ] 52 | then 53 | echo "ERROR: Failed to bring up ${nic_name}" >&2 54 | exit 1 55 | fi 56 | fi 57 | echo "setting ${numVFs} as number of VFs for ${nic}" 58 | echo "${numVFs}" >${numVFDevPath} 59 | echo "setting hwmode node to vepa for ${nic}" 60 | /sbin/bridge link set dev ${nic_name} hwmode vepa 61 | vfNum=0 62 | echo "Waiting for VFs to appear" 63 | while ((vfNum < numVFs)) 64 | do 65 | vfNetDir="${nic}/device/virtfn${vfNum}/net/" 66 | while ((maxWait > 0)) && ! test -d ${vfNetDir} 67 | do 68 | sleep 0.25 69 | ((maxWait--)) 70 | done 71 | if ! test -d ${vfNetDir} 72 | then 73 | echo "ERROR: Virtual Function ${vfNum} never appeared!" >&2 74 | exit 1 75 | fi 76 | vfName="$(ls -1 ${vfNetDir} | head -1)" 77 | echo "Setting default MTU on VF ${vfName}" 78 | [[ -n "${vfName}" ]] && /sbin/ip link set dev ${vfName} mtu ${vfMTU} 79 | ((vfNum++)) 80 | done 81 | fi 82 | done 83 | 84 | echo "Calling /usr/libexec/oci-kvm-upgrade" 85 | /usr/bin/python3 /usr/libexec/oci-kvm-upgrade 86 | 87 | -------------------------------------------------------------------------------- /libexec/oci-kvm-network-script: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. 5 | 6 | 7 | # 8 | # KVM networks service command script 9 | # script run by KVM network systemd unit created while creating a virtual network 10 | # This script handles the start, stop and status method 11 | # 12 | 13 | start() { 14 | echo "Adding default route to ${__VNIC_DEFAULT_GW__}" 15 | /usr/sbin/ip route add default via ${__VNIC_DEFAULT_GW__} dev ${__NET_DEV__} table ${__RT_TABLE_NAME__} 16 | if [ $? -ne 0 ] 17 | then 18 | echo "Cannot add route : default ${__VNIC_DEFAULT_GW__} via dev ${__NET_DEV__} table ${__RT_TABLE_NAME__}" 19 | return 1 20 | fi 21 | echo "Adding rule for ${__VNIC_PRIVATE_IP__}" 22 | /usr/sbin/ip rule add from ${__VNIC_PRIVATE_IP__} lookup ${__RT_TABLE_NAME__} 23 | if [ $? -ne 0 ] 24 | then 25 | echo "Cannot add rule : from ${__VNIC_PRIVATE_IP__} lookup ${__RT_TABLE_NAME__}" 26 | return 1 27 | fi 28 | # Start the KVM network 29 | echo "Starting the network" 30 | /bin/virsh net-start --network ${__KVM_NETWORK_NAME__} 31 | if [ $? -ne 0 ] 32 | then 33 | echo "Cannot start kvm network" 34 | return 1 35 | fi 36 | echo "network started" 37 | 38 | # Add routes for KVM 39 | echo "Adding routes for KVM network" 40 | /usr/sbin/ip route add ${__KVM_NET_ADDRESS_SPACE__} dev ${__KVM_NET_BRIDGE_NAME__} scope link proto kernel table ${__RT_TABLE_NAME__} 41 | if [ $? -ne 0 ] 42 | then 43 | echo "Cannot add route : ${__KVM_NET_ADDRESS_SPACE__} dev ${__KVM_NET_BRIDGE_NAME__} scope link proto kernel table ${__RT_TABLE_NAME__}" 44 | return 1 45 | fi 46 | /usr/sbin/ip rule add from ${__KVM_NET_ADDRESS_SPACE__} lookup ${__RT_TABLE_NAME__} 47 | # Add firewall rules 48 | echo "Adding iptables rules routes for KVM network" 49 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${__KVM_NET_ADDRESS_SPACE__} -d 224.0.0.0/24 -j ACCEPT 50 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${__KVM_NET_ADDRESS_SPACE__} -d 255.255.255.255/32 -j ACCEPT 51 | /usr/sbin/iptables -t nat -A POSTROUTING -s ${__KVM_NET_ADDRESS_SPACE__} ! -d ${__KVM_NET_ADDRESS_SPACE__} -j MASQUERADE 52 | return 0 53 | } 54 | 55 | 56 | stop() { 57 | /usr/bin/virsh net-destroy --network ${__KVM_NETWORK_NAME__} 58 | return $? 59 | } 60 | 61 | status() { 62 | /usr/bin/virsh net-info --network ${__KVM_NETWORK_NAME__} 63 | /usr/bin/virsh net-dhcp-leases --network ${__KVM_NETWORK_NAME__} 64 | } 65 | 66 | 67 | if [ -z "${__KVM_NETWORK_NAME__}" ] || \ 68 | [ -z "${__KVM_NET_ADDRESS_SPACE__}" ] || \ 69 | [ -z "${__KVM_NET_BRIDGE_NAME__}" ] || \ 70 | [ -z "${__VNIC_DEFAULT_GW__}" ] || \ 71 | [ -z "${__NET_DEV__}" ] || \ 72 | [ -z "${__RT_TABLE_NAME__}" ] || \ 73 | [ -z "${__VNIC_PRIVATE_IP__}" ] 74 | then 75 | echo "ERROR: Environment not set correctly!" >&2 76 | exit 1 77 | fi 78 | 79 | case "$1" in 80 | start) 81 | start 82 | ;; 83 | stop) 84 | stop 85 | ;; 86 | status) 87 | status 88 | ;; 89 | *) 90 | exit 1 91 | ;; 92 | esac 93 | exit $? 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /libexec/oci-utils-config-helper: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # Read the OCI SDK config and return the config data through stdout. 9 | 10 | _PY3=/usr/bin/python3 11 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 12 | _PY_CMD=oci_show_config_main.py 13 | 14 | 15 | exec ${_PY3} ${s_dir}/${_PY_CMD} 16 | -------------------------------------------------------------------------------- /libexec/oci_vcn_iface.awk: -------------------------------------------------------------------------------- 1 | function prtiface(mac, iface, addr, sbits, state, vlan, vltag, secad) { 2 | if (iface != "") printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", mac, iface, addr, sbits, state, vlan, vltag, secad 3 | } 4 | BEGIN { iface = ""; addr = "-" } 5 | /^[0-9]/ { 6 | if (addr == "-") prtiface(mac, iface, addr, sbits, state, vlan, vltag, secad) 7 | addr = "-" 8 | sbits = "-" 9 | state = "-" 10 | macvlan = "-" 11 | vlan = "-" 12 | vltag = "-" 13 | secad = "-" 14 | if ($0 ~ /BROADCAST/ && $0 !~ /UNKNOWN/ && $0 !~ /NO-CARRIER/) { 15 | i = index($2, "@") 16 | if (1 < i) { 17 | j = index($2, ".") 18 | if (j < i) { # mac vlan (not used, no addrs) 19 | macvlan = substr($2, 1, i - 1) 20 | iface = substr($2, i + 1, length($2) - i - 1) # skip : at end 21 | addr = "" 22 | } else { # vlan 23 | vlan = substr($2, 1, i - 1) 24 | # extract iface/vltag from macvlan 25 | iface = substr($2, i + 1, j - i - 1) 26 | vltag = substr($2, j + 1, length($2) - j - 1) # skip : at end 27 | } 28 | } else { 29 | i = index($2, ":") 30 | if (i <= 1) { print "cannot find interface name"; exit 1 } 31 | iface = substr($2, 1, i - 1) 32 | } 33 | if ($0 ~ /LOWER_UP/) state = "UP" 34 | else state = "DOWN" 35 | } else iface = "" 36 | next 37 | } 38 | / link\/ether / { mac = tolower($2) } 39 | / inet [0-9]/ { 40 | i = index($2, "/") 41 | if (i <= 1) { print "cannot find interface inet address"; exit 1 } 42 | if (addr != "-") secad = "YES" 43 | addr = substr($2, 0, i - 1) 44 | sbits = substr($2, i + 1, length($2) - i) 45 | prtiface(mac, iface, addr, sbits, state, vlan, vltag, secad) 46 | } 47 | END { if (addr == "-") prtiface(mac, iface, addr, sbits, state, vlan, vltag, secad) } 48 | -------------------------------------------------------------------------------- /libexec/ocid: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # oci-utils 4 | # 5 | # Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. 6 | # Licensed under the Universal Permissive License v 1.0 as shown 7 | # at http://oss.oracle.com/licenses/upl. 8 | 9 | 10 | # Launsh ocid daemon with appropriate python program 11 | 12 | 13 | _PY3=/usr/bin/python3 14 | _PY_CMD=ocid_main.py 15 | s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))'` 16 | 17 | exec ${_PY3} ${s_dir}/${_PY_CMD} "$@" 18 | -------------------------------------------------------------------------------- /man/man1/oci-attached-volumes.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-attached-volumes.1 3 | .\" 4 | .\" Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-ATTACHED-VOLUMES 1 "SEPTEMBER 2022" Linux "User Manuals" 9 | .SH NAME 10 | oci-attached-volumes \- Collect data of iscsi volumes attached to this instance. 11 | .SH SYNOPSIS 12 | .B oci-attached-volumes 13 | usage 14 | 15 | .B oci-attached-volumes 16 | attached [-h|--help] [-i|--iqn] [-a|--all] [-o|--output-mode MODE] 17 | 18 | .B oci-attached-volumes 19 | all [-h|--help] [-o|--output-mode MODE] 20 | 21 | .B oci-attached-volumes 22 | uses the services of the python3 23 | .B oci-sdk 24 | package. 25 | 26 | .SH DESCRIPTION 27 | If the Oracle Cloud Infrastructure services authorisation allows listing the block volumes, 28 | .B oci-attached-volumes 29 | can show more details on the attached and other volumes. Otherwise only the 30 | .B iqn, ip address and port 31 | are displayed. More, if there is no authorisation to list all block volumes, the 32 | .B attached option falls back to 33 | 34 | .B oci-attached-volume 35 | attached --iqn 36 | 37 | and the 38 | .B all 39 | option shows a message and exits. 40 | 41 | .B oci-attached-volumes 42 | must be run with root privileges, either as user root or using 43 | .BR sudo(8). 44 | 45 | 46 | .TP 47 | oci-attached-volumes attached 48 | Show data on attached block volumes. 49 | .RS 50 | .IP -i,--iqn 51 | Displays the ipaddress, the port and the iqn of the attached block volumes 52 | .IP -a,--all 53 | Displays the ipaddress, the port, the iqn, the display name, the create date and the volume of the attached block volumes. The 54 | flags 55 | .B --iqn 56 | and 57 | .B --all 58 | are mutually exclusive. 59 | .IP --output-mode={json,text,parsable} 60 | Display list of the attached block volumes using json format, simple text or using parsable output. 61 | (default is text) 62 | .RE 63 | .TP 64 | oci-attache-volume all 65 | Show data on all block volumes in the availability domain. 66 | .RS 67 | .IP --output-mode={json,text,parsable} 68 | Display list of block volumes using json format, simple text or using parsable output 69 | (default is text) 70 | 71 | 72 | .SH EXAMPLES 73 | .PP 74 | .nf 75 | .RS 76 | sudo oci-attached-volumes attached --iqn --output-mode=parsable 77 | .RE 78 | .PP 79 | .nf 80 | .RS 81 | sudo oci-attached-volumes all --output-mode=text 82 | .RE 83 | .fi 84 | -------------------------------------------------------------------------------- /man/man1/oci-compartmentid.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-compartmentid.1 3 | .\" 4 | .\" Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-COMPARTMENTID 1 "JANUARY 2022" Linux "User Manuals" 9 | .SH NAME 10 | oci-compartmentid - Show the Oracle Cloud IDentifier of the compartment the instance is running. 11 | .SH SYNOPSIS 12 | .B oci-compartmentid 13 | 14 | 15 | .SH DESCRIPTION 16 | The 17 | .B oci-compartmentid 18 | returns the ocid (oracle cloud identifier) of the compartment the current instance is running in. 19 | 20 | .B oci-compartmentid 21 | expects 22 | .B oci-sdk 23 | and 24 | .B oci-utils 25 | installed. Authentication is attempted via 26 | .B oci-sdk 27 | configuration. If direct authentication fails, the instance principal authentication is tried. 28 | 29 | .SH "SEE ALSO" 30 | .BR ocid (8) 31 | .BR oci-utils.conf.d (5) 32 | -------------------------------------------------------------------------------- /man/man1/oci-image-migrate-upload.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-image-migrate-upload.1 3 | .\" 4 | .\" Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-IMAGE-MIGRATE 1 "JAN 2020" Linux "User Manuals" 9 | .SH NAME 10 | oci-image-migrate-upload \- assist the upload of an on-premise image to the 11 | .B object storage 12 | of the Oracle Cloud Infrastructure 13 | .SH SYNOPSIS 14 | .B oci-image-migrate-upload [-i|--image-name 15 | .I image name 16 | .B ] [-b|--bucket-name 17 | .I bucket_name 18 | .B ] [-o|--output-name 19 | .I output name 20 | .B ] [-y|--yes] [-v|--verbose] [--help] 21 | 22 | .SH DESCRIPTION 23 | The 24 | .B oci-image-migrate-upload 25 | utility uploads an on-premise image file to the 26 | .B object storage 27 | of the 28 | .B Oracle Cloud Infrastructure. 29 | 30 | .B oci-image-migrate-upload 31 | verifies the existence of the on-premise image file, of the 32 | .B object storage. 33 | It also checks if and image with the same name already exists 34 | in the 35 | .B object storage. 36 | 37 | .B oci-image-migrate-import 38 | does not need to be run with root priviliges as long as the user has the 39 | correct priviliges to access the 40 | .B Oracle Cloud Infrastructure 41 | and write priviliges in the directory where log and result files are written, 42 | as well as in the log file itself (by default /var/tmp/oci-utils.log). 43 | 44 | 45 | .B oci-image-migrate-import 46 | requires the 47 | .B oci-cli 48 | utility installed and configured. 49 | 50 | See 51 | .BR https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/cliinstall.htm 52 | or 53 | .BR https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/climanualinst.htm 54 | for more information. 55 | 56 | .SH OPTIONS 57 | .IP "-i|--image-name" 58 | The name of the image as present in the object storage. This option is mandatory. 59 | .IP "-b|--bucket-name" 60 | The name of the object storage or bucket in the 61 | .B Oracle Cloud Infrastructure 62 | where the imagefile is to be stored. This option is mandatory. 63 | .IP "-o|--output-name" 64 | The image name or the name of the image as it will be stored in the 65 | .B object storage of the 66 | .B Oracle Cloud Infrastructure. 67 | This argument is optional, the default is the image name. 68 | .IP "-y|--yes" 69 | The answer on Yes/No questions is supposed to be yes 70 | .IP "-v|--verbose" 71 | Show more information about the import on the console. 72 | .IP "--help" 73 | Print a summary of the command line options. 74 | 75 | .SH DIAGNOSTICS 76 | Returns an exit status of 0 for success or 1 if an error occured. 77 | 78 | .SH EXAMPLES 79 | .PP 80 | .nf 81 | .RS 82 | oci-image-migrate-upload --image-name /images/OracleLinux7.vmdk -b MyObjectStorage --output-name OracleLinux7U7 -v 83 | .RE 84 | .fi 85 | .PP 86 | Uploads the image file /images/OracleLinux7.vmdk , if it exists on premise to the object MyObjectStorage of the 87 | .B Oracle Cloud Infrastructure 88 | as OracleLinux7U7 on condition there is not yet and image with the same name present. 89 | 90 | .SH SEE ALSO 91 | .BR oci-image-migrate(1) 92 | .BR oci-image-migrate-import(1) 93 | .BR ocid (8) 94 | .BR oci-metadata (1) 95 | 96 | 97 | .SH COPYRIGHT 98 | Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 99 | -------------------------------------------------------------------------------- /man/man1/oci-instanceid.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-instanceid.1 3 | .\" 4 | .\" Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-COMPARTMENTID 1 "JANUARY 2022" Linux "User Manuals" 9 | .SH NAME 10 | oci-instanceid - Show the Oracle Cloud IDentifier of the instance. 11 | .SH SYNOPSIS 12 | .B oci-instanceid 13 | 14 | 15 | .SH DESCRIPTION 16 | The 17 | .B oci-instanceid 18 | returns the ocid (oracle cloud identifier) of the instanceid the current instance. 19 | 20 | .B oci-instanceid 21 | expects 22 | .B oci-sdk 23 | and 24 | .B oci-utils 25 | installed. Authentication is attempted via 26 | .B oci-sdk 27 | configuration. If direct authentication fails, the instance principal authentication is tried. 28 | 29 | .SH "SEE ALSO" 30 | .BR ocid (8) 31 | .BR oci-utils.conf.d (5) 32 | -------------------------------------------------------------------------------- /man/man1/oci-network-inspector.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-network-inspector.1 3 | .\" 4 | .\" Copyright(c) 2018 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-NETWORK-INSPECTOR 1 "AUG 2018" Linux "User Manuals" 9 | .SH NAME 10 | oci-network-inspector \- display Oracle Cloud Infrastructure networking information. 11 | .SH SYNOPSIS 12 | .B oci-network-inspector [--help] [-C 13 | .I COMPARTMENT_OCID 14 | .B | --compartment 15 | .I COMPARTMENT_OCID 16 | .B ] [-N 17 | .I VCN_OCID 18 | .B | --vcn 19 | .I VCN_OCID 20 | .B ] [--help] 21 | .SH DESCRIPTION 22 | The 23 | .B oci-network-inspector 24 | utility is used to display networking information for a given VCN or compartment, or for the configured tenancy in the Oracle Cloud Infrastructure. By default, all VCNs in all compartments accessible by the user will be displayed. 25 | 26 | It lists detailed information including security list, IP addresses and associated VNICs and instances in all of the subnets of a given VCN, compartment or the tenancy. 27 | 28 | It works on any system that has python36-oci-sdk installed and configured to authenticate with an Oracle Cloud Infrastructure API server. 29 | .SH OPTIONS 30 | .IP "-C COMPARTMENT_OCID, --compartment COMPARTMENT_OCID" 31 | Specify the compartment you wish to inspect. 32 | .IP "-N VCN_OCID, --vcn VCN_OCID" 33 | Specify the VCN you wish to inspect. 34 | .IP --debug 35 | Print diagnostic messages. 36 | .IP --help 37 | Print a summary of the command line options. 38 | .SH EXAMPLES 39 | .IP "oci-network-inspector" 40 | List all VCNs in all compartments that the user has access to, in the tenancy you configured for the Oracle Cloud Infrastructure SDK. 41 | 42 | .IP "oci-network-inspector\ -N\ ocid1.vcn.oc1.iad.aaaaaaaaadkljfasljw3lkj4lkdlkdkj34lkjfkj34jh4kjh3knkjbkjhvoa" 43 | List the network information for the specified VCN. 44 | 45 | .IP "oci-network-inspector\ -C\ ocid1.tenancy.oc1..aaaaaaaasdlkjsdlkj34ljclkjcsjcslsc93,kjskdjhfskh3hjskchskjdq" 46 | List the network information for all the VCNs in the specified compartment. 47 | 48 | .SH DIAGNOSTICS 49 | Return an exit status of 0 for success or 1 if an error occurred. 50 | -------------------------------------------------------------------------------- /man/man1/oci-public-ip.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-public-ip.1 3 | .\" 4 | .\" Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-PUBLIC-IP 1 "MAY 2018" Linux "User Manuals" 9 | .SH NAME 10 | oci-public-ip \- display the public IP address of the system 11 | .SH SYNOPSIS 12 | .\" .B oci-public-ip [-h|--human-readable] [-j|--json] [-g|--get] [-a|--all] [-s 13 | .B oci-public-ip [-h|--human-readable] [-j|--json] [-g|--get] [-s 14 | .I SOURCEIP 15 | .B | --sourceip 16 | .I SOURCEIP 17 | .B ] [-S 18 | .I STUN_SERVER 19 | .B | --stun-server 20 | .I STUN_SERVER 21 | .B ] [-L|--list-servers] [--instance-id 22 | .I OCID 23 | .B ] [--help] 24 | .SH DESCRIPTION 25 | The purpuse of the 26 | .B oci-public-ip 27 | utility is to print the public IP address of the current system. While it was intended to be run on an compute instance in the Oracle Cloud Infrastructure, it works on any system that can connect to the Internet. The oci-public-ip utility uses the STUN protocol, implemented by the pystun library. 28 | .SH OPTIONS 29 | .IP -h,\ --human-readable 30 | (default) Print the public IP address in a form intended for humans. 31 | .IP -j,\ --json 32 | Print the public IP address(es) in JSON format, intended for scripting. 33 | .IP -g,\ --get 34 | Print the public IP address(es) (and nothing else) to the standard output. 35 | Intended for scripting. 36 | .\" .IP -a,\ --all 37 | .\" Print all of the public IP addresses to the standard output. 38 | .IP "-s SOURCEIP, --sourceip SOURCEIP" 39 | Determine the public IP address that belongs to the 40 | .B SOURCEIP 41 | source IP address. 42 | .IP "-s STUN_SERVER, --stun-server STUN_SERVER" 43 | Use the given 44 | .B STUN_SERVER 45 | for finding the public IP of this host. By default, pystun iterates through the list of known public STUN servers. Use the 46 | .I -L 47 | or 48 | .I --list-servers 49 | option to print the list of STUN servers. 50 | .IP -L,\ --list-servers 51 | Print a list of known STUN servers. 52 | .IP "--instance-id OCID" 53 | Display the public IP address of the given instance 54 | instead of the current one. 55 | .IP --debug 56 | Print diagnostic messages. 57 | .IP --help 58 | Print a summary of the command line options. 59 | .SH DIAGNOSTICS 60 | Return an exit status of 0 for success or 1 if the public IP address could not be determined. 61 | .SH "SEE ALSO" 62 | .BR oci-metadata (1), 63 | .BR ocid (8), 64 | .BR oci-utils.conf.d (5) 65 | .BR https://tools.ietf.org/html/rfc5389 66 | .BR https://pypi.python.org/pypi/pystun 67 | -------------------------------------------------------------------------------- /man/man1/oci-volume-data.1: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-volume-data.1 3 | .\" 4 | .\" Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 5 | .\" Licensed under the Universal Permissive License v 1.0 as shown 6 | .\" at http://oss.oracle.com/licenses/upl. 7 | .\" 8 | .TH OCI-VOLUME-DATA 1 "JANUARY 2022" Linux "User Manuals" 9 | .SH NAME 10 | oci-volume-data - Show data about an iscsi volume. 11 | .SH SYNOPSIS 12 | .B oci-volume-data [-k KEY|--key KEY] [-p {name,iqn,ocid,portal,chap,attachestate,avdomain,compartment,attached,size,state}| --par {name,iqn,ocid,portal,chap,attachestate,avdomain,compartment,attached,size,state}] [-v|--value-only] 13 | 14 | 15 | .SH DESCRIPTION 16 | The 17 | .B oci-volume-data 18 | utility shows metadata of an oci iscsi volume. The 19 | .b KEY 20 | argument is mandatory and can be a display name, an ocid (Oracle Cloud IDentifier) or on iqn (iScsi Qualified Name). The 21 | .b PAR argument, if provided, will shown only the values for the specified parameter. If absent, all values will be displayed. If the 22 | .b VALUE-ONLY flag is set, only the values are displayed, not the parameter names. 23 | 24 | .B oci-volume-data 25 | expects 26 | .B oci-sdk 27 | and 28 | .B oci-utils 29 | installed. Authentication is attempted via 30 | .B oci-sdk 31 | configuration. If direct authentication fails, the instance principal authentication is tried. 32 | 33 | .B oci-volume-data 34 | must be run with root privileges, either as user root or using 35 | .BR sudo(8). 36 | 37 | .SH EXAMPLES 38 | .PP 39 | .nf 40 | .RS 41 | # oci-volume-data --key debian_vol_b --par compartment 42 | compartment: MyCompartment 43 | compartment id: ocid1.compartment.oc1..aaaaaaaabbbbbbbccccccccdddddddddeeeeeeeeefffffffff0011223344 44 | .RE 45 | .fi 46 | .PP 47 | shows the compartment name and compartment ocid of the specified volume. 48 | .PP 49 | .nf 50 | .RS 51 | # oci-volume-data --key debian_vol_b --par size --value-only 52 | 51GB 53 | .RE 54 | .fi 55 | .PP 56 | only shows the size of the volume. 57 | .SH "SEE ALSO" 58 | .BR ocid (8) 59 | .BR oci-utils.conf.d (5) 60 | -------------------------------------------------------------------------------- /man/man5/oci-utils.conf.d.5: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-utils.conf.d.5 3 | .\" 4 | .\" Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved. 5 | .\" 6 | .TH OCI-UTILS-CONF-D 5 "MAY 2018" Linux "User Manuals" 7 | .SH NAME 8 | oci-utils.conf.d \- configuration files for the ocid service 9 | 10 | .SH DESCRIPTION 11 | 12 | oci-utils can be configured using configuration files in the 13 | .I /etc/oci-utils.conf.d 14 | directory. The oci-utils package installs a file called 15 | .I 00-oci-utils.conf 16 | in this directory. This file lists all configuration options and explains their use. All setting are commented out 17 | using a semicolon at the start of the line. You can change the oci-utils configuration by uncommenting a setting 18 | and changing its value, however, it is better practice to create a new configuration file in 19 | .I /etc/oci-utils.conf.d 20 | that contains the changed configuration setting only and comments that explain why the change was made. The 21 | new file must include the section header (e.g. [vnic]) above the changed configuration setting. 22 | 23 | Configuration files in 24 | .I /etc/oci-utils.conf.d 25 | are read in alphanumeric order and can override settings in configuration files that are read earlier in that sequence. 26 | 27 | .SH EXAMPLES 28 | Create a new configuration file that disables automatic VNIC configuration in 29 | .BR ocid(8): 30 | .PP 31 | .nf 32 | .RS 33 | cat > /etc/oci-utils.conf.d/01-disable-vnic-config.conf << EOF 34 | [vnic] 35 | ; do not configure VNICs automatically on this instance 36 | ; because in conflicts with...etc... 37 | enabled = False 38 | EOF 39 | .RE 40 | .fi 41 | .PP 42 | Increase the frequency of looking for new iSCSI devices to every 30 seconds: 43 | .PP 44 | .nf 45 | .RS 46 | cat > /etc/oci-utils.conf.d/02-iscsi-scan-interval.conf << EOF 47 | [iscsi] 48 | ; scan for new iSCSI devices once an hour only 49 | scan_interval = 3600 50 | EOF 51 | .RE 52 | .fi 53 | .PP 54 | 55 | .SH "SEE ALSO" 56 | .BR ocid (8) 57 | 58 | -------------------------------------------------------------------------------- /man/man8/oci-growfs.8: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-growfs.8 3 | .\" 4 | .\" Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 5 | .\" 6 | .TH OCI-GROWFS 8 "AUG 2018" Linux "User Manuals" 7 | .SH NAME 8 | /usr/libexec/oci-growfs \- expand a filesystem to its configured size in a compute instance in the Oracle Cloud Infrastructure. 9 | 10 | .SH SYNOPSIS 11 | .B /usr/libexec/oci-growfs [-h] [-y|-n] 12 | 13 | .SH DESCRIPTION 14 | When a compute instance is created with a boot volume >= 50GB (default minimum size), or is resized to a larger size, the instance does not automatically use the entire volume. By default, the boot volume will only extend to the minimum size (50GB). 15 | 16 | The purpose of 17 | .B oci-growfs 18 | is to expand the root partition to fully utilize the allocated boot volume size. 19 | When the partition already extends to the entire volume, no changes are made to the system. 20 | The script is called by the 21 | .BR ocid 22 | service if this option is enabled by the 23 | .B auto_resize 24 | flag in the 25 | .B [iscsi] 26 | section in 27 | .BR oci-utils.conf.d(5) 28 | 29 | For LVM based root filesystem, oci-growfs only support Logical Volume created on Logical Group 30 | built with only one Physical volume. 31 | 32 | .B oci-growfs 33 | must be run on a compute instance in the Oracle Cloud Infrastructure, and it requires root privilege. 34 | 35 | Note: in the current release, only the root filesystem can be resized using 36 | .B oci-growfs. 37 | 38 | Note: in the current release, only 39 | .B xfs 40 | and 41 | .B ext4 42 | filesystems are supported. 43 | 44 | .SH OPTIONS 45 | .IP -h | --help 46 | print the usage help information. 47 | .IP -y | --yes 48 | answer 'y' to all questions. 49 | .IP -n | --no 50 | answer 'n' to all questions. 51 | 52 | .SH DIAGNOSTICS 53 | Return an exit status of 0 for success or non-0 if an error occured. 54 | 55 | .SH "SEE ALSO" 56 | .BR ocid (8) 57 | .BR oci-utils.conf.d (5) 58 | -------------------------------------------------------------------------------- /man/man8/oci-image-cleanup.8: -------------------------------------------------------------------------------- 1 | .\" Process this file with 2 | .\" groff -man -Tascii oci-image-cleanup.8 3 | .\" 4 | .\" Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved. 5 | .\" 6 | 7 | .TH OCI-IMAGE-CLEANUP 1 "03 May 2018" Linux "User Manuals" 8 | .SH NAME 9 | oci-image-cleanup \- This script runs a set of cleanup steps to prepare OL compute instance for snapshot. 10 | 11 | .SH SYNOPSIS 12 | .B /usr/libexec/oci-image-cleanup [-h|--help] 13 | 14 | .B /usr/libexec/oci-image-cleanup [-c 15 | .I CONFIG_FILE 16 | .B |--config-file= 17 | .I CONFIG_FILE 18 | .B ] [-d 19 | .I BACKUP_DIR 20 | .B | --backup-dir 21 | .I BACKUP_DIR 22 | .B ][-f|--force ] [--dry-run] 23 | 24 | .B /usr/libexec/oci-image-cleanup [-r 25 | .I BACKUP_DIR 26 | .B |--restore-dir= 27 | .I BACKUP_DIR 28 | .B ][-f|--force ] [--dry-run] 29 | 30 | .SH DESCRIPTION 31 | This script runs a set of cleanup steps to prepare OL instances in Oracle Cloud Infrastructure for creating custom images 32 | WARNING!!! This script will clear ssh keys and root passwd. 33 | Upon execution of this script, if you choose to clear the ssh keys, you will no longer be able to login to this instance with your existing credentials. 34 | You will need to create a new custom image of this instance first and then create a new compute instance from that custom image to login. 35 | 36 | .BR oci-image-cleanup(8) 37 | requires root privileges. 38 | 39 | More info on custom images can be found here: 40 | 41 | https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingcustomimages.htm 42 | 43 | .SH OPTIONS 44 | 45 | .IP "-f | --force" 46 | No prompt for confirmation. force to cleanup or restore. 47 | When work with a config file, force will cleanup an item unless it is configured as No. 48 | 49 | .IP "--dry-run" 50 | for dry run, no real action is done. but show what the command with options will do. 51 | If no options are provided, it will run cleanup in interactive mode. 52 | 53 | .IP "-r | --restore=" 54 | Restore files from BACKUP_DIR 55 | 56 | .IP "-d | --backup-dir=" 57 | Specify dir to backup deleted files. 58 | Default backup dir is /dev/shm/oci-utils/image-cleanup-backup 59 | 60 | .IP "-c | --config-file=" 61 | Specify config file. 62 | Sample config file is /etc/oci-utils/oci-image-cleanup.conf. 63 | 64 | .IP "-h | --help" 65 | print this help message 66 | 67 | 68 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/oci-utils/fb5634c3550fa42484ed3560b2c901dd8db6e949/requirements.txt -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [egg_info] 2 | tag_build = 3 | tag_date = 0 4 | tag_svn_revision = 0 5 | 6 | [pep8] 7 | max-line-length = 120 8 | 9 | [sdist] 10 | dist-dir = rpmbuild/SOURCES/ 11 | 12 | [create_rpm] 13 | rpm-top-dir = rpmbuild 14 | spec-file-path = buildrpm/oci-utils.spec 15 | 16 | [sync_rpm] 17 | rpm-top-dir = rpmbuild 18 | spec-file-path = buildrpm/oci-utils.spec 19 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tests/automation/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/oci-utils/fb5634c3550fa42484ed3560b2c901dd8db6e949/tests/automation/__init__.py -------------------------------------------------------------------------------- /tests/automation/configuration/BUILD.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown at 4 | # http://oss.oracle.com/licenses/upl. 5 | # 6 | # makefile for oci-utils-automation 7 | # 8 | 9 | as user: 10 | 11 | update files, sources, spec, gpg keys 12 | run 13 | make help 14 | shows help info 15 | make showversion 16 | shows spec versiondata 17 | make distro 18 | creates compressed tarball 19 | make directorystructure 20 | creates the directorystructure for building the rpms 21 | make rpms 22 | builds the rpms 23 | make repos 24 | creates the repo directories 25 | make publish 26 | copies the rpms to the destination, the default is /var/www/html/channel_rpms/$USER 27 | the default destination is in the webserver area. 28 | make clean 29 | 30 | make copyrpm RPM=[path|url to rpm] DISTRO=[OL7|OL8] 31 | copies the rpm to the appropriate repository. 32 | make cleanrepo 33 | 34 | current supported distributions: 35 | .el7 36 | .el8 37 | -------------------------------------------------------------------------------- /tests/automation/configuration/README.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown at 4 | # http://oss.oracle.com/licenses/upl. 5 | # 6 | # makefile for oci-utils-automation 7 | # 8 | =================================================== 9 | oci-utils-automation - For Oracle Internal Use Only 10 | =================================================== 11 | The oci-utils-automation rpms define the repofiles for 12 | accessing rpms to test and creates the repository 13 | directories if they do not exist yet. 14 | 15 | usage: 16 | - pull the software tree 17 | - change directory to the software root 18 | - run 'make publish' 19 | - run 'make clean' 20 | - run 'make copyrpm RPM=[path|url] DISTRO=[OL7|OL8]' 21 | - run 'make cleanrepo' 22 | 23 | copy rpms to the repositories: 24 | make copyrpm RPM= DISTRO= 25 | -------------------------------------------------------------------------------- /tests/automation/configuration/RPM-GPG-KEY-oracle-7: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v1.4.5 (GNU/Linux) 3 | 4 | mQENBEwtJWoBCACpiY2rGA6T0ceBi92X88/QclytVBjtDRohOVzs3pmIPh3ULqsW 5 | G323nmyKbKQBBSjh9OnuO9Y09VG8mzr/w9YV0Ix4cI9/HDTERZ2+TR5u+VNn5J5h 6 | yvwQSN/FEK6oH2+mz7O0yUNleN7UltR4MOEkHIoAhIvv+1AQQKN3OM8oalz+3gv/ 7 | zz9rAoQczQzT7QWOtBrsRMZgBrKXY/TpJrpVSO3Hx8CnbhKGtLxCCrxZ5v7hh1ht 8 | 3CRAr2+h5bDA9KP6vBZWKEs7NgcvtZFDY6EJc7AoApr3phX9hHE2+snTxe82DkFT 9 | uA69C8wLyjPCoSy+tcaCqJKOZelNy9RN/WKRABEBAAG0RE9yYWNsZSBPU1MgZ3Jv 10 | dXAgKE9wZW4gU291cmNlIFNvZnR3YXJlIGdyb3VwKSA8YnVpbGRAb3NzLm9yYWNs 11 | ZS5jb20+iQE8BBMBAgAmAhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AFAlNhkUEF 12 | CSaOl9cACgkQcvl7dOxVHwNHFQf9G2ZI5ZH8T1VASvQteTyUR7uNgqXEbJhi9zZO 13 | 7EO26+wzkj9EGLmH1COdUApZ1cINsYfGGgUJT5mfcRV3yYZbwc4AZJbJe0z7C5Yu 14 | ZLs5W0ryV4bzIqcWnVphIAOwmxMxIVGz8Cr1Dsyyal7ORgYzdfOppYetwtZ+J+Wn 15 | /oVgFkh9v19l/CltBkRh2SqgUZYfCoELo7hUzLNh7cw2av8rcSUKSH3ra9MvpYfS 16 | ANCnouzbgKix1gD6niT3pm1s5II3VuQ2vEcJunnoRFci9FzLXelTuL00MvuxERr7 17 | Fsqm1/D2JfKDbE09qy5bLWrWaTM6zOFQKN7F2edY2uaukLT6/w== 18 | =Djed 19 | -----END PGP PUBLIC KEY BLOCK----- 20 | -------------------------------------------------------------------------------- /tests/automation/configuration/RPM-GPG-KEY-oracle-8: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v2.0.14 (GNU/Linux) 3 | 4 | mQINBFyr9g0BEADVpB339zKe27a0LAQn4jWDYfX4ttCgYbX1sgyOKclO2ZMxdLIF 5 | 2Tz1KrmLim0am6ltTYIVpP0hVHsH1iy7MaVg1K/vaYIS8djL3SrmjX70P3QKIru5 6 | Hr8iGOKvX4jMHbUZmghZyVRdvl2QNc9oh+l+i3CzyChFlNV3dGlmsaBRT6o5Ecvn 7 | ZQ8cVdsbFnRAYpCDO65wOCujWNVe2F5eA6xy4mQfVOCuF7jY1sb4zRanTVE0hZyy 8 | ig6OeTZjutjr7V+kDrT5K3PdXn2kPsVWcEdJJOta+hqJ9wnA1aiTJNNpvRP6fJtv 9 | iw8poJqJID7VUPTfGp38k6sPfe4BmqEfRSUbNT5JKCFvlp4Y39pHzmKfX+8jjeZ2 10 | XgBx/Z4GsW6q/tAOksZ8nHB/XIPZkr6V+tXXZP4D5peNIWLxhza585FDiGi8d1Z4 11 | KIMpeqJhUu24vre9rmYn2wOFP6GYZfi1KOMImAjQC13BktpAlSqDNzCQepoNfvoG 12 | iO8v0sO8mHy16fpp+hk7T4hveScoYYIBaTMcdTElvPjA5mgXTaBF/qttF1LlFf51 13 | PvNkKQVoCR7V9+puZGsWeq9Kv+GaUYC3uKo96MKCO4G34uSu9uYo4eZ3yr7GslSM 14 | 6rB0Fi4yfDT9R9mS8YHpuCKhgQ5IUBl6x72h1s02+maheeH0CZMbV/7hEwARAQAB 15 | tERPcmFjbGUgT1NTIGdyb3VwIChPcGVuIFNvdXJjZSBTb2Z0d2FyZSBncm91cCkg 16 | PGJ1aWxkQG9zcy5vcmFjbGUuY29tPokCPgQTAQIAKAUCXKv2DQIbAwUJJZgGAAYL 17 | CQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQglYuqa2YbaN53w/+Lx4cqKifslEa 18 | BpWz4yqHcAtuz25sCW4wbH4V56EfKZAh+WQ/JwPFybSywqbzgIUrIlzg8CMuUnKM 19 | 5BElUkKPDYI+CjvUtP0B9eFThqjp7WNly0IQX8qC6p/gTLDXuEbKLj+EfLvKihqc 20 | L2tJIaQWiQAaftG5DFHIanZpVr88eXJwAMCle/m29x7K4g0c959vZdFF7iggIcHl 21 | TJ3GWGbLzRXi0fXVTQJAltR5Gx+FnRnSmAplL6j1UG1cgesZrfJZbNsl0+5Eq4oH 22 | UN3sTgaqTYaMWR7jH6HFF+5d05ndpltLXbG6Ia1c1Z4e+ha2ehBnceBxSCt5VT5z 23 | tmvJCm4QT4+S8AKsdQLpx3XWTWs5B41DYy3yQHaQz+So42YEtvGCemPsCfkid8ZN 24 | Eltl9KM0iHYJbFehv2ckZe4RVNEDVgurlnEEKICvhfwS4bz2IQZPSYQLGLmUYwpp 25 | kf2VjkDhTQUMp1iqLXsolCjDfTcZrlUaAEXP7A1wuLBlAEHE/yZOZbqcgE4AZKkV 26 | nJYmu2lrSkNhisMOVsVhDyCyFEw1+fD+RnvR9uNHOqgeTV/6kOyGu+nC8dnwKyq0 27 | wLJzu+8ENdemcvld9pwx3FPWTGQ4GGNJ3MVdwfwnYkg5vKGDSOmPDuEnnxkaPJrT 28 | JIHSJXfjSg/M0PiLGXcOMpGVNebpSQK5Ag0EXKv2DQEQAKHZmlvNo+/+amYh9Ogn 29 | lzSUctqLENke8m7Q7HXUakEZgTfRU0an+9TmfoUCyHS11q3A0l+FoB/FBT45ByxU 30 | df850oQd0PApqo5NxNpQCqYgOCOpTHT0SnRh9gQCDGgzfYSZl8ME+izEU5WOjQ51 31 | g/2ajODXGIWHPwYE8lZyF7tE7bFNEwve7sIrQefAR0eASz8PMFdQ5US/vYZQ+jeL 32 | U2dZqfl2B7AnP7MuXpa31MkhB3laYdH+vWaQLPbk/bh7cvKtkDbDHY13NS2nTpWy 33 | fjeUCFpDHupzMNkclc0If44WKA1a0sO7d6mBWyVM0IgrCxieXJ/EZVFkhXEulcGu 34 | +L0iHhkR9NA6dRXvC/wJnsCASjzxFqyzlhTfNR1QwWdZJpC8Il9oH3VcrT4TtEvJ 35 | DxuXTMqeMSOfNSsdqaiE9u6tgbC13qBTvbsoBg9Rs2hY2nRqUhNhvMoRbt1U1qXw 36 | hn/9g1f+1i3GvED6j2AuWMnU9zehR32iuGQl48ko428bREPz08AY++v3/n4U/cbs 37 | oJzAvCg1+WYQe26v0mIJIuzOmeFRmXcaTHUZvyY6aqSvQeOno0h1cjRZAN9T6Z8q 38 | lYbwh8yhGNlfybQPmld/oeiDNVr43sSl6W02TOLFZ36h2eGpt2LKUVz+zFQwrAdF 39 | u6Uo/1lgGRGbzBezNgUCkQCLABEBAAGJAiUEGAECAA8FAlyr9g0CGwwFCSWYBgAA 40 | CgkQglYuqa2YbaO4Eg//WREjdHosvTLPbjDwmtH0R3Twis/eqHPSq57I9jDSOvRD 41 | Wkv4/CidBu1+FsTDpInn4wiAIE9eMb/L89Cc2Y5LyzHlzORJMEgzEqcjIewqRcEy 42 | vMbyTnx4Gc4hKiMhRcMLWQuWp6/JT09+B3oPzQLXHvuAuKu0ZjFJl16obdoL7tAT 43 | AOPtqmxkwt22G1lBkGUVCOiEuwg1+9AgiMhDHt6Gg8wHjKoQiHv4peGDKxcldfTF 44 | TAH03vx+2mwT61a/RjE1YqHzmlqmTa89SDNDStrG2VikSB0YdDuqSzB6FMcURktJ 45 | wwyhOKEjJ4c20wZG5xQfiJfOcij2QYPW5vYtQNCnKfspsF7BCP/GXdYATgyajCxp 46 | 4pkNsAZlRyHUx1zPMR1E1+se+l5s18y0V+b+1YBEmAmcEML9Rev+Rbyd+YXmJ+P9 47 | rDThkvPXxV+4HZgl0mXvTd1CUUnNnd40ZSzFo8hTmr/+j2T7iR3wcxnoyv/d8MOU 48 | quYsKDLdBr9ng+Cvbf/8lNJJ6dbCQAcEXvRn8FKjq+iP+hHPXXOh/FrMvBJrbD3V 49 | 6F65eyvyLMN74Caxd2B2ru01yLNGARZr8iOH3cdt4byC0lSA51yNePooe6HfgCEA 50 | sFEvovilr7kFbspDGrP49wh0evtRDPmqfjMLiiaRxOXefOjbh8XqrfNGDTCQzdE= 51 | =dTZ0 52 | -----END PGP PUBLIC KEY BLOCK----- 53 | -------------------------------------------------------------------------------- /tests/automation/configuration/oci-utils-automation.repo-7: -------------------------------------------------------------------------------- 1 | [oci-utils-automation] 2 | name=Oracle Linux $releasever - $basearch - latest 3 | baseurl=http://_IPIP_/yum/_UUUU_/OL7/$basearch/ 4 | gpgcheck=1 5 | enabled=1 6 | 7 | -------------------------------------------------------------------------------- /tests/automation/configuration/oci-utils-automation.repo-8: -------------------------------------------------------------------------------- 1 | [oci-utils-automation] 2 | name=Oracle Linux $releasever - $basearch - latest 3 | baseurl=http://_IPIP_/yum/_UUUU_/OL8/$basearch/ 4 | gpgcheck=1 5 | enabled=1 6 | 7 | -------------------------------------------------------------------------------- /tests/automation/configuration/oci-utils-automation.spec: -------------------------------------------------------------------------------- 1 | Summary: oci-utils automation build and test utils 2 | Name: oci-utils-automation 3 | Version: 0.2.2 4 | Url: http://cloud.oracle.com/iaas 5 | Release: 0%{?dist} 6 | License: UPL 7 | Group: Development/Tools 8 | Source0: oci-utils-automation-%{version}.tar.gz 9 | BuildArch: noarch 10 | 11 | BuildRoot: /tmp/oci-utils-automation 12 | 13 | %define is_el7 %(test "%{?dist}" = ".el7" && echo 1 || echo 0) 14 | %define is_el8 %(test "%{?dist}" = ".el8" && echo 1 || echo 0) 15 | 16 | %define os_id /etc/redhat-release 17 | # Default to ol7 18 | %if %is_el7 19 | %define os_version 7|7Server 20 | %define os_tag 7 21 | %endif 22 | 23 | %if %is_el8 24 | %define os_version 8|8Server 25 | %define os_tag 8 26 | %endif 27 | 28 | Requires: rpm 29 | Requires: %{os_id} 30 | 31 | %description 32 | This package contains utils for automation of oci-utils build and testing 33 | 34 | %prep 35 | %setup -q 36 | 37 | %build 38 | 39 | %install 40 | [ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf "${RPM_BUILD_ROOT}" 41 | mkdir -p "${RPM_BUILD_ROOT}/etc/yum.repos.d" 42 | mkdir -p "${RPM_BUILD_ROOT}/usr/share/rhn" 43 | # cp oci-utils-automation.repo-%{os_tag} ${RPM_BUILD_ROOT}/etc/yum.repos.d/oci-utils-automation.repo 44 | cp %{getenv:HOME}/git_repo/tests/automation/configuration/oci-utils-automation.repo-%{os_tag} ${RPM_BUILD_ROOT}/etc/yum.repos.d/oci-utils-automation.repo 45 | cp RPM-GPG-KEY-oracle-%{os_tag} ${RPM_BUILD_ROOT}/usr/share/rhn/RPM-GPG-KEY-oracle 46 | 47 | %clean 48 | [ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf "${RPM_BUILD_ROOT}" 49 | 50 | %files 51 | %defattr(644, root, root) 52 | /etc/yum.repos.d/oci-utils-automation.repo 53 | /usr/share/rhn/RPM-GPG-KEY-oracle 54 | 55 | %pre 56 | # Exit if this is a GIT machine 57 | if [ -f /usr/local/git/etc/mkks-iso-version ] || [ -f /etc/OSCC-Release ] ; then 58 | echo " 59 | This is a GIT machine. This package is not for production machines. 60 | 61 | Aborting... 62 | " 63 | exit 1 64 | fi 65 | 66 | # Check OS release 67 | egrep "%{os_version}" /etc/redhat-release > /dev/null 2>&1 68 | if [ $? -ne 0 ] ; then 69 | echo " 70 | Installed OS is not supported by this version of oci-utils-automation. 71 | " 72 | exit 1 73 | fi 74 | 75 | %post 76 | # Backup and install config files 77 | tstamp=`date -u +%Y-%m-%d-%H:%M` 78 | [ -f /etc/sysconfig/rhn/sources ] && mv /etc/sysconfig/rhn/sources /etc/sysconfig/rhn/sources.uln-$tstamp 79 | [ -f /etc/yum.repos.d/oci-utils-automation.repo ] && cp /etc/yum.repos.d/oci-utils-automation.repo /etc/yum.repos.d/oci-utils-automation.repo.uln-$tstamp 80 | # cp /usr/share/rhn/RPM-GPG-KEY-oracle /usr/share/rhn/RPM-GPG-KEY-oracle 81 | cp /usr/share/rhn/RPM-GPG-KEY-oracle /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle 82 | rpm --import /usr/share/rhn/RPM-GPG-KEY-oracle 83 | 84 | %changelog 85 | * Tue Nov 9 2021 Guido Tijskens ( 0.2.2-0) 86 | - fixed os release check 87 | 88 | * Wed Sep 15 2021 Guido Tijskens ( 0.2.1-0) 89 | - update structure 90 | 91 | * Wed Nov 18 2020 Guido Tijskens ( 0.1.1-1 ) 92 | - user specific channels 93 | 94 | * Tue Nov 10 2020 Guido Tijskens ( 0.1.1-0 ) 95 | - initial version 96 | -------------------------------------------------------------------------------- /tests/automation/create_volume: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # 3 | # Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown 5 | # at http://oss.oracle.com/licenses/upl. 6 | # 7 | # creates a volume of 51GB, creates a primary partition of 10GB and creates a filesystem on this partition; a destroy 8 | # script is als created. 9 | # 10 | NBPAR="${#}" 11 | VALIDFS=(ext4 xfs) 12 | 13 | Usage() { 14 | echo "Usage:" 15 | echo " ${0} [ext4|xfs] (volume name)" 16 | } 17 | # command line 18 | # file system type 19 | if [ "${NBPAR}" -lt 1 ]; then 20 | echo "Invalid filesystem type: ext4|xfs." 21 | Usage 22 | exit 1 23 | else 24 | FSTYPE=${1} 25 | if [[ ! " ${VALIDFS[*]} " =~ ${FSTYPE} ]]; then 26 | echo "Invalid file system type." 27 | Usage 28 | fi 29 | fi 30 | # 31 | # volume name 32 | if [ ${NBPAR} -lt 2 ]; then 33 | VOLNAME=gtijsken_vol01 34 | else 35 | VOLNAME="${2}" 36 | fi 37 | 38 | echo "${VOLNAME}" 39 | # 40 | oci-iscsi-config create --size 51 --volume-name "${VOLNAME}" --attach-volume 41 | # 42 | oci-iscsi-config show --details --no-truncate 43 | # 44 | VOL=$(oci-iscsi-config show --details --output-mode parsable |grep "${VOLNAME}") 45 | echo "${VOL}" 46 | # 47 | IFS='#'; arrVOL=(${VOL}); unset IFS; 48 | echo "${arrVOL}" 49 | DEVICE="/dev/${arrVOL[6]}" 50 | echo "${DEVICE}" 51 | # 52 | fdisk "${DEVICE}" < "${destroy_script}" 81 | echo "umount ${MOUNTPOINT}" >> "${destroy_script}" 82 | IQN=$(oci-volume-data --key "${VOLNAME}" --par iqn --value-only) 83 | OCID=$(oci-volume-data --key "${VOLNAME}" --par ocid --value-only) 84 | echo "oci-iscsi-config detach -I ${IQN}" >> "${destroy_script}" 85 | echo "oci-iscsi-config destroy -O ${OCID} --yes" >> "${destroy_script}" 86 | echo "df -h" >> "${destroy_script}" 87 | echo "oci-iscsi-config show --details --no-truncate" >> "${destroy_script}" 88 | echo "rmdir ${MOUNTPOINT}" >> "${destroy_script}" 89 | chmod 755 "${destroy_script}" 90 | echo "created ${destroy_script}" 91 | -------------------------------------------------------------------------------- /tests/automation/data/LICENSE.txt: -------------------------------------------------------------------------------- 1 | // oci-utils 2 | // 3 | // Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved. 4 | // Licensed under the Universal Permissive License v 1.0 as shown 5 | // at http://oss.oracle.com/licenses/upl. 6 | 7 | -------------------------------------------------------------------------------- /tests/automation/data/README.md: -------------------------------------------------------------------------------- 1 | # oci utils automated testing 2 | 3 | ## base module for oci utils automated testing. 4 | 5 | -------------------------------------------------------------------------------- /tests/automation/data/base_instance/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "http" "channel_rpm" { 6 | url = "http://${var.server_ip}/channel_rpms/${var.os_user}/" 7 | } -------------------------------------------------------------------------------- /tests/automation/data/base_instance/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | value = oci_core_instance.test_instance.*.private_ip[0] 7 | } 8 | 9 | //PUBIPoutput "instance_public_ip" { 10 | //PUBIP description = "Public IPs of created instance." 11 | //PUBIP value = oci_core_instance.test_instance.*.public_ip[0] 12 | //PUBIP} 13 | 14 | output "boot_volume_ocid" { 15 | value = oci_core_instance.test_instance.*.boot_volume_id[0] 16 | } 17 | 18 | output "instance_ocid" { 19 | value = oci_core_instance.test_instance.*.id[0] 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/automation/data/scripts/install_oci_utils_automation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http:/oss.oracle.com/licenses/upl. 5 | 6 | RPM=$(command -v rpm) 7 | GREP=$(command -v grep) 8 | FIND=$(command -v find) 9 | SED=$(command -v sed) 10 | MKDIR=$(command -v mkdir) 11 | DNF=dnf 12 | SYSTEMCTL=$(command -v systemctl) 13 | SUDO=$(command -v sudo) 14 | OSVERSION=$(${SED} -rn 's/.*([0-9])\.[0-9].*/\1/p' /etc/redhat-release) 15 | if ! command -v dnf; then 16 | installrpm=$(command -v yum) 17 | ${SUDO} --login ${installrpm}-config-manager --enablerepo ol${OSVERSION}_developer 18 | else 19 | installrpm=$(command -v dnf) 20 | ${SUDO} --login ${installrpm} config-manager --set-enabled ol${OSVERSION}_developer 21 | fi 22 | ${SUDO} --login ${installrpm} clean all 23 | ${SUDO} --login ${installrpm} repolist 24 | 25 | ${SUDO} --login ${MKDIR} -p /root/test_data/test_rpms 26 | ${SUDO} --login ${MKDIR} -p /root/test_data/install_rpms 27 | 28 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils 29 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-kvm 30 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-migrate 31 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-outest 32 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-oumtest 33 | # 34 | # excluding the kernel can cause the update failing 35 | # ${SUDO} --login ${installrpm} --assumeyes update --exclude=kernel*,oci-utils* 36 | ${SUDO} --login ${installrpm} --assumeyes install tree strace tmux 37 | 38 | el=el$(rpm -q --queryformat '%{RELEASE}' rpm | grep -o [[:digit:]]*\$) 39 | ${SUDO} --login "${FIND}" /tmp -name "oci-utils*el${OSVERSION}*rpm" -exec ${installrpm} -y localinstall {} \; 40 | # 41 | # install packages to be tested 42 | ${SUDO} --login ${installrpm} repository-packages oci-utils-automation install --assumeyes --nogpgcheck 43 | 44 | ${SUDO} --login ${SYSTEMCTL} enable ocid 45 | ${SUDO} --login ${SYSTEMCTL} start ocid 46 | -------------------------------------------------------------------------------- /tests/automation/data/scripts/install_oci_utils_kvm_automation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http:/oss.oracle.com/licenses/upl. 5 | 6 | RPM=$(command -v rpm) 7 | GREP=$(command -v grep) 8 | FIND=$(command -v find) 9 | SED=$(command -v sed) 10 | MKDIR=$(command -v mkdir) 11 | DNF=dnf 12 | SYSTEMCTL=$(command -v systemctl) 13 | SUDO=$(command -v sudo) 14 | OSVERSION=$(${SED} -rn 's/.*([0-9])\.[0-9].*/\1/p' /etc/redhat-release) 15 | if ! command -v dnf; then 16 | installrpm=$(command -v yum) 17 | ${SUDO} --login ${installrpm}-config-manager --enablerepo ol${OSVERSION}_developer 18 | else 19 | installrpm=$(command -v dnf) 20 | ${SUDO} --login ${installrpm} config-manager --set-enabled ol${OSVERSION}_developer 21 | fi 22 | 23 | ${SUDO} --login ${MKDIR} -p /root/test_data/test_rpms 24 | ${SUDO} --login ${MKDIR} -p /root/test_data/install_rpms 25 | 26 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils 27 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-kvm 28 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-migrate 29 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-outest 30 | ${SUDO} --login ${installrpm} --assumeyes erase oci-utils-oumtest 31 | # 32 | # excluding the kernel can cause the update failing 33 | # ${SUDO} --login ${installrpm} --assumeyes update --exclude=kernel*,oci-utils* 34 | ${SUDO} --login ${installrpm} --assumeyes install tree strace tmux 35 | 36 | el=el$(rpm -q --queryformat '%{RELEASE}' rpm | grep -o [[:digit:]]*\$) 37 | ${SUDO} --login "${FIND}" /tmp -name "oci-utils*el${OSVERSION}*rpm" -exec ${installrpm} -y localinstall {} \; 38 | 39 | ${SUDO} --login ${installrpm} clean all 40 | ${SUDO} --login ${installrpm} repolist 41 | ${SUDO} --login ${installrpm} repository-packages oci-utils-automation install --assumeyes --nogpgcheck 42 | 43 | ${SUDO} --login ${SYSTEMCTL} enable ocid 44 | ${SUDO} --login ${SYSTEMCTL} start ocid 45 | 46 | # 47 | # kvm specific 48 | ${SUDO} --login ${MKDIR} -p /isos 49 | -------------------------------------------------------------------------------- /tests/automation/data/test_iscsi/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/automation/data/test_iscsi/terraform_version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/automation/data/test_metadata/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/automation/data/test_metadata/terraform_version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/automation/data/test_various/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/automation/data/test_various/terraform_version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/automation/data/userdata/tests-env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This file contains environement variables and script commands 9 | # to be push on remote instance within /etc/profile.d 10 | 11 | export http_proxy=${http_proxy_url} 12 | export https_proxy=${https_proxy_url} 13 | export no_proxy=169.254.169.254,.oraclecloud.com,.oraclecorp.com,.us.oracle.com -------------------------------------------------------------------------------- /tests/automation/data/userdata/tests-resolve: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http://oss.oracle.com/licenses/upl. 5 | 6 | export search ${dns_search_domains} 7 | export nameserver ${dns_server_ip} -------------------------------------------------------------------------------- /tests/automation/oci_utils_network_data.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http://oss.oracle.com/licenses/upl. 5 | 6 | """ 7 | Find a the value af an attribute of a vnic based on the value of an attribute of the vnic. 8 | """ 9 | import argparse 10 | import subprocess 11 | import sys 12 | 13 | oci_network_path = '/bin/oci-network-config' 14 | vnic_fields = ['state', 15 | 'link', 16 | 'status', 17 | 'ipaddress', 18 | 'vnic', 19 | 'mac', 20 | 'hostname', 21 | 'subnet', 22 | 'routerip', 23 | 'namespace', 24 | 'index', 25 | 'vlantag', 26 | 'vlan'] 27 | 28 | 29 | def parse_args(): 30 | """ 31 | Parse command line parameters. 32 | 33 | Returns 34 | ------- 35 | namespace parsed arguments. 36 | """ 37 | parser = argparse.ArgumentParser(description='Utility for collecting 1 attribute of 1 vnic') 38 | parser.add_argument('-i', '--input_field', 39 | action='store', 40 | type=str, 41 | required=True, 42 | choices=vnic_fields, 43 | help='The vnic field to select the vnic.') 44 | parser.add_argument('-v', '--input-value', 45 | action='store', 46 | type=str, 47 | required=True, 48 | help='The value of the select field.') 49 | parser.add_argument('-o', '--output-field', 50 | choices=vnic_fields, 51 | type=str, 52 | required=True, 53 | help='The field the value requested from.') 54 | return parser 55 | 56 | 57 | def get_vnic_data(index, val, field): 58 | """ 59 | Return val for vnic based on index. 60 | 61 | Parameters 62 | ---------- 63 | index: str 64 | base field name. 65 | val: str 66 | base field value. 67 | field: str 68 | requested field value. 69 | 70 | Returns 71 | ------- 72 | str: the requested value, None if absent. 73 | """ 74 | cmd = [oci_network_path, 'show', '--details', '--output-mode', 'parsable'] 75 | all_vnic_data = subprocess.check_output(cmd).decode('utf-8').splitlines() 76 | 77 | for vnic in all_vnic_data: 78 | vnic_list = vnic.split('#') 79 | if index not in vnic_fields or field not in vnic_fields: 80 | return None 81 | if vnic_list[vnic_fields.index(index)] == val: 82 | return vnic_list[vnic_fields.index(field)] 83 | return None 84 | 85 | 86 | def main(): 87 | """ 88 | main 89 | 90 | Returns 91 | ------- 92 | No retunr value. 93 | """ 94 | parser = parse_args() 95 | args = parser.parse_args() 96 | print(get_vnic_data(args.input_field, args.input_value, args.output_field)) 97 | 98 | 99 | if __name__ == "__main__": 100 | sys.exit(main()) 101 | -------------------------------------------------------------------------------- /tests/automation/oci_utils_pool_data.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http://oss.oracle.com/licenses/upl. 5 | 6 | """ 7 | Find a the value af an attribute of a kvm pool based on the value of an attribute of the volume. 8 | """ 9 | import argparse 10 | import subprocess 11 | import sys 12 | 13 | oci_kvm_path = '/bin/oci-kvm' 14 | pool_fields = ['name', 15 | 'uuid', 16 | 'autostart', 17 | 'active', 18 | 'persistent', 19 | 'volumes', 20 | 'state', 21 | 'capacity', 22 | 'allocation', 23 | 'available'] 24 | 25 | 26 | def parse_args(): 27 | """ 28 | Parse command line parameters. 29 | 30 | Returns 31 | ------- 32 | namespace parsed arguments. 33 | """ 34 | choicelist = pool_fields 35 | parser = argparse.ArgumentParser(description='Utility for collecting 1 attribute of 1 pool') 36 | parser.add_argument('-i', '--input_field', 37 | action='store', 38 | type=str, 39 | required=True, 40 | choices=choicelist, 41 | help='The vnic field to select the pool.') 42 | parser.add_argument('-v', '--input-value', 43 | action='store', 44 | type=str, 45 | required=True, 46 | help='The value of the select field.') 47 | parser.add_argument('-o', '--output-field', 48 | choices=choicelist, 49 | type=str, 50 | required=True, 51 | help='The field the value requested from.') 52 | return parser 53 | 54 | 55 | def get_pool_data(index, val, field): 56 | """ 57 | Return val for volume based on index. 58 | 59 | Parameters 60 | ---------- 61 | index: str 62 | base field name. 63 | val: str 64 | base field value. 65 | field: str 66 | requested field value. 67 | 68 | Returns 69 | ------- 70 | str: the requested value, None if absent. 71 | """ 72 | cmd = [oci_kvm_path, 'list-pool', '--output-mode', 'parsable'] 73 | all_pool_data = subprocess.check_output(cmd).decode('utf-8').splitlines() 74 | 75 | for pool in all_pool_data: 76 | pool_list = pool.split('#') 77 | if index not in pool_fields or field not in pool_fields: 78 | return None 79 | if pool_list[pool_fields.index(index)] == val: 80 | return pool_list[pool_fields.index(field)] 81 | return None 82 | 83 | 84 | def main(): 85 | """ 86 | main 87 | 88 | Returns 89 | ------- 90 | No retunr value. 91 | """ 92 | parser = parse_args() 93 | args = parser.parse_args() 94 | print(get_pool_data(args.input_field, args.input_value, args.output_field)) 95 | 96 | 97 | if __name__ == "__main__": 98 | sys.exit(main()) 99 | -------------------------------------------------------------------------------- /tests/automation/templates/tf_apikey: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_sdk_config" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.oci_private_key 9 | destination = "/tmp/oci_private_key.pem" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_PUBIP_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_PUBIP_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.oci", 30 | "/bin/sudo --preserve-env cp /tmp/oci_private_key.pem /root/.oci/$(basename ${var.oci_private_key})", 31 | "/bin/sudo --preserve-env echo [DEFAULT] > /tmp/config", 32 | "/bin/sudo --preserve-env echo user=${var.user_ocid} >> /tmp/config", 33 | "/bin/sudo --preserve-env echo fingerprint=${var.fingerprint} >> /tmp/config", 34 | "/bin/sudo --preserve-env echo key_file=/root/.oci/$(basename ${var.oci_private_key}) >> /tmp/config", 35 | "/bin/sudo --preserve-env echo tenancy=${var.tenancy_ocid} >> /tmp/config", 36 | "/bin/sudo --preserve-env echo region=${var.region} >> /tmp/config", 37 | "/bin/sudo cp /tmp/config /root/.oci/config", 38 | "/bin/sudo chmod -R 600 /root/.oci/" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/automation/templates/tf_data: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | -------------------------------------------------------------------------------- /tests/automation/templates/tf_output: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | value = module.base_instance.instance_private_ip 7 | } 8 | 9 | //PUBIPoutput "instance_public_ip" { 10 | //PUBIP value = module.base_instance.instance_public_ip 11 | //PUBIP} 12 | 13 | output "boot_volume_ocid" { 14 | value = module.base_instance.boot_volume_ocid 15 | } 16 | 17 | output "instance_ocid" { 18 | value = module.base_instance.instance_ocid 19 | } -------------------------------------------------------------------------------- /tests/automation/templates/tf_test: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "run__TTTT_" { 6 | depends_on = [_BBBB_] 7 | provisioner "remote-exec" { 8 | connection { 9 | type = "ssh" 10 | user = var.remote_user 11 | agent = false 12 | host = module.base_instance.instance_private_ip 13 | timeout = "15m" 14 | private_key = file(var.ssh_private_key) 15 | } 16 | inline = [ 17 | "_SSSS_" 18 | ] 19 | } 20 | } -------------------------------------------------------------------------------- /tests/automation/templates/tf_version: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } -------------------------------------------------------------------------------- /tests/common.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. 3 | 4 | # Common utility functions for tests 5 | 6 | import os 7 | import subprocess 8 | import oci_utils 9 | 10 | 11 | def get_hostname(): 12 | return os.popen("hostname").read().strip() 13 | 14 | 15 | def get_instance_id(): 16 | return oci_utils.metadata()['instance']['id'] 17 | 18 | 19 | def run_cmd(cmd): 20 | """ 21 | Run a [command, with, its, args] and return (exit code, output) 22 | """ 23 | try: 24 | output = subprocess.check_output(cmd, stderr=subprocess.STDOUT) 25 | return 0, output 26 | except OSError as e: 27 | return 255, str(e) 28 | except subprocess.CalledProcessError as e: 29 | return e.returncode, e.output 30 | -------------------------------------------------------------------------------- /tests/data/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | waittime = 30 3 | oci-iscsi-config = /bin/oci-iscsi-config 4 | oci-kvm = /bin/oci-kvm 5 | oci-metadata = /bin/oci-metadata 6 | oci-public-ip = /bin/oci-public-ip 7 | oci-network-inspector = /bin/oci-network-inspector 8 | oci-network-config = /bin/oci-network-config 9 | oci-notify = /bin/oci-notify 10 | oci-utils-config-helper = /usr/libexec/oci-utils-config-helper 11 | oci-image-migrate = /bin/oci-image-migrate 12 | oci-image-migrate-upload = /bin/oci-image-migrate-upload 13 | oci-image-migrate-import = /bin/oci-image-migrate-import 14 | volume-name-prefix = auto-test- 15 | volume-size = 51 16 | compartment-name = ImageDev -------------------------------------------------------------------------------- /tests/data/tests/test_cli_iscsi_config/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | compartment-name = ImageDev 3 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_iscsi_config_create/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | compartment-name = ImageDev 3 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_iscsi_config_createattachdetachattachdetachdestroy/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | volume-size = 52 3 | volume-name-prefix = multidetach 4 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_iscsi_config_more/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | compartment-name = ImageDev 3 | 4 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_kvm/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | pool-name-prefix = auto-pool- 3 | vnic-name-prefix = auto- 4 | kvm-net-prefix = auto- 5 | ip-bridge = 192.168.111.1 6 | ip-start = 192.168.111.111 7 | ip-end = 192.168.111.222 8 | ip-prefix = 24 9 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_network_config/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | network-name = vnic-name 3 | network-name-prefix = vnic- 4 | new_ip= 10.0.0.101 5 | extra_ip= 10.0.0.102 6 | waittime = 120 7 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_network_config_attach/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | network-name = vnic-name 3 | network-name-prefix = vnic- 4 | new_ip= 10.0.0.101 5 | extra_ip= 10.0.0.102 6 | waittime = 120 7 | -------------------------------------------------------------------------------- /tests/data/tests/test_cli_network_config_configure/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | network-name = vnic-name 3 | network-name-prefix = vnic- 4 | new_ip= 10.0.0.101 5 | extra_ip= 10.0.0.102 6 | waittime = 120 7 | -------------------------------------------------------------------------------- /tests/data/tests/test_exec_helpers/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | exec_cmd = /bin/date --rfc-2822 -------------------------------------------------------------------------------- /tests/data/tests/test_exec_ocid/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | ocid-path = /usr/libexec/ocid -------------------------------------------------------------------------------- /tests/data/tests/test_iscsiadm/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | discovery-address = 169.254.0.2 3 | lun-iqn = iqn.2015-02.oracle.boot:uefi -------------------------------------------------------------------------------- /tests/data/tests/test_network_helpers/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | connect_remote = localhost 3 | connect_remote_port = 10000 4 | -------------------------------------------------------------------------------- /tests/data/tests/test_oci_notify/properties.cfg: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | # london 3 | valid_topic = ocid1.onstopic.oc1.uk-london-1.aaaaaaaa72bxhckvrtqa2xvfitsist7bm7dsfnkfte36hxsq5d4ghcriiifq 4 | # ashburn 5 | # valid_topic = ocid1.onstopic.oc1.iad.aaaaaaaa7wuzgezxx7hbnrgp6xg5xxaffpueej74r3dob3p57gqhbvzgkz3q 6 | non_exist_topic = ocid1.onstopic.oc1.uk-london-1.abcdefghijklmnopqrstuvwxyz0123456789 7 | invalid_topic = abcdefghijklmnopqrstuvwxyz0123456789 8 | test_file = /var/log/messages -------------------------------------------------------------------------------- /tests/templates/instance.tfvars.json: -------------------------------------------------------------------------------- 1 | { 2 | "tests_tools_dir": "", 3 | "tenancy_ocid": "", 4 | "user_ocid": "", 5 | "fingerprint": "", 6 | "private_key_path": "", 7 | "region": "uk-london-1", 8 | "compartment_id": "", 9 | "availability_domain_id": "VkEH:UK-LONDON-1-AD-1", 10 | "subnet_id": "", 11 | "instance_shape": "VM.Standard.E2.1", 12 | "instance_image_ocid": "ocid1.image.oc1.uk-london-1.aaaaaaaal5pmft27cqisocpgak37k7zyhnjccuwqqigpwwy6zst5bpyynrqq", 13 | "ssh_private_key_path": "", 14 | "ssh_authorized_key_path": "", 15 | "ssh_user": "opc", 16 | "dns_search_domains": "", 17 | "dns_server_ip": "", 18 | "http_proxy_url": "", 19 | "https_proxy_url": "" 20 | } -------------------------------------------------------------------------------- /tests/test_auth_helper.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import unittest 6 | from oci_utils.impl.auth_helper import OCIAuthProxy 7 | import os 8 | from tools.decorators import skipUnlessOCI 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestAuthHelpers(OciTestCase): 15 | """ 16 | Auth helpers Test cases. 17 | """ 18 | 19 | @skipUnlessOCI() 20 | def test_get_config(self): 21 | """ 22 | Test OCIAuthProxy.get_config. 23 | 24 | Returns 25 | ------- 26 | No return value. 27 | """ 28 | unittest.skip('Need user password') 29 | # print(OCIAuthProxy('opc').get_config()) 30 | 31 | 32 | if __name__ == '__main__': 33 | suite = unittest.TestLoader().loadTestsFromTestCase(TestAuthHelpers) 34 | unittest.TextTestRunner().run(suite) 35 | -------------------------------------------------------------------------------- /tests/test_cli_metadata_bugs.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import time 8 | import unittest 9 | from tools.oci_test_case import OciTestCase 10 | 11 | 12 | os.environ['LC_ALL'] = 'en_US.UTF8' 13 | os.environ['_OCI_UTILS_DEBUG'] = '1' 14 | 15 | 16 | class TestCliOciMetadataBugs(OciTestCase): 17 | """ oci-metadata tests. 18 | """ 19 | 20 | def setUp(self): 21 | """ 22 | Test initialisation. 23 | 24 | Returns 25 | ------- 26 | No return value. 27 | 28 | Raises 29 | ------ 30 | unittest.Skiptest 31 | If the metadata_cli does not exist. 32 | """ 33 | 34 | super().setUp() 35 | self.oci_metadata_path = self.properties.get_property('oci-metadata') 36 | if not os.path.exists(self.oci_metadata_path): 37 | raise unittest.SkipTest("%s not present" % self.oci_metadata_path) 38 | 39 | def test_linux11499(self): 40 | """ 41 | Test oci-metadata --get ... --value-only; should not return None 42 | Returns 43 | ------- 44 | No return value. 45 | """ 46 | get_value = subprocess.check_output([self.oci_metadata_path, '--get', 'region', '--value-only']).decode('utf-8').strip() 47 | self.assertIsNotNone(get_value, 'Is None') 48 | 49 | def test_linux11505(self): 50 | """ 51 | Test oci-metadata --get ... --export; should not return None 52 | Returns 53 | ------- 54 | No return value. 55 | """ 56 | get_value = subprocess.check_output([self.oci_metadata_path, '--get', 'canonicalregionname', '--export']).decode('utf-8').strip() 57 | self.assertIsNotNone(get_value, 'Is None') 58 | 59 | 60 | if __name__ == '__main__': 61 | suite = unittest.TestLoader().loadTestsFromTestCase(TestCliOciMetadataBugs) 62 | unittest.TextTestRunner().run(suite) 63 | -------------------------------------------------------------------------------- /tests/test_cli_public_ip.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import unittest 8 | from tools.oci_test_case import OciTestCase 9 | 10 | os.environ['LC_ALL'] = 'en_US.UTF8' 11 | os.environ['_OCI_UTILS_DEBUG'] = '1' 12 | 13 | class TestCliOciPublicIp(OciTestCase): 14 | """ oci-public-ip tests. 15 | """ 16 | 17 | def setUp(self): 18 | """ 19 | Test initialisation. 20 | 21 | Returns 22 | ------- 23 | No return value. 24 | 25 | Raises 26 | ------ 27 | unittest.Skiptest 28 | If the PUBLIC_IP does not exist. 29 | """ 30 | super(TestCliOciPublicIp, self).setUp() 31 | self.oci_public_ip = self.properties.get_property('oci-public-ip') 32 | if not os.path.exists(self.oci_public_ip): 33 | raise unittest.SkipTest("%s not present" % self.oci_public_ip) 34 | 35 | def test_display_help(self): 36 | """ 37 | Test displaying help. Dummy test to check that the CLI at least runs. 38 | 39 | Returns 40 | ------- 41 | No return value. 42 | """ 43 | try: 44 | _ = subprocess.check_output([self.oci_public_ip, '--help']) 45 | except Exception as e: 46 | self.fail('Execution has failed: %s' % str(e)) 47 | 48 | def test_get(self): 49 | """ 50 | Test displaying all pulic addr 51 | Returns 52 | ------- 53 | No return value. 54 | """ 55 | try: 56 | _ = subprocess.check_output([self.oci_public_ip, '--get', '--human-readable']) 57 | except subprocess.CalledProcessError as e: 58 | if e.returncode != 1: 59 | # when we cannot find the public IP , exit code is 1. 60 | self.fail('Execution has failed: %s' % str(e)) 61 | 62 | def test_list_servers(self): 63 | """ 64 | Test displaying STUN server 65 | Returns 66 | ------- 67 | No return value. 68 | """ 69 | try: 70 | _ = subprocess.check_output([self.oci_public_ip, '--list-servers']) 71 | except Exception as e: 72 | self.fail('Execution has failed: %s' % str(e)) 73 | 74 | def test_list_all(self): 75 | """ 76 | Test displaying all pulic addr 77 | Returns 78 | ------- 79 | No return value. 80 | """ 81 | try: 82 | _ = subprocess.check_output([self.oci_public_ip, '--all', '--json']) 83 | except subprocess.CalledProcessError as e: 84 | if e.returncode != 1: 85 | # when we cannot find the public IP , exit code is 1. 86 | self.fail('Execution has failed: %s' % str(e)) 87 | 88 | 89 | if __name__ == '__main__': 90 | suite = unittest.TestLoader().loadTestsFromTestCase(TestCliOciPublicIp) 91 | unittest.TextTestRunner().run(suite) 92 | -------------------------------------------------------------------------------- /tests/test_exec_helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import unittest 7 | 8 | from tools.decorators import skipUnlessRoot 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestExecHelpers(OciTestCase): 15 | """ Test around lib/oci_utils/impl/sudo_utils.py. 16 | """ 17 | 18 | def setUp(self): 19 | """ 20 | Initialisation. 21 | 22 | Returns 23 | ------- 24 | No return value. 25 | """ 26 | super().setUp() 27 | self.execute_cmd = self.properties.get_property('exec_cmd').split(' ') 28 | 29 | def test_execute(self): 30 | """ 31 | Test execute. 32 | 33 | Returns 34 | ------- 35 | No return value. 36 | """ 37 | import oci_utils.impl.sudo_utils 38 | self.assertTrue(oci_utils.impl.sudo_utils.execute(self.execute_cmd)) 39 | 40 | def test_call_output(self): 41 | """ 42 | Test execute. 43 | 44 | Returns 45 | ------- 46 | No return value. 47 | """ 48 | import oci_utils.impl.sudo_utils 49 | self.assertTrue(oci_utils.impl.sudo_utils.execute(self.execute_cmd)) 50 | 51 | @skipUnlessRoot() 52 | def test_call(self): 53 | """ 54 | Test initialisation. 55 | 56 | Returns 57 | ------- 58 | No return value. 59 | """ 60 | import oci_utils.impl.sudo_utils 61 | self.assertFalse(oci_utils.impl.sudo_utils.call(['/bin/ls', '/'])) 62 | 63 | 64 | if __name__ == '__main__': 65 | suite = unittest.TestLoader().loadTestsFromTestCase(TestExecHelpers) 66 | unittest.TextTestRunner().run(suite) -------------------------------------------------------------------------------- /tests/test_exec_ocid.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import unittest 8 | from tools.decorators import skipUnlessRoot 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestExecOcid(OciTestCase): 15 | """ libexec/ocid tests. 16 | """ 17 | 18 | OCID = '/usr/libexec/ocid' 19 | 20 | @skipUnlessRoot() 21 | def setUp(self): 22 | """ 23 | Test initialisation. 24 | 25 | Returns 26 | ------- 27 | No return value. 28 | """ 29 | super(TestExecOcid, self).setUp() 30 | self.ocid = self.properties.get_property('ocid-path') 31 | if not os.path.exists(self.ocid): 32 | raise unittest.SkipTest("%s not present" % self.ocid) 33 | 34 | def test_display_help(self): 35 | """ 36 | Test displaying help. Dummy test to check that the CLI at least runs. 37 | 38 | Returns 39 | ------- 40 | No return value. 41 | """ 42 | try: 43 | _ = subprocess.check_output([self.ocid, '--help']) 44 | except Exception as e: 45 | self.fail('Execution has failed: %s' % str(e)) 46 | 47 | def test_refresh_vnic(self): 48 | """ 49 | Test refresh all. 50 | 51 | Returns 52 | ------- 53 | No return value. 54 | """ 55 | try: 56 | _ = subprocess.check_output([self.ocid, '--refresh', 'vnic']) 57 | except Exception as e: 58 | self.fail('Execution has failed: %s' % str(e)) 59 | 60 | def test_refresh_iscsi(self): 61 | """ 62 | Test refresh all. 63 | 64 | Returns 65 | ------- 66 | No return value. 67 | """ 68 | try: 69 | _ = subprocess.check_output([self.ocid, '--refresh', 'iscsi']) 70 | except Exception as e: 71 | self.fail('Execution has failed: %s' % str(e)) 72 | 73 | def test_refresh_public_ip(self): 74 | """ 75 | Test refresh all. 76 | 77 | Returns 78 | ------- 79 | No return value. 80 | """ 81 | try: 82 | _ = subprocess.check_output([self.ocid, '--refresh', 'public_ip']) 83 | except Exception as e: 84 | self.fail('Execution has failed: %s' % str(e)) 85 | 86 | def test_refresh_all(self): 87 | """ 88 | Test refresh all. 89 | 90 | Returns 91 | ------- 92 | No return value. 93 | """ 94 | try: 95 | _ = subprocess.check_output([self.ocid, '--refresh']) 96 | except Exception as e: 97 | self.fail('Execution has failed: %s' % str(e)) 98 | 99 | 100 | if __name__ == '__main__': 101 | suite = unittest.TestLoader().loadTestsFromTestCase(TestExecOcid) 102 | unittest.TextTestRunner().run(suite) -------------------------------------------------------------------------------- /tests/test_exec_utils-config-helper.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown at 3 | # http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import sys 7 | import subprocess 8 | import unittest 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestExecConfigHelper(OciTestCase): 15 | """ oci-utils-config-helper tests. 16 | """ 17 | 18 | def setUp(self): 19 | """ 20 | Test initialisation. 21 | 22 | Returns 23 | ------- 24 | No return value. 25 | 26 | Raises 27 | ------ 28 | unittest.Skiptest 29 | If the OCI_UTILS_CONFIG_HELPER does not exist. 30 | """ 31 | super(TestExecConfigHelper, self).setUp() 32 | self.oci_config_helper = self.properties.get_property('oci-utils-config-helper') 33 | if not os.path.exists(self.oci_config_helper): 34 | raise unittest.SkipTest("%s not present" % self.oci_config_helper) 35 | 36 | def test_display_help(self): 37 | """ 38 | Test displaying help. Dummy test to check that the CLI at least runs. 39 | 40 | Returns 41 | ------- 42 | No return value. 43 | """ 44 | try: 45 | _ = subprocess.check_output([sys.executable, self.oci_config_helper]) 46 | except subprocess.CalledProcessError as e: 47 | if e.returncode != 1: 48 | self.fail('Execution has failed: %s' % str(e)) 49 | 50 | 51 | if __name__ == '__main__': 52 | suite = unittest.TestLoader().loadTestsFromTestCase(TestExecConfigHelper) 53 | unittest.TextTestRunner().run(suite) -------------------------------------------------------------------------------- /tests/test_iscsiadm.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown at 3 | # http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import unittest 7 | 8 | import oci_utils.iscsiadm 9 | from tools.decorators import (skipUnlessOCI, skipUnlessRoot, skipItAsUnresolved) 10 | from tools.oci_test_case import OciTestCase 11 | 12 | os.environ['LC_ALL'] = 'en_US.UTF8' 13 | os.environ['_OCI_UTILS_DEBUG'] = '1' 14 | 15 | class TestIScsiAdm(OciTestCase): 16 | """ Test iscsiadm module. 17 | """ 18 | 19 | @skipItAsUnresolved() 20 | @skipUnlessOCI() 21 | @skipUnlessRoot() 22 | def test_discovery(self): 23 | """ 24 | Tests iscsiadm.discovery. Test LUNs discovery from an OCI instance. 25 | 26 | Returns 27 | ------- 28 | No return value. 29 | """ 30 | iqns = oci_utils.iscsiadm.discovery(self.properties.get_property('discovery-address')) 31 | self.assertTrue(len(iqns) > 0, 32 | 'No LUNs discovered against [%s]' % 33 | self.properties.get_property('discovery-address')) 34 | self.assertIn(self.properties.get_property('lun_iqn'), iqns[0], 35 | '[%s] not the first IQN discovered: <> [%s]' % 36 | (self.properties.get_property('lun_iqn'), iqns[0])) 37 | 38 | @skipItAsUnresolved() 39 | @skipUnlessOCI() 40 | @skipUnlessRoot() 41 | def test_session(self): 42 | """ 43 | Tests iscsiadm.session. 44 | 45 | Returns 46 | ------- 47 | No return value. 48 | """ 49 | iqns = oci_utils.iscsiadm.session() 50 | self.assertIn(self.properties.get_property('lun_iqn'), iqns, 51 | 'boot disk lun [%s] not found in IQN discovered [%s]' % 52 | (self.properties.get_property('lun_iqn'), iqns)) 53 | self.assertEqual(iqns['iqn.2015-02.oracle.boot:uefi'] 54 | ['current_portal_ip'], '169.254.0.2') 55 | 56 | 57 | if __name__ == '__main__': 58 | suite = unittest.TestLoader().loadTestsFromTestCase(TestIScsiAdm) 59 | unittest.TextTestRunner().run(suite) 60 | -------------------------------------------------------------------------------- /tests/test_lsblk.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import unittest 7 | 8 | import oci_utils.lsblk 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestLsBlk(OciTestCase): 15 | """ Test the lsblk module. 16 | """ 17 | 18 | def test_list_root(self): 19 | """ 20 | Tests lsblk.list_blk_dev give us the root filesystem. 21 | 22 | Returns 23 | ------- 24 | No return value. 25 | """ 26 | dev_list = oci_utils.lsblk.list_blk_dev() 27 | self.assertIsNotNone(dev_list, 'None returned as device list.') 28 | self.assertTrue(len(dev_list), 'Empty device list returned.') 29 | 30 | 31 | if __name__ == '__main__': 32 | suite = unittest.TestLoader().loadTestsFromTestCase(TestLsBlk) 33 | unittest.TextTestRunner().run(suite) 34 | -------------------------------------------------------------------------------- /tests/test_mig_import.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import unittest 8 | 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | class TestImport(OciTestCase): 15 | """ Test image import. 16 | """ 17 | def setUp(self): 18 | super(TestImport, self).setUp() 19 | self.oci_migrate_image_import_path = self.properties.get_property('oci-image-migrate-import') 20 | if not os.path.exists(self.oci_migrate_image_import_path): 21 | raise unittest.SkipTest("%s not present" % 22 | self.oci_migrate_image_import_path) 23 | 24 | def test_display_help(self): 25 | """ Display help message. 26 | """ 27 | try: 28 | _ = subprocess.check_output([self.oci_migrate_image_import_path, '--help']) 29 | except Exception as e: 30 | self.fail('Execution has failed: %s' % str(e)) 31 | 32 | 33 | if __name__ == '__main__': 34 | suite = unittest.TestLoader().loadTestsFromTestCase(TestImport) 35 | unittest.TextTestRunner().run(suite) 36 | -------------------------------------------------------------------------------- /tests/test_mig_migrate.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import unittest 8 | 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | 15 | class TestMigrate(OciTestCase): 16 | """ Test image validate for migration. 17 | """ 18 | def setUp(self): 19 | super(TestMigrate, self).setUp() 20 | self.oci_migrate_image_path = self.properties.get_property('oci-image-migrate') 21 | if not os.path.exists(self.oci_migrate_image_path): 22 | raise unittest.SkipTest("%s not present" % 23 | self.oci_migrate_image_path) 24 | 25 | def test_display_help(self): 26 | """ Display help message. 27 | """ 28 | try: 29 | _ = subprocess.check_output([self.oci_migrate_image_path, '--help']) 30 | except Exception as e: 31 | self.fail('Execution has failed: %s' % str(e)) 32 | 33 | 34 | if __name__ == '__main__': 35 | suite = unittest.TestLoader().loadTestsFromTestCase(TestMigrate) 36 | unittest.TextTestRunner().run(suite) 37 | -------------------------------------------------------------------------------- /tests/test_mig_upload.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import subprocess 7 | import unittest 8 | 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | 15 | class TestUpload(OciTestCase): 16 | """ Test image upload. 17 | """ 18 | def setUp(self): 19 | super(TestUpload, self).setUp() 20 | self.oci_migrate_image_upload_path = self.properties.get_property('oci-image-migrate-upload') 21 | if not os.path.exists(self.oci_migrate_image_upload_path): 22 | raise unittest.SkipTest("%s not present" % 23 | self.oci_migrate_image_upload_path) 24 | 25 | def test_display_help(self): 26 | """ Display help message. 27 | """ 28 | try: 29 | _ = subprocess.check_output([self.oci_migrate_image_upload_path, '--help']) 30 | except Exception as e: 31 | self.fail('Execution has failed: %s' % str(e)) 32 | 33 | 34 | if __name__ == '__main__': 35 | suite = unittest.TestLoader().loadTestsFromTestCase(TestUpload) 36 | unittest.TextTestRunner().run(suite) 37 | -------------------------------------------------------------------------------- /tests/test_network_helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown at 3 | # http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import socket 7 | import unittest 8 | 9 | from oci_utils.impl.network_helpers import is_ip_reachable 10 | from tools.oci_test_case import OciTestCase 11 | 12 | os.environ['LC_ALL'] = 'en_US.UTF8' 13 | os.environ['_OCI_UTILS_DEBUG'] = '1' 14 | 15 | 16 | class TestNetworkHelpers(OciTestCase): 17 | """ 18 | Test impl/network_helpers.py. 19 | 20 | Attributes 21 | ---------- 22 | _test_connect_remote: str 23 | The remote hostname. 24 | _test_connect_remote_port: 25 | The port to use for the test. 26 | """ 27 | 28 | def setUp(self): 29 | """ 30 | Test initialisation. 31 | 32 | Returns 33 | ------- 34 | No return value. 35 | """ 36 | super(TestNetworkHelpers, self).setUp() 37 | self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 38 | self.sock.bind((self.properties.get_property('connect_remote'), 39 | int(self.properties.get_property('connect_remote_port')))) 40 | self.sock.listen(1) 41 | 42 | def tearDown(self): 43 | """ 44 | Test removal. 45 | 46 | Returns 47 | ------- 48 | No return value. 49 | """ 50 | self.sock.close() 51 | 52 | def test_can_connect(self): 53 | """ 54 | Test network connection. 55 | 56 | Returns 57 | ------- 58 | No return value. 59 | """ 60 | 61 | self.assertTrue(is_ip_reachable( 62 | str(self.properties.get_property('connect_remote')), 63 | int(self.properties.get_property('connect_remote_port')))) 64 | self.assertFalse(is_ip_reachable('blabber', 80)) 65 | 66 | 67 | if __name__ == '__main__': 68 | suite = unittest.TestLoader().loadTestsFromTestCase(TestNetworkHelpers) 69 | unittest.TextTestRunner().run(suite) 70 | -------------------------------------------------------------------------------- /tests/test_platform_helpers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import os 6 | import unittest 7 | 8 | from tools.decorators import skipUnlessOCI 9 | from tools.oci_test_case import OciTestCase 10 | 11 | os.environ['LC_ALL'] = 'en_US.UTF8' 12 | os.environ['_OCI_UTILS_DEBUG'] = '1' 13 | 14 | 15 | class TestPlatformHelpers(OciTestCase): 16 | """ Test around lib/oci_utils/impl/platform_helpers.py. 17 | """ 18 | 19 | @skipUnlessOCI() 20 | def test_get_phys_device(self): 21 | """ 22 | Test get_phys_device. 23 | 24 | Returns 25 | ------- 26 | No return value. 27 | """ 28 | import oci_utils.impl.platform_helpers 29 | self.assertIsNotNone(oci_utils.impl.platform_helpers.get_phys_device(), 30 | 'None returned by get_phys_device()') 31 | 32 | @skipUnlessOCI() 33 | def test_get_block_device(self): 34 | """ 35 | Test get_block_devices. 36 | 37 | Returns 38 | ------- 39 | No return value. 40 | """ 41 | import oci_utils.impl.platform_helpers 42 | self.assertIsNotNone( 43 | oci_utils.impl.platform_helpers.get_block_devices(), 44 | 'None returned by get_block_devices()') 45 | 46 | 47 | if __name__ == '__main__': 48 | suite = unittest.TestLoader().loadTestsFromTestCase(TestPlatformHelpers) 49 | unittest.TextTestRunner().run(suite) -------------------------------------------------------------------------------- /tests/test_vnicutils.py: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http://oss.oracle.com/licenses/upl. 5 | 6 | import os 7 | import unittest 8 | 9 | from tools.decorators import (skipUnlessOCI, skipUnlessRoot) 10 | from tools.oci_test_case import OciTestCase 11 | 12 | os.environ['LC_ALL'] = 'en_US.UTF8' 13 | os.environ['_OCI_UTILS_DEBUG'] = '1' 14 | 15 | 16 | class TestVnicUtils(OciTestCase): 17 | """ 18 | VNICUtils Test cases. 19 | """ 20 | 21 | @skipUnlessOCI() 22 | def test_create_instance(self): 23 | """ 24 | Test VNICUtils.new. 25 | 26 | Returns 27 | ------- 28 | No return value. 29 | """ 30 | import oci_utils.vnicutils 31 | self.assertIsNotNone(oci_utils.vnicutils.VNICUtils()) 32 | 33 | def test_get_network_config(self): 34 | """ 35 | Test VNICUtils.get_network_config() 36 | 37 | Returns 38 | ------- 39 | No return value. 40 | """ 41 | import oci_utils.vnicutils 42 | vu = oci_utils.vnicutils.VNICUtils() 43 | 44 | for nc in vu.get_network_config(): 45 | print(nc) 46 | 47 | 48 | if __name__ == '__main__': 49 | suite = unittest.TestLoader().loadTestsFromTestCase(TestVnicUtils) 50 | unittest.TextTestRunner().run(suite) -------------------------------------------------------------------------------- /tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tools/execution/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tools/execution/storable.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | __all__ = ['Storable'] 6 | 7 | 8 | class Storable(object): 9 | """ 10 | Base class for object storable in store 11 | """ 12 | 13 | def toXMLElement(self): 14 | """ 15 | return an XMLElement of this instance 16 | Storable object are expected to implement this 17 | Returned element is expected to have an attribute named 'key' 18 | 19 | Returns 20 | ------- 21 | xml.etree.ElementTree.Element 22 | this as XML element 23 | """ 24 | raise Exception('subclass must implement this') 25 | 26 | def getKey(self): 27 | """ 28 | Return the unique identifier of this instance 29 | """ 30 | raise Exception('subclass must implement this') 31 | -------------------------------------------------------------------------------- /tools/execution/store.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import xml.etree.ElementTree as ET 6 | 7 | import os 8 | import logging 9 | 10 | __all__ = ['getCommandStore', 'setCommandStore'] 11 | 12 | _logger = logging.getLogger('oci-utils-tests') 13 | 14 | _default_repo_path = '/tmp/commands.xml' 15 | _store = None 16 | 17 | 18 | def setCommandStore(store): 19 | global _store 20 | _store = store 21 | 22 | 23 | def getCommandStore(): 24 | global _store 25 | if _store is None: 26 | _store = Store(_default_repo_path) 27 | return _store 28 | 29 | 30 | class Store(object): 31 | def __init__(self, repo_filename): 32 | self.repo_filename = repo_filename 33 | if os.path.exists(self.repo_filename) and os.stat(self.repo_filename).st_size > 0: 34 | # load it first 35 | _logger.info('load command from [%s]', self.repo_filename) 36 | self.commandRoot = ET.parse(self.repo_filename).getroot() 37 | else: 38 | self.commandRoot = ET.ElementTree(ET.Element('commands')).getroot() 39 | 40 | def _getCommandByKey(self, key): 41 | _logger.debug('fetching command [%s]' % key) 42 | for command in self.commandRoot.findall('command'): 43 | if command.get('key') == key: 44 | _logger.debug('fetched command [%s]' % str(command)) 45 | return command 46 | _logger.warning('unknown command key [%s]' % key) 47 | return None 48 | 49 | def store(self, storableObject): 50 | """ 51 | Store to the repository a Storable instance 52 | see Storable.toXMLElement() 53 | if the storable with the same key is already present the store 54 | is ignored 55 | 56 | Parameters 57 | ---------- 58 | storableObject : storable.Storable 59 | a Storable object 60 | Returns 61 | ------- 62 | boolean 63 | True if store has happend False otherwise (command already exists) 64 | """ 65 | if self._getCommandByKey(storableObject.getKey()) is not None: 66 | _logger.debug('new store aborted key [%s] already found' % storableObject.getKey()) 67 | return False 68 | 69 | _toxml = storableObject.toXMLElement() 70 | 71 | self.commandRoot.append(_toxml) 72 | 73 | return True 74 | 75 | def fetch(self, key): 76 | return self._getCommandByKey(key) 77 | 78 | def flush(self): 79 | """flush the tree into repository file 80 | """ 81 | 82 | ET.ElementTree(self.commandRoot).write(self.repo_filename) 83 | -------------------------------------------------------------------------------- /tools/kvm_image/build_image/scripts/custom_firstboot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Add the libvirt group to the opc user to allow easier virsh usage 4 | sudo usermod -aG libvirt opc 5 | echo 'export LIBVIRT_DEFAULT_URI="qemu:///system"' >> /home/opc/.bashrc -------------------------------------------------------------------------------- /tools/kvm_image/build_image/scripts/custom_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown at 4 | # http://oss.oracle.com/licenses/upl. 5 | 6 | CMDPATH="command -v" 7 | SUDO=$($CMDPATH sudo) 8 | DNF=$($CMDPATH dnf) 9 | YUM=$($CMDPATH yum) 10 | # 11 | # if dnf exists, this is OL8 or later, use dnf. 12 | if [ ! ${DNF} ] 13 | then 14 | # 15 | # OL7 16 | ${SUDO} "${YUM}" install --assumeyes python36-libvirt 17 | ${SUDO} "${YUM}" install --assumeyes git 18 | else 19 | # 20 | # OL8+ 21 | ${SUDO} "${DNF}" install --assumeyes python3-libvirt 22 | ${SUDO} "${DNF}" install --assumeyes git 23 | fi -------------------------------------------------------------------------------- /tools/kvm_image/build_image/templates/al-kvm-image-template.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "user_availability_domain": "", 4 | "user_base_image_ocid": "", 5 | "user_compartment_ocid": "", 6 | "user_subnet_ocid": "", 7 | "user_image_name": "", 8 | "user_instance_name": "", 9 | "user_OL_version": "", 10 | "user_OL_flavour": "Autonomous", 11 | "user_shape_name": "", 12 | "user_custom_post_install_task": "", 13 | "user_custom_firstboot": "" 14 | }, 15 | "builders": [ 16 | { 17 | "use_instance_principals": "false", 18 | "ssh_username": "opc", 19 | "use_private_ip": "true", 20 | "availability_domain": "{{user `user_availability_domain`}}", 21 | "base_image_ocid": "{{user `user_base_image_ocid`}}", 22 | "compartment_ocid": "{{user `user_compartment_ocid`}}", 23 | "shape": "{{user `user_shape_name`}}", 24 | "subnet_ocid": "{{user `user_subnet_ocid`}}", 25 | "image_name": "{{user `user_image_name`}}", 26 | "instance_name": "{{user `user_instance_name`}}", 27 | "tags": { 28 | "OL_flavour": "{{user `user_OL_flavour`}}", 29 | "OL_version": "{{user `user_OL_version`}}" 30 | }, 31 | "type": "oracle-oci" 32 | } 33 | ], 34 | "provisioners": [ 35 | { 36 | "type": "file", 37 | "source": "{{user `user_custom_post_install_task_path`}}", 38 | "destination": "/tmp/{{user `user_custom_post_install_task`}}" 39 | }, 40 | { 41 | "type": "file", 42 | "source": "{{user `user_custom_firstboot_path`}}", 43 | "destination": "/tmp/{{user `user_custom_firstboot`}}" 44 | }, 45 | { 46 | "type": "file", 47 | "source": "{{user `user_custom_install_path`}}", 48 | "destination": "/tmp/{{user `user_custom_install`}}" 49 | }, 50 | { 51 | "type": "shell", 52 | "inline": [ 53 | "sudo -u root /bin/bash /tmp/custom_install.sh", 54 | "sudo -u root /bin/bash /tmp/custom_post_install_task.sh", 55 | "sudo -u root /bin/bash /tmp/custom_firstboot.sh" 56 | ] 57 | }, 58 | { 59 | "type": "shell", 60 | "inline": [ 61 | "sudo rm -f /etc/cron.d/al-update /var/lib/al-config/* /var/log/al.log", 62 | "sudo rm -f /tmp/custom*sh", 63 | "sudo sed -i '/^auto_update_time_window=/d;/# Auto update time window/d' /etc/al-config/al.conf", 64 | "sudo cp /var/lib/cloud/scripts/per-instance/oci.sh /var/tmp", 65 | "sudo /usr/libexec/oci-image-cleanup --force", 66 | "sudo mv /var/tmp/oci.sh /var/lib/cloud/scripts/per-instance", 67 | "history -c" 68 | ] 69 | } 70 | ] 71 | } 72 | -------------------------------------------------------------------------------- /tools/kvm_image/build_image/templates/ol-kvm-image-template.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "user_availability_domain": "", 4 | "user_base_image_ocid": "", 5 | "user_compartment_ocid": "", 6 | "user_subnet_ocid": "", 7 | "user_image_name": "", 8 | "user_instance_name": "", 9 | "user_OL_version": "", 10 | "user_OL_flavour": "NonAutonomous", 11 | "user_shape_name": "", 12 | "user_custom_post_install_task": "", 13 | "user_custom_firstboot": "" 14 | }, 15 | "builders": [ 16 | { 17 | "use_instance_principals": "false", 18 | "ssh_username": "opc", 19 | "use_private_ip": "true", 20 | "availability_domain": "{{user `user_availability_domain`}}", 21 | "base_image_ocid": "{{user `user_base_image_ocid`}}", 22 | "compartment_ocid": "{{user `user_compartment_ocid`}}", 23 | "shape": "{{user `user_shape_name`}}", 24 | "subnet_ocid": "{{user `user_subnet_ocid`}}", 25 | "image_name": "{{user `user_image_name`}}", 26 | "instance_name": "{{user `user_instance_name`}}", 27 | "tags": { 28 | "OL_flavour": "{{user `user_OL_flavour`}}", 29 | "OL_version": "{{user `user_OL_version`}}" 30 | }, 31 | "type": "oracle-oci" 32 | } 33 | ], 34 | "provisioners": [ 35 | { 36 | "type": "file", 37 | "source": "{{user `user_custom_post_install_task_path`}}", 38 | "destination": "/tmp/{{user `user_custom_post_install_task`}}" 39 | }, 40 | { 41 | "type": "file", 42 | "source": "{{user `user_custom_firstboot_path`}}", 43 | "destination": "/tmp/{{user `user_custom_firstboot`}}" 44 | }, 45 | { 46 | "type": "file", 47 | "source": "{{user `user_custom_install_path`}}", 48 | "destination": "/tmp/{{user `user_custom_install`}}" 49 | }, 50 | { 51 | "type": "shell", 52 | "inline": [ 53 | "sudo -u root /bin/bash /tmp/custom_install.sh", 54 | "sudo -u root /bin/bash /tmp/custom_post_install_task.sh", 55 | "sudo -u root /bin/bash /tmp/custom_firstboot.sh" 56 | ] 57 | }, 58 | { 59 | "type": "shell", 60 | "inline": [ 61 | "sudo rm -f /tmp/custom*sh", 62 | "history -c" 63 | ] 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/create_kvm_instance.0.11_May_05_2022.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oracle/oci-utils/fb5634c3550fa42484ed3560b2c901dd8db6e949/tools/kvm_image/test_image/create_kvm_instance.0.11_May_05_2022.bz2 -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/bin/create_guest_vm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | 12 | _PY3=/usr/bin/python3 13 | s_dir=${HOME}/bin 14 | 15 | 16 | exec ${_PY3} ${s_dir}/create_guest_vm.py "$@" 17 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_bridge_template_ol7: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability 21 | repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage 22 | # Root password 23 | rootpw --plaintext '__ROOTPASSWORD__' 24 | # System services 25 | services --enabled="chronyd" 26 | # Do not configure the X Window System 27 | skipx 28 | # System timezone 29 | timezone Europe/Brussels --utc 30 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 31 | # System bootloader configuration 32 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 33 | autopart --type=lvm 34 | # Partition clearing information 35 | clearpart --all --initlabel --drives=vda 36 | # Firewall configuration 37 | firewall --enabled --ssh 38 | # reboot after install 39 | reboot 40 | 41 | %packages 42 | @core 43 | chrony 44 | kexec-tools 45 | tmux 46 | psmisc 47 | firewalld 48 | python3 49 | strace 50 | tree 51 | %end 52 | 53 | %addon com_redhat_kdump --enable --reserve-mb='auto' 54 | 55 | %end 56 | 57 | %anaconda 58 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 59 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 60 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 61 | %end 62 | 63 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_bridge_template_ol8: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream 21 | # Root password 22 | rootpw --plaintext '__ROOTPASSWORD__' 23 | # System services 24 | services --enabled="chronyd" 25 | # Do not configure the X Window System 26 | skipx 27 | # System timezone 28 | timezone Europe/Brussels --utc 29 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 30 | # System bootloader configuration 31 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 32 | autopart --type=lvm 33 | # Partition clearing information 34 | clearpart --all --initlabel --drives=vda 35 | # Firewall configuration 36 | firewall --enabled --ssh 37 | # reboot after install 38 | reboot 39 | 40 | %packages 41 | @core 42 | chrony 43 | kexec-tools 44 | tmux 45 | psmisc 46 | firewalld 47 | python3 48 | strace 49 | tree 50 | %end 51 | 52 | %addon com_redhat_kdump --enable --reserve-mb='auto' 53 | 54 | %end 55 | 56 | %anaconda 57 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 58 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 59 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 60 | %end 61 | 62 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_bridge_template_ol9: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream 21 | # Root password 22 | rootpw --plaintext '__ROOTPASSWORD__' 23 | # System services 24 | services --enabled="chronyd" 25 | # Do not configure the X Window System 26 | skipx 27 | # System timezone 28 | timezone Europe/Brussels --utc 29 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 30 | # System bootloader configuration 31 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 32 | autopart --type=lvm 33 | # Partition clearing information 34 | clearpart --all --initlabel --drives=vda 35 | # Firewall configuration 36 | firewall --enabled --ssh 37 | # reboot after install 38 | reboot 39 | 40 | %packages 41 | @core 42 | chrony 43 | kexec-tools 44 | tmux 45 | psmisc 46 | firewalld 47 | python3 48 | strace 49 | tree 50 | %end 51 | 52 | %addon com_redhat_kdump --enable --reserve-mb='auto' 53 | 54 | %end 55 | 56 | %anaconda 57 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 58 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 59 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 60 | %end 61 | 62 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_direct_template_ol7: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability 21 | repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage 22 | # Root password 23 | rootpw --plaintext '__ROOTPASSWORD__' 24 | # System services 25 | services --enabled="chronyd" 26 | # Do not configure the X Window System 27 | skipx 28 | # System timezone 29 | timezone Europe/Brussels --utc 30 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 31 | # System bootloader configuration 32 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 33 | autopart 34 | # Partition clearing information 35 | clearpart --all --initlabel --drives=vda 36 | # Firewall configuration 37 | firewall --enabled --ssh 38 | # reboot after install 39 | reboot 40 | 41 | %packages 42 | @core 43 | chrony 44 | kexec-tools 45 | tmux 46 | psmisc 47 | firewalld 48 | python3 49 | strace 50 | tree 51 | %end 52 | 53 | %addon com_redhat_kdump --enable --reserve-mb='auto' 54 | 55 | %end 56 | 57 | %anaconda 58 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 59 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 60 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 61 | %end 62 | 63 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_direct_template_ol8: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream 21 | # Root password 22 | rootpw --plaintext '__ROOTPASSWORD__' 23 | # System services 24 | services --enabled="chronyd" 25 | # Do not configure the X Window System 26 | skipx 27 | # System timezone 28 | timezone Europe/Brussels --utc 29 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 30 | # System bootloader configuration 31 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 32 | autopart 33 | # Partition clearing information 34 | clearpart --all --initlabel --drives=vda 35 | # Firewall configuration 36 | firewall --enabled --ssh 37 | # reboot after install 38 | reboot 39 | 40 | %packages 41 | @core 42 | chrony 43 | kexec-tools 44 | tmux 45 | psmisc 46 | firewalld 47 | python3 48 | strace 49 | tree 50 | %end 51 | 52 | %addon com_redhat_kdump --enable --reserve-mb='auto' 53 | 54 | %end 55 | 56 | %anaconda 57 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 58 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 59 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 60 | %end 61 | 62 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/guest_instance/templates/kickstart_direct_template_ol9: -------------------------------------------------------------------------------- 1 | #version=DEVEL 2 | # System authorization information 3 | auth --enableshadow --passalgo=sha512 4 | # Use CDROM installation media 5 | cdrom 6 | # Use text mode install 7 | text 8 | # Run the Setup Agent on first boot 9 | firstboot --enable 10 | ignoredisk --only-use=vda 11 | # Keyboard layouts 12 | keyboard --vckeymap=us --xlayouts='' 13 | # System language 14 | lang en_US.UTF-8 15 | 16 | # Network information 17 | network --bootproto=static --device=link --gateway=__GATEWAY__ --ip=__IPADDRESS__ --nameserver=__NAMESERVER__ --netmask=__NETMASK__ --ipv6=auto --activate 18 | network --hostname=__HOSTNAME__ 19 | 20 | repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream 21 | # Root password 22 | rootpw --plaintext '__ROOTPASSWORD__' 23 | # System services 24 | services --enabled="chronyd" 25 | # Do not configure the X Window System 26 | skipx 27 | # System timezone 28 | timezone Europe/Brussels --utc 29 | user --groups=wheel --name=__USERNAME__ --password='__USERPASSWORD__' --plaintext --gecos="__USERNAME__" 30 | # System bootloader configuration 31 | bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda 32 | autopart 33 | # Partition clearing information 34 | clearpart --all --initlabel --drives=vda 35 | # Firewall configuration 36 | firewall --enabled --ssh 37 | # reboot after install 38 | reboot 39 | 40 | %packages 41 | @core 42 | chrony 43 | kexec-tools 44 | tmux 45 | psmisc 46 | firewalld 47 | python3 48 | strace 49 | tree 50 | %end 51 | 52 | %addon com_redhat_kdump --enable --reserve-mb='auto' 53 | 54 | %end 55 | 56 | %anaconda 57 | pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty 58 | pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok 59 | pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty 60 | %end 61 | 62 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/base_instance/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/base_instance/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | description = "Private IP of created instance." 7 | value = oci_core_instance.test_instance.*.private_ip[0] 8 | } 9 | 10 | //XXXXoutput "instance_public_ip" { 11 | //XXXX description = "Public IPs of created instance." 12 | //XXXX value = oci_core_instance.test_instance.*.public_ip[0] 13 | //XXXX} 14 | 15 | output "boot_volume_ocid" { 16 | description = "OCID of the boot volume of the created instance." 17 | value = oci_core_instance.test_instance.*.boot_volume_id[0] 18 | } 19 | 20 | output "instance_ocid" { 21 | description = "OCID of the created instance." 22 | value = oci_core_instance.test_instance.*.id[0] 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/bin/create_kvm_host: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # utility assists with configuring iscsi storage on Oracle Cloud 9 | # Infrastructure instances. See the manual page for more information. 10 | 11 | 12 | _PY3=/usr/bin/python3 13 | s_dir=${HOME}/bin 14 | 15 | 16 | exec ${_PY3} ${s_dir}/create_kvm_host.py "$@" 17 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/sh_scripts/initial_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 3 | # Licensed under the Universal Permissive License v 1.0 as shown 4 | # at http:/oss.oracle.com/licenses/upl. 5 | 6 | RPM=$(command -v rpm) 7 | GREP=$(command -v grep) 8 | FIND=$(command -v find) 9 | SED=$(command -v sed) 10 | MKDIR=$(command -v mkdir) 11 | DNF=dnf 12 | YUM=yum 13 | SYSTEMCTL=$(command -v systemctl) 14 | SUDO=$(command -v sudo) 15 | INITIALLOG=/logs/initial.log 16 | OSVERSION=$(${SED} -rn 's/.*([0-9])\.[0-9].*/\1/p' /etc/redhat-release) 17 | ${SUDO} --login mkdir -p /logs 18 | ${SUDO} --login mkdir /logs 19 | ${SUDO} --login chmod 777 /logs 20 | ${SUDO} --login echo ${OSVERSION} 2>&1 > ${INITIALLOG} 21 | if ! command -v dnf; then 22 | installrpm=$(command -v yum) 23 | ${SUDO} --login ${installrpm}-config-manager --enablerepo ol${OSVERSION}_developer 24 | else 25 | installrpm=$(command -v dnf) 26 | ${SUDO} --login ${installrpm} config-manager --set-enabled ol${OSVERSION}_developer 27 | fi 28 | # 29 | # excluding the kernel can cause the install failing 30 | # ${SUDO} --login ${installrpm} --assumeyes update --exclude=kernel*,oci-utils* 2>&1 >> ${INITIALLOG} 31 | ${SUDO} --login ${installrpm} --assumeyes install tree strace tmux iotop psmisc net-tools 2>&1 >> ${INITIALLOG} 32 | # 33 | # create space for storing isos for guest installs 34 | ${SUDO} --login mkdir -p /isos 35 | ${SUDO} --login mkdir /isos 36 | ${SUDO} --login chmod 777 /isos -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/api_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_sdk_config" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.oci_private_key 9 | destination = "/tmp/oci_private_key.pem" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.oci", 30 | "/bin/sudo --preserve-env cp /tmp/oci_private_key.pem /root/.oci/$(basename ${var.oci_private_key})", 31 | "/bin/sudo --preserve-env echo [DEFAULT] > /tmp/config", 32 | "/bin/sudo --preserve-env echo user=${var.user_ocid} >> /tmp/config", 33 | "/bin/sudo --preserve-env echo fingerprint=${var.fingerprint} >> /tmp/config", 34 | "/bin/sudo --preserve-env echo key_file=/root/.oci/$(basename ${var.oci_private_key}) >> /tmp/config", 35 | "/bin/sudo --preserve-env echo tenancy=${var.tenancy_ocid} >> /tmp/config", 36 | "/bin/sudo --preserve-env echo region=${var.region} >> /tmp/config", 37 | "/bin/sudo cp /tmp/config /root/.oci/config", 38 | "/bin/sudo chmod -R 600 /root/.oci/", 39 | "/bin/sudo chmod 700 /root/.oci", 40 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.oci", 41 | "/bin/sudo cp /tmp/config /home/${var.remote_user}/.oci/config", 42 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.oci", 43 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.oci/", 44 | "/bin/sudo chmod 700 /home/${var.remote_user}/.oci" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | value = module.base_instance.instance_private_ip 7 | } 8 | 9 | //XXXXoutput "instance_public_ip" { 10 | //XXXX value = module.base_instance.instance_public_ip 11 | //XXXX} 12 | 13 | output "boot_volume_ocid" { 14 | value = module.base_instance.boot_volume_ocid 15 | } 16 | 17 | output "instance_ocid" { 18 | value = module.base_instance.instance_ocid 19 | } -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/rsa_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_private_key" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.ssh_private_key 9 | destination = "/tmp/id_rsa" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.ssh", 30 | "/bin/sudo --preserve-env cp /tmp/id_rsa /root/.ssh/id_rsa", 31 | "/bin/sudo chmod -R 600 /root/.ssh/", 32 | "/bin/sudo chmod 700 /root/.ssh", 33 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.ssh", 34 | "/bin/sudo --preserve-env cp /tmp/id_rsa /home/${var.remote_user}/.ssh/id_rsa", 35 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.ssh", 36 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.ssh/", 37 | "/bin/sudo chmod 700 /home/${var.remote_user}/.ssh" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/rsa_pub_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_public_key" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.ssh_public_key 9 | destination = "/tmp/id_rsa.pub" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.ssh", 30 | "/bin/sudo --preserve-env cp /tmp/id_rsa.pub /root/.ssh/id_rsa.pub", 31 | "/bin/sudo chmod -R 600 /root/.ssh/", 32 | "/bin/sudo chmod 700 /root/.ssh", 33 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.ssh", 34 | "/bin/sudo --preserve-env cp /tmp/id_rsa.pub /home/${var.remote_user}/.ssh/id_rsa.pub", 35 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.ssh", 36 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.ssh/", 37 | "/bin/sudo chmod 700 /home/${var.remote_user}/.ssh/" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tools/kvm_image/test_image/host_instance/tf_scripts/version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } -------------------------------------------------------------------------------- /tools/oci_test_case.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | import logging 6 | from unittest import TestCase 7 | 8 | from .tree_config import TreeConfigParser 9 | 10 | 11 | class OciTestCase(TestCase): 12 | """Base class for OCI util test case 13 | """ 14 | test_config_dir = None 15 | 16 | @classmethod 17 | def _set_base(cls, namespace): 18 | """Set test base directory. 19 | from the base we derived the path to test configuration 20 | 21 | Parameters 22 | ---------- 23 | namespace : string 24 | the tests base dir 25 | 26 | """ 27 | OciTestCase.test_config_dir = namespace 28 | 29 | def setUp(self): 30 | """Test setUp method 31 | NOTE : any subclass implementation must call it during their own 32 | setUp phase 33 | """ 34 | self.properties = TreeConfigParser(OciTestCase.test_config_dir, self) 35 | self.logger = logging.getLogger('oci-utils.%s' % self.__class__.__name__) 36 | -------------------------------------------------------------------------------- /tools/provisioning/dev_instance/dev-instance.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http://oss.oracle.com/licenses/upl. 4 | terraform { 5 | required_providers { 6 | oci = ">= 3.56.0" 7 | } 8 | } 9 | 10 | variable "tenancy_ocid" {} 11 | variable "user_ocid" {} 12 | variable "fingerprint" {} 13 | variable "private_key_path" {} 14 | variable "region" {} 15 | variable "compartment_id" {} 16 | variable "availability_domain_id" {} 17 | variable "subnet_id" {} 18 | variable "instance_shape" {} 19 | variable "instance_image_ocid" {} 20 | 21 | variable "ssh_private_key_path" {} 22 | variable "ssh_authorized_key_path" {} 23 | variable "ssh_user" {} 24 | variable "ssh_public_key_path" {} 25 | 26 | variable "dns_search_domains" {} 27 | variable "dns_server_ip" {} 28 | variable "http_proxy_url" {} 29 | variable "https_proxy_url" {} 30 | 31 | 32 | provider "oci" { 33 | tenancy_ocid = var.tenancy_ocid 34 | user_ocid = var.user_ocid 35 | fingerprint = var.fingerprint 36 | private_key_path = var.private_key_path 37 | region = var.region 38 | } 39 | 40 | data "oci_identity_availability_domains" "ad" { 41 | compartment_id = var.compartment_id 42 | } 43 | 44 | 45 | resource "oci_core_instance" "dev_instance" { 46 | availability_domain = var.availability_domain_id 47 | compartment_id = var.compartment_id 48 | display_name = "OCI-DEV-Instance" 49 | shape = var.instance_shape 50 | 51 | create_vnic_details { 52 | subnet_id = var.subnet_id 53 | display_name = "Primaryvnic" 54 | assign_public_ip = false 55 | } 56 | 57 | source_details { 58 | source_type = "image" 59 | source_id = var.instance_image_ocid 60 | } 61 | 62 | preserve_boot_volume = false 63 | 64 | metadata = { 65 | ssh_authorized_keys = file(var.ssh_authorized_key_path) 66 | } 67 | 68 | 69 | timeouts { 70 | create = "60m" 71 | } 72 | 73 | } 74 | 75 | resource "oci_core_vnic_attachment" "test_vnic_attachment_0" { 76 | create_vnic_details { 77 | subnet_id = var.subnet_id 78 | } 79 | instance_id = oci_core_instance.dev_instance.id 80 | nic_index = 0 81 | } 82 | resource "oci_core_instance_console_connection" "instance_console_connection" { 83 | depends_on = [oci_core_instance.dev_instance] 84 | #Required 85 | instance_id = oci_core_instance.dev_instance.id 86 | public_key = file(var.ssh_public_key_path) 87 | } 88 | 89 | resource "oci_core_volume" "vm_tank_volume" { 90 | availability_domain = var.availability_domain_id 91 | compartment_id = var.compartment_id 92 | display_name = "DevInstanceTank" 93 | size_in_gbs = 256 94 | } 95 | resource "oci_core_volume_attachment" "vm_tank_volume_attachment" { 96 | attachment_type = "iscsi" 97 | instance_id = oci_core_instance.dev_instance.id 98 | volume_id = oci_core_volume.vm_tank_volume.id 99 | 100 | is_read_only = false 101 | 102 | } 103 | 104 | 105 | output "instance_private_ip" { 106 | value = oci_core_instance.dev_instance.*.private_ip 107 | } 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/README.md: -------------------------------------------------------------------------------- 1 | # Assistance for creating a basic instance in OCI. 2 | 3 | ## Prerequisites 4 | 5 | - terraform software installed 6 | - oci-sdk installed and configured for direct authentication (for now) 7 | 8 | ## Command line 9 | ```buildoutcfg 10 | $ create_instance --help 11 | usage: create_instance.py [-h] [-n DISPLAY_NAME] [-p PROFILE] [-c CONFIGFILE] 12 | [-d DATADIR] [-f VARFILENAME] 13 | 14 | Configure oci utils auto test. 15 | 16 | Arguments: 17 | -h, --help show this help message and exit 18 | -n DISPLAY_NAME, --name DISPLAY_NAME 19 | The display name of the instance to create. There is 20 | no default, if not provided, the script asks for it. 21 | -p PROFILE, --profile PROFILE 22 | The profile in the cli/sdk config file, default is 23 | DEFAULT. 24 | -c CONFIGFILE, --config CONFIGFILE 25 | The cli/sdk config file, default is ~/.oci/config. 26 | -d DATADIR, --data-directory DATADIR 27 | Root directory with data for auto test run, default is 28 | ~//data. 29 | -f VARFILENAME, --var-file VARFILENAME 30 | filename to store the variables; the extension 31 | .tfvars.json is added automatically. 32 | 33 | ``` 34 | ## Flow 35 | - copy this tree/tar ball and expand to a working location 36 | - chdir to **gen_instance** directory 37 | - `make` will show some help information 38 | - install by executing `make install`, this will the copy template structure to a directory `~/create_instance` and the python code `create_instance.py` and the bash wrapper `create_instance` to `~/bin` 39 | - run `~/bin/create_instance` which completes the variable data, creates a directory `~/oci_instance/` which contains the data for creating the instance, and creates create and destroy scripts. 40 | - the code assumes the presence of **${HOME}/.ssh/id_rsa** and **${HOME}/.ssh/id_rsa.pub**. -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/base_instance/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/base_instance/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | description = "Private IP of created instance." 7 | value = oci_core_instance.test_instance.*.private_ip[0] 8 | } 9 | 10 | //XXXXoutput "instance_public_ip" { 11 | //XXXX description = "Public IPs of created instance." 12 | //XXXX value = oci_core_instance.test_instance.*.public_ip[0] 13 | //XXXX} 14 | 15 | output "boot_volume_ocid" { 16 | description = "OCID of the boot volume of the created instance." 17 | value = oci_core_instance.test_instance.*.boot_volume_id[0] 18 | } 19 | 20 | output "instance_ocid" { 21 | description = "OCID of the created instance." 22 | value = oci_core_instance.test_instance.*.id[0] 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/bin/create_instance: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility assists with creating an oci instance. 8 | 9 | _PY3=/usr/bin/python3 10 | # s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 11 | 12 | 13 | exec ${_PY3} ${HOME}/bin/create_instance.py $@ 14 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/api_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_sdk_config" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.oci_private_key 9 | destination = "/tmp/oci_private_key.pem" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.oci", 30 | "/bin/sudo --preserve-env cp /tmp/oci_private_key.pem /root/.oci/$(basename ${var.oci_private_key})", 31 | "/bin/sudo --preserve-env echo [DEFAULT] > /tmp/config", 32 | "/bin/sudo --preserve-env echo user=${var.user_ocid} >> /tmp/config", 33 | "/bin/sudo --preserve-env echo fingerprint=${var.fingerprint} >> /tmp/config", 34 | "/bin/sudo --preserve-env echo key_file=/root/.oci/$(basename ${var.oci_private_key}) >> /tmp/config", 35 | "/bin/sudo --preserve-env echo tenancy=${var.tenancy_ocid} >> /tmp/config", 36 | "/bin/sudo --preserve-env echo region=${var.region} >> /tmp/config", 37 | "/bin/sudo cp /tmp/config /root/.oci/config", 38 | "/bin/sudo chmod -R 600 /root/.oci/", 39 | "/bin/sudo chmod 700 /root/.oci", 40 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.oci", 41 | "/bin/sudo cp /tmp/config /home/${var.remote_user}/.oci/config", 42 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.oci", 43 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.oci/", 44 | "/bin/sudo chmod 700 /home/${var.remote_user}/.oci" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | value = module.base_instance.instance_private_ip 7 | } 8 | 9 | //XXXXoutput "instance_public_ip" { 10 | //XXXX value = module.base_instance.instance_public_ip 11 | //XXXX} 12 | 13 | output "boot_volume_ocid" { 14 | value = module.base_instance.boot_volume_ocid 15 | } 16 | 17 | output "instance_ocid" { 18 | value = module.base_instance.instance_ocid 19 | } -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/rsa_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_private_key" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.ssh_private_key 9 | destination = "/tmp/id_rsa" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.ssh", 30 | "/bin/sudo --preserve-env cp /tmp/id_rsa /root/.ssh/id_rsa", 31 | "/bin/sudo chmod -R 600 /root/.ssh/", 32 | "/bin/sudo chmod 700 /root/.ssh", 33 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.ssh", 34 | "/bin/sudo --preserve-env cp /tmp/id_rsa /home/${var.remote_user}/.ssh/id_rsa", 35 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.ssh", 36 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.ssh/", 37 | "/bin/sudo chmod 700 /home/${var.remote_user}/.ssh" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/rsa_pub_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_public_key" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.ssh_public_key 9 | destination = "/tmp/id_rsa.pub" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.ssh", 30 | "/bin/sudo --preserve-env cp /tmp/id_rsa.pub /root/.ssh/id_rsa.pub", 31 | "/bin/sudo chmod -R 600 /root/.ssh/", 32 | "/bin/sudo chmod 700 /root/.ssh", 33 | "/bin/sudo --preserve-env mkdir -p /home/${var.remote_user}/.ssh", 34 | "/bin/sudo --preserve-env cp /tmp/id_rsa.pub /home/${var.remote_user}/.ssh/id_rsa.pub", 35 | "/bin/sudo --preserve-env chown -R ${var.remote_user}:${var.remote_user} /home/${var.remote_user}/.ssh", 36 | "/bin/sudo chmod -R 600 /home/${var.remote_user}/.ssh/", 37 | "/bin/sudo chmod 700 /home/${var.remote_user}/.ssh/" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tools/provisioning/gen_instance/tf_scripts/version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown at 3 | # http://oss.oracle.com/licenses/upl. 4 | # 5 | # makefile for creating an instance in OCI 6 | # 7 | # 8 | # 9 | # proxy 10 | # 11 | export no_proxy=169.254.169.254,.oraclecloud.com 12 | # 13 | CREATEKVMINSTANCEPY=bin/create_kvm_instance.py 14 | CREATEKVMINSTANCESH=bin/create_kvm_instance 15 | BINARIES=$(CREATEKVMINSTANCESH) $(CREATEKVMINSTANCEPY) 16 | 17 | BASEDATATF=base_instance/data.tf 18 | BASEMAINTF=base_instance/main.tf 19 | BASEOUTPUTTF=base_instance/output.tf 20 | BASES=$(BASEDATATF) $(BASEMAINTF) $(BASEOUTPUTTF) 21 | 22 | TFAPITF=tf_scripts/api_key.tf 23 | TFDATATF=tf_scripts/data.tf 24 | TFMAINTF=tf_scripts/main.tf 25 | TFVERSION=tf_scripts/version.tf 26 | TFOUTPUTTF=tf_scripts/output.tf 27 | TFSCRIPTS=$(TFAPITF) $(TFDATATF) $(TFMAINTF) $(TFVERSION) $(TFOUTPUTTF) 28 | 29 | INITIALSCRIPT=gen_scripts/initial_config.sh 30 | SHSCRIPTS=$(INITIALSCRIPT) 31 | # 32 | # files involved 33 | FILELIST=Makefile README.md $(BINARIES) $(BASES) $(TFSCRIPTS) $(SHSCRIPTS) 34 | # 35 | TARGET=create_kvm_instance 36 | VERSION=0.1_Dec_09_2021 37 | WRITE=@echo 38 | CREATETAR=tar -cjvf 39 | EXPANDTAR=tar -xjvf 40 | MKDIR=-mkdir -p 41 | RMFORCE=rm -rf 42 | DELETE=rm -f 43 | INSTALL=install --mode=755 44 | COPYA=cp -a 45 | SUDO=sudo 46 | # 47 | # destinations 48 | HOMEBINS=$(HOME)/bin 49 | HOMEBASES=$(HOME)/$(TARGET)/base_instance 50 | HOMETFSCRIPTS=$(HOME)/$(TARGET)/tf_scripts 51 | HOMESHSCRIPTS=$(HOME)/$(TARGET)/sh_scripts 52 | # 53 | # tarball name 54 | TARBALL=$(TARGET).$(VERSION).bz 55 | # help 56 | # 57 | .PHONY: help 58 | help: 59 | $(WRITE) "help info:" 60 | $(WRITE) " make help" 61 | $(WRITE) " make show_version" 62 | $(WRITE) " make tarball" 63 | $(WRITE) " make install" 64 | $(WRITE) " make uninstall" 65 | 66 | # 67 | # version info 68 | .PHONY: showversion 69 | show_version: 70 | $(WRITE) "version of $(TARGET) source is $(VERSION)" 71 | # 72 | # create tarball 73 | tarball: 74 | $(CREATETAR) $(TARBALL) $(FILELIST) 75 | # 76 | # create directories 77 | bindir: 78 | $(MKDIR) $(HOMEBINS) 79 | 80 | basedir: 81 | $(MKDIR) $(HOMEBASES) 82 | 83 | tfscriptdir: 84 | $(MKDIR) $(HOMETFSCRIPTS) 85 | 86 | shscriptdir: 87 | $(MKDIR) $(HOMESHSCRIPTS) 88 | # 89 | # lists 90 | $(BINARIES): bindir 91 | $(WRITE) $(BINARIES) 92 | 93 | $(BASES): basedir 94 | $(WRITE) $(BASES) 95 | 96 | $(TFSCRIPTS): tfscriptdir 97 | $(WRITE) $(TFSCRIPTS) 98 | 99 | $(SHSCRIPTS): shscriptdir 100 | $(WRITE) $(SHSCRIPTS) 101 | # 102 | # install 103 | BIN: $(BINARIES) 104 | $(INSTALL) $^ $(HOMEBINS) 105 | 106 | $(HOMEBASES): $(BASES) 107 | $(COPYA) $^ $@ 108 | 109 | $(HOMETFSCRIPTS): $(TFSCRIPTS) 110 | $(COPYA) $^ $@ 111 | 112 | $(HOMESHSCRIPTS): $(SHSCRIPTS) 113 | $(COPYA) $^ $@ 114 | 115 | install: BIN $(HOMETFSCRIPTS) $(HOMEBASES) $(HOMESHSCRIPTS) 116 | $(WRITE) "Installed" 117 | # 118 | # uninstall 119 | uninstallbins: $(BINARIES) 120 | $(foreach var,$(BINARIES),$(DELETE) $(HOME)/$(var);) 121 | 122 | uninstalldata: 123 | $(RMFORCE) $(HOME)/$(TARGET) 124 | 125 | uninstall: uninstallbins uninstalldata 126 | $(WRITE) "Uninstalled" -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/README.md: -------------------------------------------------------------------------------- 1 | # Assistance for creating an oci-kvm instance in OCI. 2 | 3 | ## Prerequisites 4 | 5 | - terraform software installed 6 | - oci-sdk installed and configured for direct authentication (for now) 7 | 8 | ## Overview 9 | This utility generates a terraform script which will create an instance in OCI which is ready to act as an oci-kvm server in OCI. The instance can be virtual (if supported by the hardware) as well as bare metal. 10 | The instance will have all the necessary software packages installed as well as the required operating system configuration changes. 11 | The **ocid** service will be enabled and running. It is advised to reboot the newly create instance after provisioning. 12 | ## Command line 13 | ```buildoutcfg 14 | $ create_kvm_instance --help 15 | usage: create_kvm_instance.py [-h] [-n DISPLAY_NAME] [-p PROFILE] 16 | [-c CONFIGFILE] [-d DATADIR] [-f VARFILENAME] 17 | 18 | Configure oci utils auto test. 19 | 20 | Arguments: 21 | -h, --help show this help message and exit 22 | -n DISPLAY_NAME, --name DISPLAY_NAME 23 | The display name of the instance to create. There is 24 | no default, if not provided, the script asks for it. 25 | -p PROFILE, --profile PROFILE 26 | The profile in the cli/sdk config file, default is 27 | DEFAULT. 28 | -c CONFIGFILE, --config CONFIGFILE 29 | The cli/sdk config file, default is ~/.oci/config. 30 | -d DATADIR, --data-directory DATADIR 31 | Root directory with data for auto test run, default is 32 | ~//data. 33 | -f VARFILENAME, --var-file VARFILENAME 34 | filename to store the variables; the extension 35 | .tfvars.json is added automatically. 36 | ``` 37 | ## Flow 38 | - copy this tree/tar ball and expand to a working location 39 | - chdir to **kvm_instance** directory 40 | - `make` will show some help information 41 | - install by executing `make install`, this will copy the template structure to a directory `~/create_kvm_instance` and the python code `create_kvm_instance.py` and the bash wrapper `create_kvm_instance` to `~/bin` 42 | - run `~/bin/create_kvm_instance` which completes the variable data, creates a directory `~/oci_instance/` which contains the data for creating the instance, and creates create and destroy scripts. 43 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/base_instance/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/base_instance/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | description = "Private IP of created instance." 7 | value = oci_core_instance.test_instance.*.private_ip[0] 8 | } 9 | 10 | //XXXXoutput "instance_public_ip" { 11 | //XXXX description = "Public IPs of created instance." 12 | //XXXX value = oci_core_instance.test_instance.*.public_ip[0] 13 | //XXXX} 14 | 15 | output "boot_volume_ocid" { 16 | description = "OCID of the boot volume of the created instance." 17 | value = oci_core_instance.test_instance.*.boot_volume_id[0] 18 | } 19 | 20 | output "instance_ocid" { 21 | description = "OCID of the created instance." 22 | value = oci_core_instance.test_instance.*.id[0] 23 | } 24 | 25 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/bin/create_kvm_instance: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | # utility assists with creating an oci-kvm instance. 8 | 9 | _PY3=/usr/bin/python3 10 | # s_dir=`${_PY3} -c 'import os.path ; import oci_utils.impl ; print (os.path.dirname(oci_utils.impl.__file__))' 2>/dev/null` 11 | 12 | 13 | exec ${_PY3} ${HOME}/bin/create_kvm_instance.py $@ 14 | 15 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/tf_scripts/api_key.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | resource "null_resource" "oci_sdk_config" { 6 | depends_on = [module.base_instance] 7 | provisioner "file" { 8 | source = var.oci_private_key 9 | destination = "/tmp/oci_private_key.pem" 10 | connection { 11 | type = "ssh" 12 | user = var.remote_user 13 | agent = false 14 | host = module.base_instance.instance_XXXX_ip 15 | timeout = "15m" 16 | private_key = file(var.ssh_private_key) 17 | } 18 | } 19 | provisioner "remote-exec" { 20 | connection { 21 | type = "ssh" 22 | user = var.remote_user 23 | agent = false 24 | host = module.base_instance.instance_XXXX_ip 25 | timeout = "15m" 26 | private_key = file(var.ssh_private_key) 27 | } 28 | inline = [ 29 | "/bin/sudo --preserve-env mkdir -p /root/.oci", 30 | "/bin/sudo --preserve-env cp /tmp/oci_private_key.pem /root/.oci/$(basename ${var.oci_private_key})", 31 | "/bin/sudo --preserve-env echo [DEFAULT] > /tmp/config", 32 | "/bin/sudo --preserve-env echo user=${var.user_ocid} >> /tmp/config", 33 | "/bin/sudo --preserve-env echo fingerprint=${var.fingerprint} >> /tmp/config", 34 | "/bin/sudo --preserve-env echo key_file=/root/.oci/$(basename ${var.oci_private_key}) >> /tmp/config", 35 | "/bin/sudo --preserve-env echo tenancy=${var.tenancy_ocid} >> /tmp/config", 36 | "/bin/sudo --preserve-env echo region=${var.region} >> /tmp/config", 37 | "/bin/sudo cp /tmp/config /root/.oci/config", 38 | "/bin/sudo chmod -R 600 /root/.oci/" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/tf_scripts/data.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | data "oci_identity_availability_domains" "ads" { 6 | compartment_id = var.tenancy_ocid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/tf_scripts/output.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | output "instance_private_ip" { 6 | value = module.base_instance.instance_private_ip 7 | } 8 | 9 | //XXXXoutput "instance_public_ip" { 10 | //XXXX value = module.base_instance.instance_public_ip 11 | //XXXX} 12 | 13 | output "boot_volume_ocid" { 14 | value = module.base_instance.boot_volume_ocid 15 | } 16 | 17 | output "instance_ocid" { 18 | value = module.base_instance.instance_ocid 19 | } -------------------------------------------------------------------------------- /tools/provisioning/kvm_instance/tf_scripts/version.tf: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. 2 | // Licensed under the Universal Permissive License v 1.0 as shown 3 | // at http:/oss.oracle.com/licenses/upl. 4 | 5 | terraform { 6 | required_providers { 7 | oci = ">= 3.56.0" 8 | } 9 | } -------------------------------------------------------------------------------- /tools/provisioning/test_instance/userdata/oci-tests-env: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 4 | # Licensed under the Universal Permissive License v 1.0 as shown at 5 | # http://oss.oracle.com/licenses/upl. 6 | 7 | 8 | # This file contains environement variables and script commands 9 | # to be push on remote instance within /etc/profile.d 10 | 11 | export http_proxy=${http_proxy_url} 12 | export https_proxy=${https_proxy_url} 13 | export no_proxy=169.254.169.254,.oraclecloud.com,.oraclecorp.com,.us.oracle.com 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tools/provisioning/test_instance/userdata/oci_resolver_config: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | search ${dns_search_domains} 6 | nameserver ${dns_server_ip} 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tools/test_runnner.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 2 | # Licensed under the Universal Permissive License v 1.0 as shown 3 | # at http://oss.oracle.com/licenses/upl. 4 | 5 | from unittest import TextTestRunner 6 | import sys 7 | from .execution.store import getCommandStore 8 | 9 | 10 | class OciUtilsTestRunner(TextTestRunner): 11 | """Base class for OCI util test runner 12 | Subclass of TextTestRunner 13 | """ 14 | 15 | def __init__(self, mode): 16 | """Creates a new OciUtilsTestRunner 17 | This will replace the current subprocess.Popen implementation 18 | by a custom one responsible of recirding or replay execution 19 | """ 20 | 21 | TextTestRunner.__init__(self) 22 | 23 | assert (mode in ['replay', 'record']), 'unkonwn mode' 24 | 25 | # if subprocess module is already imported 26 | # delete it first 27 | if 'subprocess' in sys.modules: 28 | del sys.modules['subprocess'] 29 | 30 | # import the subprocess module and keep a reference on it. 31 | _subprocess_origin = __import__('subprocess') 32 | 33 | # We gonna need the real implementation to execute command and to be able 34 | # to use it a super-class for our own Popen impl so we keep it as 35 | # a new symbol _Popen 36 | _subprocess_origin.__dict__['_Popen'] = _subprocess_origin.Popen 37 | _subprocess_origin.__all__.append('_Popen') 38 | 39 | # import our own Popen class 40 | _new_popen = __import__('snooppopen') 41 | 42 | # Replace the Popen class with our implementation 43 | if mode == 'record': 44 | _subprocess_origin.__dict__['Popen'] = _new_popen.RecordPopen 45 | # 'call' and 'check_call' discard stdout and stderr 46 | # but we need to record them any way. otherwise following scenario will fail 47 | # call('foo') 48 | # ... 49 | # check_output('foo') 50 | # -> for second method call, as we already record the command, we won't 51 | # execute/record it again . i.e we never have the output 52 | _subprocess_origin.__dict__['_call'] = _subprocess_origin.call 53 | _subprocess_origin.__all__.append('_call') 54 | _subprocess_origin.__dict__['call'] = _new_popen.call 55 | elif mode == 'replay': 56 | _subprocess_origin.__dict__['Popen'] = _new_popen.ReplayPopen 57 | 58 | 59 | class OciUtilsTestRunnerReplay(OciUtilsTestRunner): 60 | """Replay OciUtilsTestRunner 61 | Any executed command line will be simulate and outputs will be 62 | fetched from command repository 63 | """ 64 | 65 | def __init__(self): 66 | OciUtilsTestRunner.__init__(self, 'replay') 67 | 68 | 69 | class OciUtilsTestRunnerRecord(OciUtilsTestRunner): 70 | """Record OciUtilsTestRunner 71 | Any executed command line will be recorded to command repository 72 | """ 73 | 74 | def __init__(self): 75 | OciUtilsTestRunner.__init__(self, 'record') 76 | 77 | def run(self, test): 78 | try: 79 | return OciUtilsTestRunner.run(self, test) 80 | finally: 81 | getCommandStore().flush() 82 | --------------------------------------------------------------------------------