Introduce resource_registry in the proxies

Instead of hardcoding resource types on various places (what is
especially problematic once different api versions support different
resources) it would be possible to rely on a regisitry describing which
resources are supported by the certain proxy pointing to the exact
object classes. This is going to be used in a series of changes
implementing search_XXX method accepting string "service.resource" and
the method figuring out which exact class should be used as well as it
a first step into auto-generation of ansible modules.

Change-Id: If4abc89e88b0843877517cf9eaf5648778b325b0
This commit is contained in:
Artem Goncharov 2022-11-04 15:32:48 +01:00
parent 57fbb72e32
commit 4421b87508
20 changed files with 254 additions and 0 deletions

View File

@ -30,6 +30,19 @@ class Proxy(proxy.Proxy):
retriable_status_codes = _common.RETRIABLE_STATUS_CODES
_resource_registry = {
"allocation": _allocation.Allocation,
"chassis": _chassis.Chassis,
"conductor": _conductor.Conductor,
"deploy_template": _deploytemplates.DeployTemplate,
"driver": _driver.Driver,
"node": _node.Node,
"port": _port.Port,
"port_group": _portgroup.PortGroup,
"volume_connector": _volumeconnector.VolumeConnector,
"volume_target": _volumetarget.VolumeTarget,
}
def _get_with_fields(self, resource_type, value, fields=None):
"""Fetch a bare metal resource.

View File

@ -21,6 +21,9 @@ _logger = _log.setup_logging('openstack')
class Proxy(proxy.Proxy):
_resource_registry = {
"introspection": _introspect.Introspection,
}
def introspections(self, **query):
"""Retrieve a generator of introspection records.

View File

@ -31,6 +31,22 @@ from openstack import resource
class Proxy(_base_proxy.BaseBlockStorageProxy):
_resource_registry = {
"availability_zone": availability_zone.AvailabilityZone,
"backup": _backup.Backup,
"capabilities": _capabilities.Capabilities,
"extension": _extension.Extension,
"group": _group.Group,
"group_snapshot": _group_snapshot.GroupSnapshot,
"group_type": _group_type,
"limits": _limits.Limit,
"quota_set": _quota_set.QuotaSet,
"resource_filter": _resource_filter.ResourceFilter,
"snapshot": _snapshot.Snapshot,
"stats_pools": _stats.Pools,
"type": _type.Type,
"volume": _volume.Volume
}
# ====== SNAPSHOTS ======
def get_snapshot(self, snapshot):

View File

@ -28,6 +28,21 @@ from openstack import resource
class Proxy(proxy.Proxy):
_resource_registry = {
"action": _action.Action,
"build_info": build_info.BuildInfo,
"cluster": _cluster.Cluster,
"cluster_attr": _cluster_attr.ClusterAttr,
"cluster_policy": _cluster_policy.ClusterPolicy,
"event": _event.Event,
"node": _node.Node,
"policy": _policy.Policy,
"policy_type": _policy_type.PolicyType,
"profile": _profile.Profile,
"profile_type": _profile_type.ProfileType,
"receiver": _receiver.Receiver,
"service": _service.Service,
}
def get_build_info(self):
"""Get build info for service engine and API

View File

@ -43,6 +43,29 @@ from openstack import utils
class Proxy(proxy.Proxy):
_resource_registry = {
"aggregate": _aggregate.Aggregate,
"availability_zone": availability_zone.AvailabilityZone,
"extension": extension.Extension,
"flavor": _flavor.Flavor,
"hypervisor": _hypervisor.Hypervisor,
"image": _image.Image,
"keypair": _keypair.Keypair,
"limits": limits.Limits,
"migration": _migration.Migration,
"quota_set": _quota_set.QuotaSet,
"server": _server.Server,
"server_action": _server_action.ServerAction,
"server_diagnostics": _server_diagnostics.ServerDiagnostics,
"server_group": _server_group.ServerGroup,
"server_interface": _server_interface.ServerInterface,
"server_ip": server_ip.ServerIP,
"server_migration": _server_migration.ServerMigration,
"server_remote_console": _src.ServerRemoteConsole,
"service": _service.Service,
"usage": _usage.Usage,
"volume_attachment": _volume_attachment.VolumeAttachment
}
# ========== Extensions ==========

View File

@ -18,6 +18,12 @@ from openstack import proxy
class Proxy(proxy.Proxy):
_resource_registry = {
"database": _database.Database,
"flavor": _flavor.Flavor,
"instance": _instance.Instance,
"user": _user.User,
}
def create_database(self, instance, **attrs):
"""Create a new database from attributes

View File

@ -20,6 +20,14 @@ from openstack import proxy
class Proxy(proxy.Proxy):
_resource_registry = {
"floating_ip": _fip.FloatingIP,
"recordset": _rs.Recordset,
"zone": _zone.Zone,
"zone_export": _zone_export.ZoneExport,
"zone_import": _zone_import.ZoneImport,
"zone_transfer_request": _zone_transfer.ZoneTransferRequest,
}
# ======== Zones ========
def zones(self, **query):

View File

@ -48,6 +48,40 @@ from openstack import utils
class Proxy(proxy.Proxy):
_resource_registry = {
"application_credential":
_application_credential.ApplicationCredential,
"credential": _credential.Credential,
"domain": _domain.Domain,
"endpoint": _endpoint.Endpoint,
"federation_protocol": _federation_protocol.FederationProtocol,
"group": _group.Group,
"identity_provider": _identity_provider.IdentityProvider,
"limit": _limit.Limit,
"mapping": _mapping.Mapping,
"policy": _policy.Policy,
"project": _project.Project,
"region": _region.Region,
"registered_limit": _registered_limit.RegisteredLimit,
"role": _role.Role,
"role_assignment": _role_assignment.RoleAssignment,
"role_domain_group_assignment":
_role_domain_group_assignment.RoleDomainGroupAssignment,
"role_domain_user_assignment":
_role_domain_user_assignment.RoleDomainUserAssignment,
"role_project_group_assignment":
_role_project_group_assignment.RoleProjectGroupAssignment,
"role_project_user_assignment":
_role_project_user_assignment.RoleProjectUserAssignment,
"role_system_group_assignment":
_role_system_group_assignment.RoleSystemGroupAssignment,
"role_system_user_assignment":
_role_system_user_assignment.RoleSystemUserAssignment,
"service": _service.Service,
"system": _system.System,
"trust": _trust.Trust,
"user": _user.User,
}
def create_credential(self, **attrs):
"""Create a new credential from attributes

View File

@ -32,6 +32,15 @@ _RAW_PROPERTIES = ('is_protected', 'tags')
class Proxy(_base_proxy.BaseImageProxy):
_resource_registry = {
"image": _image.Image,
"image_member": _member.Member,
"metadef_namespace": _metadef_namespace.MetadefNamespace,
"schema": _schema.Schema,
"info_import": _si.Import,
"info_store": _si.Store,
"task": _task.Task
}
# ====== IMAGES ======
def _create_image(self, **kwargs):

View File

@ -26,6 +26,12 @@ class Proxy(proxy.Proxy):
Create method for each action of each API.
"""
_resource_registry = {
"host": _host.Host,
"notification": _notification.Notification,
"segment": _segment.Segment,
}
def notifications(self, **query):
"""Return a generator of notifications.

View File

@ -17,6 +17,11 @@ from openstack import proxy
class Proxy(proxy.Proxy):
_resource_registry = {
"container": _container.Container,
"order": _order.Order,
"secret": _secret.Secret,
}
def create_container(self, **attrs):
"""Create a new container from attributes

View File

@ -30,6 +30,22 @@ from openstack import resource
class Proxy(proxy.Proxy):
_resource_registry = {
"amphora": _amphora.Amphora,
"availability_zone": _availability_zone.AvailabilityZone,
"availability_zone_profile":
_availability_zone_profile.AvailabilityZoneProfile,
"flavor": _flavor.Flavor,
"flavor_profile": _flavor_profile.FlavorProfile,
"health_monitor": _hm.HealthMonitor,
"l7_policy": _l7policy.L7Policy,
"l7_rule": _l7rule.L7Rule,
"load_balancer": _lb.LoadBalancer,
"member": _member.Member,
"pool": _pool.Pool,
"provider": _provider.Provider,
"quota": _quota.Quota
}
def create_load_balancer(self, **attrs):
"""Create a new load balancer from attributes

View File

@ -19,6 +19,12 @@ from openstack import resource
class Proxy(proxy.Proxy):
_resource_registry = {
"claim": _claim.Claim,
"message": _message.Message,
"queue": _queue.Queue,
"subscription": _subscription.Subscription,
}
def create_queue(self, **attrs):
"""Create a new queue from attributes

View File

@ -71,6 +71,63 @@ from openstack import proxy
class Proxy(proxy.Proxy):
_resource_registry = {
"address_group": _address_group.AddressGroup,
"address_scope": _address_scope.AddressScope,
"agent": _agent.Agent,
"auto_allocated_topology":
_auto_allocated_topology.AutoAllocatedTopology,
"availability_zone": availability_zone.AvailabilityZone,
"extension": extension.Extension,
"firewall_group": _firewall_group.FirewallGroup,
"firewall_policy": _firewall_policy.FirewallPolicy,
"firewall_rule": _firewall_rule.FirewallRule,
"flavor": _flavor.Flavor,
"floating_ip": _floating_ip.FloatingIP,
"health_monitor": _health_monitor.HealthMonitor,
"l3_conntrack_helper": _l3_conntrack_helper.ConntrackHelper,
"listener": _listener.Listener,
"load_balancer": _load_balancer.LoadBalancer,
"local_ip": _local_ip.LocalIP,
"local_ip_association": _local_ip_association.LocalIPAssociation,
"metering_label": _metering_label.MeteringLabel,
"metering_label_rule": _metering_label_rule.MeteringLabelRule,
"ndp_proxy": _ndp_proxy.NDPProxy,
"network": _network.Network,
"network_ip_availability":
network_ip_availability.NetworkIPAvailability,
"network_segment_range": _network_segment_range.NetworkSegmentRange,
"pool": _pool.Pool,
"pool_member": _pool_member.PoolMember,
"port": _port.Port,
"port_forwarding": _port_forwarding.PortForwarding,
"qos_bandwidth_limit_rule":
_qos_bandwidth_limit_rule.QoSBandwidthLimitRule,
"qos_dscp_marking_rule": _qos_dscp_marking_rule.QoSDSCPMarkingRule,
"qos_minimum_bandwidth_rule":
_qos_minimum_bandwidth_rule.QoSMinimumBandwidthRule,
"qos_minimum_packet_rate_rule":
_qos_minimum_packet_rate_rule.QoSMinimumPacketRateRule,
"qos_policy": _qos_policy.QoSPolicy,
"qos_rule_type": _qos_rule_type.QoSRuleType,
"quota": _quota.Quota,
"rbac_policy": _rbac_policy.RBACPolicy,
"router": _router.Router,
"security_group": _security_group.SecurityGroup,
"security_group_rule": _security_group_rule.SecurityGroupRule,
"segment": _segment.Segment,
"service_profile": _service_profile.ServiceProfile,
"service_provider": _service_provider.ServiceProvider,
"subnet": _subnet.Subnet,
"subnet_pool": _subnet_pool.SubnetPool,
"trunk": _trunk.Trunk,
"vpn_endpoint_group": _vpn_endpoint_group.VpnEndpointGroup,
"vpn_ike_policy": _ike_policy.VpnIkePolicy,
"vpn_ipsec_policy": _ipsec_policy.VpnIpsecPolicy,
"vpn_ipsec_site_connection":
_ipsec_site_connection.VpnIPSecSiteConnection,
"vpn_service": _vpn_service.VpnService,
}
@proxy._check_resource(strict=False)
def _update(self, resource_type, value, base_path=None,

View File

@ -36,6 +36,12 @@ SHORT_EXPIRES_ISO8601_FORMAT = '%Y-%m-%d'
class Proxy(proxy.Proxy):
_resource_registry = {
"account": _account.Account,
"container": _container.Container,
"info": _info.Info,
"object": _obj.Object
}
skip_discovery = True

View File

@ -25,6 +25,15 @@ from openstack import resource
class Proxy(proxy.Proxy):
_resource_registry = {
"resource": _resource.Resource,
"software_config": _sc.SoftwareConfig,
"software_deployment": _sd.SoftwareDeployment,
"stack": _stack.Stack,
"stack_environment": _stack_environment.StackEnvironment,
"stack_files": _stack_files.StackFiles,
"stack_template": _stack_template.StackTemplate,
}
def _extract_name_consume_url_parts(self, url_parts):
if (len(url_parts) == 3 and url_parts[0] == 'software_deployments'

View File

@ -16,6 +16,10 @@ from openstack import proxy
class Proxy(proxy.Proxy):
_resource_registry = {
"resource_class": _resource_class.ResourceClass,
"resource_provider": _resource_provider.ResourceProvider,
}
# resource classes

View File

@ -77,6 +77,12 @@ class Proxy(adapter.Adapter):
``<service-type>_status_code_retries``.
"""
_resource_registry = dict()
"""Registry of the supported resourses.
Dictionary of resource names (key) types (value).
"""
def __init__(
self,
session,

View File

@ -28,6 +28,14 @@ from openstack.shared_file_system.v2 import share as _share
class Proxy(proxy.Proxy):
_resource_registry = {
"availability_zone": _availability_zone.AvailabilityZone,
"share_snapshot": _share_snapshot.ShareSnapshot,
"storage_pool": _storage_pool.StoragePool,
"user_message": _user_message.UserMessage,
"limit": _limit.Limit,
"share": _share.Share,
}
def availability_zones(self):
"""Retrieve shared file system availability zones

View File

@ -16,6 +16,10 @@ from openstack.workflow.v2 import workflow as _workflow
class Proxy(proxy.Proxy):
_resource_registry = {
"execution": _execution.Execution,
"workflow": _workflow.Workflow,
}
def create_workflow(self, **attrs):
"""Create a new workflow from attributes