How openstack/glance works
Main Components
• API Layer:
• Glance API service. Note the separation between v1 and v2 (found under glance/api/v1 and glance/api/v2) as well as the middleware (in glance/api/middleware) that processes requests (e.g., caching, gzip, context extraction, and version negotiation).
• WSGI interface (in glance/common/wsgi and glance/wsgi/api) and configuration files (such as those in the “httpd” directory and etc/glance-api-paste.ini).
• Business Logic and Domain:
• This encompasses the “glance/common”, “glance/domain”, and “glance/api” directories where core processing, property protections, policies (see glance/policies), and client helper functions exist.
• Database Layer:
• Database interaction implemented via SQLAlchemy within the “glance/db” directory.
• Migration and metadata management components (e.g., alembic_migrations in glance/db/sqlalchemy/alembic_migrations) that show how the project handles schema evolutions.
• Caching and Image Store:
• Cover the “glance/image_cache” directory which contains drivers (e.g., centralized_db, sqlite, xattr) and logic for managing image caching to speed up delivery.
• Asynchronous Processing:
• Asynchronous flows located in the “glance/async_” module. These manage tasks like image import, conversion, and processing using internal plugins and flows.
• Configuration/Policies & External Integration:
• Configuration layer (found across config files in etc/, glance/opts.py, and the oslo-config-generator in etc/oslo-config-generator) and policy definitions (in glance/policies).
• Also, it’s good to indicate external integrations with other OpenStack services (such as Keystone authentication and Nova) even though they may be referenced indirectly via the project’s client libraries and API endpoints.
Relationships and Data Flow
• Processed requests are handled by the business logic that invokes database operations in the “glance/db/*” components.
• Caching components interact with both the API server and the database/stores, ensuring fast access to popular images.
• Configuration and policy components govern rules for request authorization, image properties, and store selection.
Architectural Patterns and Design Principles
• Modular Design – clear separation of concerns between API handling, business logic, database management, caching, and asynchronous workflows.
• Middleware Chains – demonstrated by the numerous WSGI middleware components that enhance, secure, and modify HTTP flows.
• Layered Architecture – separation between the API layer (presentation), business logic (controller/service), and persistence (data access).
• Use of Plug-ins – asynchronous image processing is implemented using configurable and extensible plugins found in the “glance/async_/flows/plugins” directory.
• Dependency Injection and Configuration Driven – plenty of configuration files (in etc/ and oslo-config-generator) indicate the system is designed to be highly configurable.