diff --git a/codegenerator/common/__init__.py b/codegenerator/common/__init__.py index 3412caa..c58817a 100644 --- a/codegenerator/common/__init__.py +++ b/codegenerator/common/__init__.py @@ -446,6 +446,7 @@ def get_resource_names_from_url(path: str): el[-1] == "s" and el[-3:] != "dns" and el[-6:] != "access" + and el[-6:] != "status" and el != "qos" # quota/details and el != "details" @@ -456,20 +457,21 @@ def get_resource_names_from_url(path: str): if part.startswith("os_"): # We should remove `os_` prefix from resource name part = part[3:] + if part == "availabilityzone": + part = "availability_zone" + elif part == "availabilityzoneprofile": + part = "availability_zone_profile" + elif part == "flavorprofile": + part = "flavor_profile" path_resource_names.append(part) if len(path_resource_names) > 1 and ( path_resource_names[-1] - in [ - "action", - "detail", - ] + in ["action", "detail", "stat", "status", "failover", "config"] or "add" in path_resource_names[-1] or "remove" in path_resource_names[-1] or "update" in path_resource_names[-1] ): path_resource_names.pop() - if len(path_resource_names) == 0: - return ["version"] if path.startswith("/v2/schemas/"): # Image schemas should not be singularized (schema/images, # schema/image) @@ -482,6 +484,12 @@ def get_resource_names_from_url(path: str): path_resource_names = ["volume_transfer"] if path == "/v2.0/ports/{port_id}/bindings/{id}/activate": path_resource_names = ["port", "binding"] + if path.startswith("/v2/lbaas"): + path_resource_names.remove("lbaa") + if path.startswith("/v2/octavia/amphorae"): + path_resource_names.remove("octavia") + if len(path_resource_names) == 0: + return ["version"] return path_resource_names @@ -522,6 +530,8 @@ def get_rust_service_type_from_str(xtype: str): return "Network" case "object-store": return "ObjectStore" + case "load-balancer": + return "LoadBalancer" case _: return xtype diff --git a/codegenerator/metadata.py b/codegenerator/metadata.py index ba661f2..33307f8 100644 --- a/codegenerator/metadata.py +++ b/codegenerator/metadata.py @@ -194,6 +194,13 @@ class MetadataGenerator(BaseGenerator): and method == "get" ): operation_key = "list" + elif ( + args.service_type == "load-balancer" + and len(path_elements) > 1 + and path_elements[-1] + in ["stats", "status", "failover", "config"] + ): + operation_key = path_elements[-1] elif response_schema and ( method == "get" @@ -550,7 +557,7 @@ class MetadataGenerator(BaseGenerator): def get_operation_type_by_key(operation_key): if operation_key in ["list", "list_detailed"]: return "list" - elif operation_key == "get": + elif operation_key in ["get", "stats", "status"]: return "get" elif operation_key == "check": return "get" diff --git a/codegenerator/openapi/base.py b/codegenerator/openapi/base.py index 1a6d65f..bdaafea 100644 --- a/codegenerator/openapi/base.py +++ b/codegenerator/openapi/base.py @@ -1209,9 +1209,9 @@ def _convert_wsme_to_jsonschema(body_spec): elif wtypes.isdict(body_spec): res = { "type": "object", - "additionalProperties": { - "type": _convert_wsme_to_jsonschema(body_spec.value_type) - }, + "additionalProperties": _convert_wsme_to_jsonschema( + body_spec.value_type + ), } elif wtypes.isusertype(body_spec): basetype = body_spec.basetype diff --git a/codegenerator/openapi/octavia.py b/codegenerator/openapi/octavia.py index 01e99d7..b7f711f 100644 --- a/codegenerator/openapi/octavia.py +++ b/codegenerator/openapi/octavia.py @@ -148,7 +148,7 @@ class OctaviaGenerator(OpenStackServerSourceBase): proc.start() proc.join() if proc.exitcode != 0: - raise RuntimeError("Error generating Octavia OpenAPI schma") + raise RuntimeError("Error generating Octavia OpenAPI schema") def _generate(self, target_dir, args): from octavia.api import root_controller @@ -172,7 +172,7 @@ class OctaviaGenerator(OpenStackServerSourceBase): impl_path = Path( work_dir, "openapi_specs", - "load-balancing", + "load-balancer", f"v{self.api_version}.yaml", ) impl_path.parent.mkdir(parents=True, exist_ok=True) @@ -360,13 +360,13 @@ class OctaviaGenerator(OpenStackServerSourceBase): action="status", conditions={"method": ["GET"]}, ) - mapper.connect( - None, - "/v2/lbaas/loadbalancers/{loadbalancer_id}/statuses", - controller=load_balancer.StatusController.get, - action="status", - conditions={"method": ["GET"]}, - ) + # mapper.connect( + # None, + # "/v2/lbaas/loadbalancers/{loadbalancer_id}/statuses", + # controller=load_balancer.StatusController.get, + # action="status", + # conditions={"method": ["GET"]}, + # ) mapper.connect( None, "/v2/lbaas/loadbalancers/{loadbalancer_id}/failover", diff --git a/codegenerator/openapi_spec.py b/codegenerator/openapi_spec.py index ce4db04..c01ad6a 100644 --- a/codegenerator/openapi_spec.py +++ b/codegenerator/openapi_spec.py @@ -79,7 +79,7 @@ class OpenApiSchemaGenerator(BaseGenerator): self.generate_glance(target_dir, args) elif args.service_type == "identity": self.generate_keystone(target_dir, args) - elif args.service_type == "load-balancing": + elif args.service_type == "load-balancer": self.generate_octavia(target_dir, args) elif args.service_type == "network": self.generate_neutron(target_dir, args) diff --git a/tools/generate_openapi_specs.sh b/tools/generate_openapi_specs.sh index 4d31d73..778327a 100755 --- a/tools/generate_openapi_specs.sh +++ b/tools/generate_openapi_specs.sh @@ -15,14 +15,16 @@ if [ -z "$1" -o "$1" = "block-storage" ]; then openstack-codegenerator --work-dir wrk --target openapi-spec --service-type volume --api-ref-src ${API_REF_BUILD_ROOT}/cinder/api-ref/build/html/v3/index.html fi if [ -z "$1" -o "$1" = "image" ]; then - openstack-codegenerator --work-dir wrk --target openapi-spec --service-type image --api-ref-src ${API_REF_BUILD_ROOT}/glance/api-ref/build/html/v2/index.html + openstack-codegenerator --work-dir wrk --target openapi-spec --service-type image --api-ref-src ${API_REF_BUILD_ROOT}/glance/api-ref/build/html/v2/index.html --api-ref-src ${API_REF_BUILD_ROOT}/glance/api-ref/build/html/v2/metadefs-index.html + sed -i "s|\[API versions call\](../versions/index.html#versions-call)|API versions call|g" wrk/openapi_specs/image/v2.yaml fi if [ -z "$1" -o "$1" = "identity" ]; then - openstack-codegenerator --work-dir wrk --target openapi-spec --service-type identity --api-ref-src ${API_REF_BUILD_ROOT}/keystone/api-ref/build/html/v3/index.html + openstack-codegenerator --work-dir wrk --target openapi-spec --service-type identity --api-ref-src ${API_REF_BUILD_ROOT}/keystone/api-ref/build/html/v3/index.html --api-ref-src ${API_REF_BUILD_ROOT}/keystone/api-ref/build/html/v3-ext/index.html + fi -if [ -z "$1" -o "$1" = "load-balancing" ]; then - openstack-codegenerator --work-dir wrk --target openapi-spec --service-type load-balancing --api-ref-src ${API_REF_BUILD_ROOT}/octavia/api-ref/build/html/v2/index.html +if [ -z "$1" -o "$1" = "load-balancer" ]; then + openstack-codegenerator --work-dir wrk --target openapi-spec --service-type load-balancer --api-ref-src ${API_REF_BUILD_ROOT}/octavia/api-ref/build/html/v2/index.html --validate fi if [ -z "$1" -o "$1" = "placement" ]; then openstack-codegenerator --work-dir wrk --target openapi-spec --service-type placement --api-ref-src ${API_REF_BUILD_ROOT}/placement/api-ref/build/html/index.html diff --git a/tools/generate_rust.sh b/tools/generate_rust.sh index acfdff3..619e590 100755 --- a/tools/generate_rust.sh +++ b/tools/generate_rust.sh @@ -5,9 +5,11 @@ openstack-codegenerator --work-dir metadata --target metadata --openapi-yaml-spe openstack-codegenerator --work-dir metadata --target metadata --openapi-yaml-spec wrk/openapi_specs/identity/v3.yaml --service-type identity openstack-codegenerator --work-dir metadata --target metadata --openapi-yaml-spec wrk/openapi_specs/image/v2.yaml --service-type image openstack-codegenerator --work-dir metadata --target metadata --openapi-yaml-spec wrk/openapi_specs/network/v2.yaml --service-type network +openstack-codegenerator --work-dir metadata --target metadata --openapi-yaml-spec wrk/openapi_specs/load-balancer/v2.yaml --service-type load-balancer tools/generate_rust_block_storage.sh tools/generate_rust_compute.sh tools/generate_rust_identity.sh tools/generate_rust_image.sh tools/generate_rust_network.sh +tools/generate_rust_load_balancer.sh diff --git a/tools/generate_rust_load_balancer.sh b/tools/generate_rust_load_balancer.sh new file mode 100755 index 0000000..3548699 --- /dev/null +++ b/tools/generate_rust_load_balancer.sh @@ -0,0 +1,32 @@ +#!/usr/bin/bash -e +# + +WRK_DIR=wrk +METADATA=metadata +DST=~/workspace/github/gtema/openstack +NET_RESOURCES=( + "amphorae" + "availability_zone" + "availability_zone_profile" + "flavor" + "flavor_profile" + "healthmonitor" + "l7policy" + "listener" + "loadbalancer" + "pool" + "provider" + "quota" + "version" +) + +openstack-codegenerator --work-dir ${WRK_DIR} --target rust-sdk --metadata ${METADATA}/load-balancer_metadata.yaml --service load-balancer +openstack-codegenerator --work-dir ${WRK_DIR} --target rust-cli --metadata ${METADATA}/load-balancer_metadata.yaml --service load-balancer + + +for resource in "${NET_RESOURCES[@]}"; do + cp -av "${WRK_DIR}/rust/openstack_sdk/src/api/load_balancer/v2/${resource}" ${DST}/openstack_sdk/src/api/load_balancer/v2 + cp -av "${WRK_DIR}/rust/openstack_sdk/src/api/load_balancer/v2/${resource}.rs" ${DST}/openstack_sdk/src/api/load_balancer/v2 + cp -av "${WRK_DIR}/rust/openstack_cli/src/load_balancer/v2/${resource}" ${DST}/openstack_cli/src/load_balancer/v2 + cp -av "${WRK_DIR}/rust/openstack_cli/tests/load_balancer/v2/${resource}" ${DST}/openstack_cli/tests/load_balancer/v2 +done; diff --git a/zuul.d/openapi.yaml b/zuul.d/openapi.yaml index fc51ee1..2a53824 100644 --- a/zuul.d/openapi.yaml +++ b/zuul.d/openapi.yaml @@ -15,7 +15,7 @@ - compute - identity - image - - load-balancing + - load-balancer - network - placement required-projects: @@ -158,7 +158,7 @@ - name: openstack/octavia vars: - openapi_service: load-balancing + openapi_service: load-balancer install_additional_projects: - project: "opendev.org/openstack/octavia" name: "."