### Example: Start glance-api Server Source: https://github.com/openstack/glance/blob/master/doc/source/admin/controllingservers.rst This example demonstrates starting the glance-api server with a specific configuration file and verifies its running status using ps aux. ```bash $ sudo glance-control api start glance-api.conf Starting glance-api with /home/jsuh/glance.conf $ ps aux | grep glance root 20038 4.0 0.1 12728 9116 ? Ss 12:51 0:00 /usr/bin/python /usr/bin/glance-api /home/jsuh/glance-api.conf jsuh 20042 0.0 0.0 3368 744 pts/1 S+ 12:51 0:00 grep glance ``` -------------------------------- ### Manually Start Glance API Server Source: https://github.com/openstack/glance/blob/master/doc/source/admin/controllingservers.rst This example shows how to manually start the glance-api server in a shell. It includes specifying the configuration file and enabling debug mode. The output demonstrates the configuration options loaded and the server starting up. It also shows how to verify the process is running using 'ps aux'. ```bash $ sudo glance-api --config-file glance-api.conf --debug & jsuh@mc-ats1:~$ 2011-04-13 14:50:12 DEBUG [glance-api] ******************************************************************************** 2011-04-13 14:50:12 DEBUG [glance-api] Configuration options gathered from config file: 2011-04-13 14:50:12 DEBUG [glance-api] /home/jsuh/glance-api.conf 2011-04-13 14:50:12 DEBUG [glance-api] ================================================ 2011-04-13 14:50:12 DEBUG [glance-api] bind_host 65.114.169.29 2011-04-13 14:50:12 DEBUG [glance-api] bind_port 9292 2011-04-13 14:50:12 DEBUG [glance-api] debug True 2011-04-13 14:50:12 DEBUG [glance-api] default_store file 2011-04-13 14:50:12 DEBUG [glance-api] filesystem_store_datadir /home/jsuh/images/ 2011-04-13 14:50:12 DEBUG [glance-api] ******************************************************************************** 2011-04-13 14:50:12 DEBUG [routes.middleware] Initialized with method overriding = True, and path info altering = True 2011-04-13 14:50:12 DEBUG [eventlet.wsgi.server] (21354) wsgi starting up on http://65.114.169.29:9292/ $ ps aux | grep glance root 20009 0.7 0.1 12744 9148 pts/1 S 12:47 0:00 /usr/bin/python /usr/bin/glance-api glance-api.conf --debug jsuh 20017 0.0 0.0 3368 744 pts/1 S+ 12:47 0:00 grep glance ``` -------------------------------- ### Glance Configuration After Upgrade (Multiple Cinder Stores, New Backend) Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This configuration example shows the 'new' Cinder store setup after an upgrade, with a specific volume type assigned. ```ini # new configuration in glance [DEFAULT] enabled_backends = old:cinder, new:cinder [glance_store] default_backend = new [new] rootwrap_config = /etc/glance/rootwrap.conf cinder_volume_type = glance-new description = NFS based cinder store cinder_catalog_info = volumev3::publicURL cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service # etc.. ``` -------------------------------- ### Example Plugin Entry Point Source: https://github.com/openstack/glance/blob/master/doc/source/admin/interoperable-image-import.rst An example of how a plugin should be listed in the entry point list for the glance.image_import.plugins namespace in setup.cfg. ```text no_op = glance.async_.flows.plugins.no_op:get_flow ``` -------------------------------- ### Example Single Store Credentials Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst Example of cinder store specific configuration parameters set in a single store setup. These values should be retained after upgrading to multiple stores. ```ini [glance_store] stores = cinder, file, http default_store = cinder cinder_state_transition_timeout = 300 rootwrap_config = /etc/glance/rootwrap.conf cinder_catalog_info = volumev3::publicURL cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service ``` -------------------------------- ### Glance Configuration After Upgrade (Multiple Cinder Stores, Default Backend Old) Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This configuration example shows the Glance setup after an upgrade, with the default backend set to 'old' and a specific volume type. ```ini # new configuration in glance [DEFAULT] enabled_backends = old:cinder,new:cinder [glance_store] default_backend = old [old] rootwrap_config = /etc/glance/rootwrap.conf cinder_volume_type = glance-old # as per old cinder.conf description = LVM based cinder store cinder_catalog_info = volumev3::publicURL ``` -------------------------------- ### Glance Configuration After Upgrade (Multiple Cinder Stores, Old Backend) Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This configuration example shows the 'old' Cinder store setup after an upgrade, replicating the previous single-store configuration. ```ini # new configuration in glance [DEFAULT] enabled_backends = old:cinder, new:cinder [glance_store] default_backend = new # cinder store as per old (single store configuration) [old] rootwrap_config = /etc/glance/rootwrap.conf description = LVM based cinder store cinder_catalog_info = volumev3::publicURL cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service # etc.. ``` -------------------------------- ### Example URL for OpenStack Components Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/documentation.rst Use this consistent format for example URLs when referring to OpenStack components in documentation. ```text project.openstack.example.org ``` -------------------------------- ### Glance Configuration Before Upgrade (Single Cinder Store) Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This is an example of the Glance configuration before upgrading to a multi-store setup, using a single Cinder store. ```ini # old configuration in glance [glance_store] stores = cinder, file, http default_store = cinder cinder_state_transition_timeout = 300 rootwrap_config = /etc/glance/rootwrap.conf cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service cinder_catalog_info = volumev3::publicURL cinder_volume_type = glance-old ``` -------------------------------- ### Install Glance Package Source: https://github.com/openstack/glance/blob/master/doc/source/install/install-debian.rst Installs the Glance package using apt. This is a prerequisite for configuring the service. ```console # apt install glance ``` -------------------------------- ### Enable and Start Glance Services Source: https://github.com/openstack/glance/blob/master/doc/source/install/install-rdo.rst Enables the Glance API service to start on system boot and then starts the service. This ensures the Glance service is running and accessible. ```console # systemctl enable openstack-glance-api.service # systemctl start openstack-glance-api.service ``` -------------------------------- ### Example Configuration Directory Structure Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This example shows a typical structure for a configuration directory, where numbered files indicate parse order. This is used with the --config-dir option. ```bash $ ls /etc/glance/glance-api.d 00-core.conf 01-swift.conf 02-ssl.conf ... etc. ``` -------------------------------- ### Migration Naming Convention Examples Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/database_migrations.rst Provides examples of migration names following the specified conventions. ```text Monolith migration: ocata01 Expand migration: ocata_expand01 Contract migration: ocata_contract01 ``` -------------------------------- ### Start a Glance Server Source: https://github.com/openstack/glance/blob/master/doc/source/admin/controllingservers.rst Use glance-control with a server name and 'start' to launch a daemonized Glance server process. Command-line options and a configuration file path can be provided. ```bash $ sudo glance-control [OPTIONS] start [CONFPATH] ``` -------------------------------- ### Add Image Tag Request Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/index.md This example demonstrates how to add a tag to an image. Ensure the image exists and you have ownership. ```http PUT /v2/images/{image_id}/tags/{tag} HTTP/1.1 Host: example.com Content-Type: application/json Accept: application/json X-Auth-Token: ``` -------------------------------- ### Property Protection Configuration Example Source: https://github.com/openstack/glance/blob/master/doc/source/admin/interoperable-image-import.rst Example of property protection configuration to control creation, update, and deletion of injected image properties. ```ini [property1] create = admin,service_role read = admin,service_role,member,_member_ update = admin delete = admin ``` -------------------------------- ### Example Glance API Call URL Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/documentation.rst An example of how to format a URL for an image-list call to the Glance API. ```text http://glance.openstack.example.org/v2/images ``` -------------------------------- ### Example Policy Rule Using Tenant Owner Attribute Source: https://github.com/openstack/glance/blob/master/doc/source/admin/policies.rst This example illustrates a policy rule that utilizes the 'owner' attribute, which is specific to image-related actions. It shows how to reference user attributes within a rule definition. ```json { "tenant:%(owner)s": "role:owner" } ``` -------------------------------- ### Response Example for Tag Definition Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md This JSON object shows an example response when a tag definition is successfully created or retrieved, including its creation timestamp, name, and last updated timestamp. ```json { "created_at": "2015-05-09T01:12:31Z", "name": "added-sample-tag", "updated_at": "2015-05-09T01:12:31Z" } ``` -------------------------------- ### Base Class Example Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/domain_model.rst Defines the fundamental interface for domain model objects. ```Python class Base(object): """Base class in domain model.""" msg = "Hello Domain" def print_msg(self): print(self.msg) def sum_numbers(self, *args): return sum(args) ``` -------------------------------- ### Get Tag Definition Response Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md Example of a successful response when retrieving a tag definition. This shows the structure of the returned tag object. ```json { "created_at": "2015-05-06T23:16:12Z", "name": "sample-tag2", "updated_at": "2015-05-06T23:16:12Z" } ``` -------------------------------- ### Install python-glanceclient Source: https://github.com/openstack/glance/blob/master/doc/source/admin/troubleshooting.rst Install the python-glanceclient package using pip to get the 'glance' command-line tool. This utility is used for managing all your images within OpenStack Glance. ```console # pip install python-glanceclient ``` -------------------------------- ### Swift Store Configuration File Example Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This INI format shows how to define references for multiple Swift accounts or backing stores. Each reference includes user credentials, domain information, and the authentication address. ```ini [ref1] user = project_name1:user_name1 key = key1 user_domain_id = default project_domain_id = default auth_address = http://localhost:5000/v3 [ref2] user = project_name2:user_name2 key = key2 user_domain_id = default project_domain_id = default auth_address = http://localhost:5000/v3 ``` -------------------------------- ### Image Memberships Response Example Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst The response to a GET request for image memberships is JSON data containing a list of members, each with a 'member_id' and a 'can_share' boolean. ```json { "members": [ {"member_id": "project1", "can_share": false} ...] } ``` -------------------------------- ### Get Namespace Response Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md This JSON object represents a successful response when retrieving a metadefs namespace. It includes details about the namespace's properties and associations. ```json { "created_at": "2016-06-28T14:57:10Z", "description": "The libvirt compute driver options.", "display_name": "libvirt Driver Options", "namespace": "OS::Compute::Libvirt", "owner": "admin", "properties": { "boot_menu": { "description": "If true, enables the BIOS bootmenu.", "enum": [ "true", "false" ], "title": "Boot Menu", "type": "string" }, "serial_port_count": { "description": "Specifies the count of serial ports.", "minimum": 0, "title": "Serial Port Count", "type": "integer" } }, "protected": true, "resource_type_associations": [ { "created_at": "2016-06-28T14:57:10Z", "name": "OS::Glance::Image", "prefix": "hw_" }, { "created_at": "2016-06-28T14:57:10Z", "name": "OS::Nova::Flavor", "prefix": "hw:" } ], "schema": "/v2/schemas/metadefs/namespace", "self": "/v2/metadefs/namespaces/OS::Compute::Libvirt", "visibility": "public" } ``` -------------------------------- ### API Message Localization Example Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst Request API messages in a specific language by setting the 'Accept-Language' header. Ensure the corresponding language package is installed on the Glance server. ```bash curl -i -X GET -H 'Accept-Language: zh' -H 'Content-Type: application/json' http://glance.openstack.example.org/v2/images/aaa ``` -------------------------------- ### Build Release Notes HTML Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/release-notes.rst Execute this command to build the HTML version of the release notes. The generated files will be located in the 'releasenotes/build/html/' directory. ```bash $ tox -e releasenotes ``` -------------------------------- ### Get Namespace Response Example with Resource Type Filter Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md This JSON object shows the response when retrieving a namespace filtered by a specific resource type. Property names are prefixed according to the resource type association. ```json { "created_at": "2016-06-28T14:57:10Z", "description": "The libvirt compute driver options.", "display_name": "libvirt Driver Options", "namespace": "OS::Compute::Libvirt", "owner": "admin", "properties": { "hw_boot_menu": { "description": "If true, enables the BIOS bootmenu.", "enum": [ "true", "false" ], "title": "Boot Menu", "type": "string" }, "hw_serial_port_count": { "description": "Specifies the count of serial ports.", "minimum": 0, "title": "Serial Port Count", "type": "integer" } }, "protected": true, "resource_type_associations": [ { "created_at": "2016-06-28T14:57:10Z", "name": "OS::Glance::Image", "prefix": "hw_" }, { "created_at": "2016-06-28T14:57:10Z", "name": "OS::Nova::Flavor", "prefix": "hw:" } ], "schema": "/v2/schemas/metadefs/namespace", "self": "/v2/metadefs/namespaces/OS::Compute::Libvirt", "visibility": "public" } ``` -------------------------------- ### Configure Multiple S3 Stores in Glance Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst Example configuration for setting up two S3 stores, 's3-primary' and 's3-backup', in a fresh Glance deployment. ```ini [DEFAULT] # list of enabled stores identified by their property group name enabled_backends = s3-primary:s3, s3-backup:s3 # the default store, if not set glance-api service will not start [glance_store] default_backend = s3-primary # conf props for s3-primary store instance [s3-primary] s3_store_host = https://s3-us-east-1.amazonaws.com s3_store_access_key = primary-access-key s3_store_secret_key = primary-secret-key s3_store_bucket = glance-primary-bucket s3_store_create_bucket_on_put = True s3_store_bucket_url_format = virtual # etc.. # conf props for s3-backup store instance [s3-backup] s3_store_host = https://s3-us-west-2.amazonaws.com s3_store_access_key = backup-access-key s3_store_secret_key = backup-secret-key s3_store_bucket = glance-backup-bucket s3_store_create_bucket_on_put = True s3_store_bucket_url_format = virtual # etc.. ``` -------------------------------- ### Gateway Method Example Source: https://github.com/openstack/glance/blob/master/doc/source/contributor/domain_model.rst This function demonstrates how to create a layered object using proxy classes. It shows the dynamic assembly of a domain object based on specified requirements. ```python def gateway(logg, only_positive=True): base = Base() logger = LoggerProxy(base, logg) if only_positive: return ValidatorProxy(logger) return logger domain_object = gateway(sys.stdout, only_positive=True) ``` -------------------------------- ### Glance Configuration After Upgrade (Multiple Cinder Stores) Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst This example shows the Glance configuration after upgrading to support multiple Cinder stores, defining separate configurations for 'old' and 'new' backends. ```ini # new configuration in glance [DEFAULT] enabled_backends = old:cinder, new:cinder [glance_store] default_backend = new [new] rootwrap_config = /etc/glance/rootwrap.conf cinder_volume_type = glance-new description = LVM based cinder store cinder_catalog_info = volumev3::publicURL cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service # etc.. [old] rootwrap_config = /etc/glance/rootwrap.conf cinder_volume_type = glance-old # as per old cinder.conf description = NFS based cinder store cinder_catalog_info = volumev3::publicURL cinder_store_auth_address = http://localhost/identity/v3 cinder_store_user_name = glance cinder_store_password = admin cinder_store_project_name = service # etc.. ``` -------------------------------- ### Glance API v2 Metadefs Response Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md Example JSON response showing resource type associations. ```json { "resource_type_associations": [ { "created_at": "2018-03-05T18:20:44Z", "name": "OS::Nova::Flavor", "prefix": "hw:" }, { "created_at": "2018-03-05T18:20:44Z", "name": "OS::Glance::Image", "prefix": "hw_" } ] } ``` -------------------------------- ### Create a Task Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst Initiate a new asynchronous image-related task by sending a POST request to the /v2/tasks endpoint. The request body must include the task type and input parameters. ```bash POST /v2/tasks ``` -------------------------------- ### Populate Image Service Database Source: https://github.com/openstack/glance/blob/master/doc/source/install/install-debian.rst Synchronizes the Image service database schema. Run this command as the 'glance' user. ```console # su -s /bin/sh -c "glance-manage db_sync" glance ``` -------------------------------- ### Install Glance Package Source: https://github.com/openstack/glance/blob/master/doc/source/install/install-rdo.rst Installs the OpenStack Glance package using the dnf package manager. This is a prerequisite for configuring the Glance service. ```console # dnf install openstack-glance ``` -------------------------------- ### Load Configuration from a Directory Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst Use the --config-dir option to load all .conf fragments from a specified directory. This overrides --config-file and is useful when configuration is managed by a deployment framework. ```bash $ glance-api --config-dir=/etc/glance/glance-api.d ``` -------------------------------- ### Create an ISO Image with Glance Source: https://github.com/openstack/glance/blob/master/doc/source/admin/manage-images.rst Upload an ISO image to the Image service (glance) for later use with Compute. Ensure the file path and image format are correctly specified. ```console $ glance image-create --name ISO_IMAGE --file IMAGE.iso \ --disk-format iso --container-format bare ``` -------------------------------- ### List Shared Images GET Request Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst To view images shared with a specific project, issue a GET request to '/shared-images/'. ```http GET http://glance.openstack.example.org/v1/shared-images/project1 ``` -------------------------------- ### Build Glance API Reference Source: https://github.com/openstack/glance/blob/master/api-ref/source/versions/index.md Use tox to build the API reference from the Glance repository. The HTML output will be in the api-ref/build/html directory. ```bash tox -e api-ref ``` -------------------------------- ### Install python-openstackclient Source: https://github.com/openstack/glance/blob/master/doc/source/admin/troubleshooting.rst Install the python-openstackclient package using pip to obtain the 'openstack' command-line utility. This tool is essential for managing OpenStack resources. ```console # pip install python-openstackclient ``` -------------------------------- ### Delete Image Tag Request Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/index.md This example shows how to delete a specific tag from an image. The tag has a maximum length of 255 characters. ```http DELETE /v2/images/{image_id}/tags/{tag} HTTP/1.1 Host: example.com Content-Type: application/json Accept: application/json X-Auth-Token: ``` -------------------------------- ### Example Image Creation Timestamp Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/index.md An example of the ISO 8601 formatted date and time stamp for image creation, including a UTC offset. ```default 2015-08-27T09:49:58-05:00 ``` -------------------------------- ### Sync Glance Database Source: https://github.com/openstack/glance/blob/master/doc/source/admin/db-sqlalchemy-migrate.rst Use this command to place a database under migration control and upgrade it, creating it if it doesn't exist. Specify the target version and the current version. ```bash glance-manage db sync ``` -------------------------------- ### List Shared Images Response Example Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst This is an example of the JSON response when listing shared images, indicating image IDs and whether they can be further shared. ```json { "shared_images": [ {'image_id': '71c675ab-d94f-49cd-a114-e12490b328d9', 'can_share': false} ...] } ``` -------------------------------- ### Create Glance User and Service Entity Source: https://github.com/openstack/glance/blob/master/doc/source/install/install-debian.rst Create the 'glance' user with a password prompt and then create the 'glance' service entity for the Image service. ```console $ openstack user create --domain default --password-prompt glance User Password: Repeat User Password: +---------------------+ | Field | Value | +---------------------+ | domain_id | default | | enabled | True | | id | 3f4e777c4062483ab8d9edd7dff829df | | name | glance | | options | {} | | password_expires_at | None | +---------------------+ $ openstack role add --project service --user glance admin $ openstack service create --name glance \ --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 8c2c7f1b9b5049ea9e63757b5533e6d2 | | name | glance | | type | image | +-------------+----------------------------------+ ``` -------------------------------- ### Specify Configuration File via Command Line Source: https://github.com/openstack/glance/blob/master/doc/source/configuration/configuring.rst Use the --config-file option to explicitly provide the path to a configuration file. If not specified, Glance searches default locations. ```bash $ glance-api --config-file=/etc/glance/glance-api.conf ``` -------------------------------- ### Filtering Images Lists Source: https://github.com/openstack/glance/blob/master/doc/source/user/glanceapi.rst Details the query parameters available for filtering image lists returned by GET /v1/images and GET /v1/images/detail requests. ```APIDOC ## Filtering Images Lists Both the ``GET /v1/images`` and ``GET /v1/images/detail`` requests accept query parameters to filter the returned list of images. ### Query Parameters * **name** (string) - Filters images having a ``name`` attribute matching the provided value. * **container_format** (string) - Filters images having a ``container_format`` attribute matching the provided value. * **disk_format** (string) - Filters images having a ``disk_format`` attribute matching the provided value. * **status** (string) - Filters images having a ``status`` attribute matching the provided value. * **size_min** (integer) - Filters images having a ``size`` attribute greater than or equal to the provided value in bytes. * **size_max** (integer) - Filters images having a ``size`` attribute less than or equal to the provided value in bytes. * **sort_key** (string) - Results will be ordered by the specified image attribute. Accepted values depend on the specific API implementation. ``` -------------------------------- ### Update Tag Definition Request Example Source: https://github.com/openstack/glance/blob/master/api-ref/source/v2/metadefs-index.md Example of a request body to rename a tag definition. The 'name' field specifies the new name for the tag. ```json { "name": "new-tag-name" } ``` -------------------------------- ### Import Image API Call Source: https://github.com/openstack/glance/blob/master/doc/source/admin/interoperable-image-import.rst This is an example of an API call to import an image using the glance-direct method. It specifies the stores to import to and whether all stores must succeed. ```bash curl -i -X POST -H "X-Auth-Token: $token" -H "Content-Type: application/json" -d '{"method": {"name":"glance-direct"}, "stores": ["ceph1", "ceph2"], "all_stores_must_succeed": false}' $image_url/v2/images/{image_id}/import ```