Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
feat(network): add address_{group_scope} schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
gtema committed Mar 23, 2024
1 parent f776092 commit 534bcd7
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 33 deletions.
6 changes: 6 additions & 0 deletions codegenerator/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,12 @@ def post_process_network_operation(
"rust-cli"
].cli_full_command.replace("extraroutes", "extraroute")

if resource_name == "address_group":
if "addresses" in operation_name:
operation.targets["rust-cli"].cli_full_command = operation.targets[
"rust-cli"
].cli_full_command.replace("addresses", "address")

if "/tag" in resource_name:
if operation_name == "update":
operation.targets["rust-cli"].cli_full_command = operation.targets[
Expand Down
16 changes: 13 additions & 3 deletions codegenerator/openapi/neutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

class NeutronGenerator(OpenStackServerSourceBase):
URL_TAG_MAP = {
"/agents/{agent_id}/l3-routers": "l3-agent-scheduler",
"/agents/{agent_id}/dhcp-networks": "dhcp-agent-scheduler",
"/agents": "networking-agents",
"/ports/{port_id}/bindings": "port-bindings",
Expand Down Expand Up @@ -845,12 +846,22 @@ def _get_schema_ref(
# PUT tag does not have request body
return None

# ...
elif name in [
# L3 routers
"RoutersL3_AgentsIndexResponse",
"AgentsL3_RouterShowResponse",
"AgentsL3_RouterUpdateRequest",
"AgentsL3_RouterUpdateResponse",
"RoutersL3_AgentShowResponse",
"RoutersL3_AgentUpdateRequest",
"RoutersL3_AgentUpdateResponse"
"RoutersL3_AgentsCreateRequest",
"RoutersL3_AgentsCreateResponse",
]:
return None
# ...
elif name in [
# L3 routers
"RoutersL3_AgentsIndexResponse",
"RoutersL3_AgentShowResponse",
"RoutersL3_AgentUpdateRequest",
"RoutersL3_AgentUpdateResponse"
Expand Down Expand Up @@ -1094,7 +1105,6 @@ def get_schema(param_data):
"type": "array",
"items": {
"type": "string",
"format": "uuid",
},
}
elif "type:service_plugin_type" in validate:
Expand Down
229 changes: 201 additions & 28 deletions codegenerator/openapi/neutron_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@
},
}

EXTERNAL_GATEWAY_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"enable_snat": {
"type": "boolean",
},
"external_fixed_ips": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ip_address": {
"type": "string",
"oneOf": [
{"format": "ipv4"},
{"format": "ipv6"},
],
},
"subnet_id": {
"type": "string",
"format": "uuid",
},
},
},
},
"network_id": {"type": "string", "format": "uuid"},
},
}

ROUTER_ADD_EXTERNAL_GATEWAYS_REQUEST_SCHEMA: dict[str, Any] = {
"description": "Request body",
"type": "object",
Expand All @@ -313,34 +342,7 @@
"external_gateways": {
"type": "array",
"description": "The list of external gateways of the router.",
"items": {
"type": "object",
"properties": {
"enable_snat": {
"type": "boolean",
},
"external_fixed_ips": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ip_address": {
"type": "string",
"oneOf": [
{"format": "ipv4"},
{"format": "ipv6"},
],
},
"subnet_id": {
"type": "string",
"format": "uuid",
},
},
},
},
"network_id": {"type": "string", "format": "uuid"},
},
},
"items": EXTERNAL_GATEWAY_SCHEMA
},
},
}
Expand All @@ -360,6 +362,123 @@
"properties"
]["external_gateways"]["items"]["properties"].pop("enable_snat")

ADDRESS_GROUP_ADDRESS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"address_group": {
"type": "object",
"properties": {
"addresses": {
"type": "array",
"description": "A list of IP addresses.",
"items": {
"type": "string",
},
}
},
}
},
}

L3_ROUTER_AGENT_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"admin_state_up": {
"type": "boolean",
"description": "The administrative state of the resource, which is up (true) or down (false)."
},
"availability_zone_hints": {
"type": "array",
"description": "The availability zone candidates for the router. It is available when router_availability_zone extension is enabled.",
"items": {"type": "string"}
},
"availability_zones": {
"type": "array",
"description": "The availability zone(s) for the router. It is available when router_availability_zone extension is enabled.",
"items": {"type": "string"}
},
"description": {
"type": "string",
"description": "A human-readable description for the resource."
},
"distributed": {
"type": "boolean",
"description": "true indicates a distributed router. It is available when dvr extension is enabled."
},
"external_gateway_info": {
"description": "The external gateway information of the router. If the router has an external gateway, this would be a dict with network_id, enable_snat, external_fixed_ips, qos_policy_id, enable_default_route_ecmp and enable_default_route_bfd. Otherwise, this would be null.",
**EXTERNAL_GATEWAY_SCHEMA
},
"flavor_id": {
"type": "string",
"format": "uuid",
"description": "The ID of the flavor associated with the router."
},
"ha": {
"type": "boolean",
"description": "true indicates a highly-available router. It is available when l3-ha extension is enabled."
},
"id": {
"type": "string",
"format": "uuid",
"description": "The ID of the router."
},
"name": {
"type": "string",
"description": "Human-readable name of the resource."
},
"revision_number": {
"type": "integer",
"description": "The revision number of the resource."
},
"routes": {
"type": "array",
"description": "The extra routes configuration for L3 router. A list of dictionaries with destination and nexthop parameters. It is available when extraroute extension is enabled.",
"items": {
"type": "object",
"properties": {
"destination": {
"type": "string"
},
"next_hop": {
"type": "string"
}
}
}
},
"status": {
"type": "string",
"description": "The router status."
},
"project_id": {
"type": "string",
"format": "uuid",
"description": "The ID of the project."
},
"tenant_id": {
"type": "string",
"format": "uuid",
"description": "The ID of the project."
},
"service_type_id": {
"type": "string",
"format": "uuid",
"description": "The ID of the service type associated with the router."
},
}
}

L3_ROUTER_AGENTS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"routers": {
"type": "array",
"description": "A list of router objects.",
"items": L3_ROUTER_AGENT_SCHEMA
}
}
}


def _get_schema_ref(
openapi_spec,
Expand Down Expand Up @@ -431,6 +550,60 @@ def _get_schema_ref(
**ROUTER_UPDATE_EXTRAROUTES_REQUEST_SCHEMA
)
ref = "#/components/schemas/RouterShowResponse"
elif name in [
"Address_GroupsAdd_AddressesAdd_AddressesRequest",
"Address_GroupsRemove_AddressesRemove_AddressesRequest",
]:
openapi_spec.components.schemas[name] = TypeSchema(
**ADDRESS_GROUP_ADDRESS_SCHEMA
)
ref = f"#/components/schemas/{name}"
elif name in [
"Address_GroupsAdd_AddressesAdd_AddressesResponse",
"Address_GroupsRemove_AddressesRemove_AddressesResponse",
]:
ref = "#/components/schemas/Address_GroupShowResponse"

elif name == "AgentsL3_RoutersIndexResponse":
openapi_spec.components.schemas[name] = TypeSchema(
**L3_ROUTER_AGENTS_SCHEMA
)
ref = f"#/components/schemas/{name}"
elif name == "AgentsL3_RoutersIndexResponse":
openapi_spec.components.schemas[name] = TypeSchema(
**L3_ROUTER_AGENTS_SCHEMA
)
ref = f"#/components/schemas/{name}"
elif name == "AgentsL3_RoutersCreateRequest":
openapi_spec.components.schemas[name] = TypeSchema(
**{
"type": "object",
"properties": {
"router_id": {
"type": "string",
"format": "uuid",
"description": "The ID of the router."
}
}
}
)
ref = f"#/components/schemas/{name}"
elif name == "PortsBindingsActivateActivateRequest":
openapi_spec.components.schemas[name] = TypeSchema(
**{
"type": "object",
"properties": {
"host": {
"type": "string",
"description": "The hostname of the system the agent is running on."
}
}
}
)
ref = f"#/components/schemas/{name}"
elif name == "PortsBindingsActivateActivateResponse":
ref = "#/components/schemas/PortsBindingShowResponse"

else:
return (None, None, False)

Expand Down
4 changes: 2 additions & 2 deletions metadata/network_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resources:
module_name: add_addresses
sdk_mod_name: add_addresses
find_implemented_by_sdk: true
cli_full_command: address-group add-addresses
cli_full_command: address-group add-address
remove_addresses:
operation_id: address-groups/id/remove_addresses:put
operation_type: action
Expand All @@ -68,7 +68,7 @@ resources:
module_name: remove_addresses
sdk_mod_name: remove_addresses
find_implemented_by_sdk: true
cli_full_command: address-group remove-addresses
cli_full_command: address-group remove-address
show:
operation_id: address-groups/id:get
operation_type: show
Expand Down
2 changes: 2 additions & 0 deletions tools/generate_rust_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ WRK_DIR=wrk
METADATA=metadata
DST=~/workspace/github/gtema/openstack
NET_RESOURCES=(
"address_group"
"address_scope"
"availability_zone"
"extension"
"floatingip"
Expand Down

0 comments on commit 534bcd7

Please sign in to comment.