From fb2dc58d91bd93ba3aaa63d46e49e6609c18d46f Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 22 Nov 2021 13:37:39 -0600 Subject: graphql: T3993: normalize naming conventions --- src/services/api/graphql/README.graphql | 20 ++++++++++++-------- src/services/api/graphql/graphql/mutations.py | 10 +++++----- .../api/graphql/graphql/schema/config_file.graphql | 16 ++++++++-------- .../api/graphql/graphql/schema/dhcp_server.graphql | 8 ++++---- .../graphql/schema/interface_ethernet.graphql | 8 ++++---- .../api/graphql/graphql/schema/schema.graphql | 8 ++++---- .../api/graphql/recipes/create_dhcp_server.py | 13 +++++++++++++ .../api/graphql/recipes/create_interface_ethernet.py | 13 +++++++++++++ src/services/api/graphql/recipes/dhcp_server.py | 13 ------------- .../api/graphql/recipes/interface_ethernet.py | 13 ------------- .../recipes/templates/create_dhcp_server.tmpl | 9 +++++++++ .../recipes/templates/create_interface_ethernet.tmpl | 5 +++++ .../api/graphql/recipes/templates/dhcp_server.tmpl | 9 --------- .../recipes/templates/interface_ethernet.tmpl | 5 ----- 14 files changed, 77 insertions(+), 73 deletions(-) create mode 100644 src/services/api/graphql/recipes/create_dhcp_server.py create mode 100644 src/services/api/graphql/recipes/create_interface_ethernet.py delete mode 100644 src/services/api/graphql/recipes/dhcp_server.py delete mode 100644 src/services/api/graphql/recipes/interface_ethernet.py create mode 100644 src/services/api/graphql/recipes/templates/create_dhcp_server.tmpl create mode 100644 src/services/api/graphql/recipes/templates/create_interface_ethernet.tmpl delete mode 100644 src/services/api/graphql/recipes/templates/dhcp_server.tmpl delete mode 100644 src/services/api/graphql/recipes/templates/interface_ethernet.tmpl (limited to 'src/services') diff --git a/src/services/api/graphql/README.graphql b/src/services/api/graphql/README.graphql index a387f3276..6e9e16c6b 100644 --- a/src/services/api/graphql/README.graphql +++ b/src/services/api/graphql/README.graphql @@ -10,7 +10,7 @@ to run with that address as default router by requesting these 'mutations' in the GraphQL playground: mutation { - createInterfaceEthernet (data: {interface: "eth1", + CreateInterfaceEthernet (data: {interface: "eth1", address: "192.168.0.1/24", description: "BOB"}) { success @@ -22,7 +22,7 @@ mutation { } mutation { - createDhcpServer(data: {sharedNetworkName: "BOB", + CreateDhcpServer(data: {sharedNetworkName: "BOB", subnet: "192.168.0.0/24", defaultRouter: "192.168.0.1", nameServer: "192.168.0.1", @@ -45,7 +45,7 @@ mutation { To save the configuration, use the following mutation: mutation { - saveConfigFile(data: {fileName: "/config/config.boot"}) { + SaveConfigFile(data: {fileName: "/config/config.boot"}) { success errors data { @@ -64,7 +64,7 @@ https://hostname/graphql), one can load an arbitrary config file from a path. mutation { - loadConfigFile(data: {fileName: "/home/vyos/config.boot"}) { + LoadConfigFile(data: {fileName: "/home/vyos/config.boot"}) { success errors data { @@ -89,22 +89,26 @@ What's here: services ├── api │   └── graphql +│   ├── bindings.py │   ├── graphql │   │   ├── directives.py │   │   ├── __init__.py │   │   ├── mutations.py │   │   └── schema +│   │   ├── config_file.graphql │   │   ├── dhcp_server.graphql │   │   ├── interface_ethernet.graphql │   │   └── schema.graphql +│   ├── README.graphql │   ├── recipes -│   │   ├── dhcp_server.py +│   │   ├── config_file.py +│   │   ├── create_dhcp_server.py +│   │   ├── create_interface_ethernet.py │   │   ├── __init__.py -│   │   ├── interface_ethernet.py │   │   ├── recipe.py │   │   └── templates -│   │   ├── dhcp_server.tmpl -│   │   └── interface_ethernet.tmpl +│   │   ├── create_dhcp_server.tmpl +│   │   └── create_interface_ethernet.tmpl │   └── state.py ├── vyos-configd ├── vyos-hostsd diff --git a/src/services/api/graphql/graphql/mutations.py b/src/services/api/graphql/graphql/mutations.py index 8c613b9ca..02d5be0ef 100644 --- a/src/services/api/graphql/graphql/mutations.py +++ b/src/services/api/graphql/graphql/mutations.py @@ -21,9 +21,9 @@ def make_configure_resolver(mutation_name): :raise Exception: encapsulating ConfigErrors, or internal errors """ - class_name = mutation_name.replace('create', '', 1).replace('delete', '', 1) + class_name = mutation_name func_base_name = convert_camel_case_to_snake(class_name) - resolver_name = f'resolve_create_{func_base_name}' + resolver_name = f'resolve_{func_base_name}' func_sig = '(obj: Any, info: GraphQLResolveInfo, data: Dict)' @mutation.field(mutation_name) @@ -59,12 +59,12 @@ def make_configure_resolver(mutation_name): def make_config_file_resolver(mutation_name): op = '' - if 'save' in mutation_name: + if 'Save' in mutation_name: op = 'save' - elif 'load' in mutation_name: + elif 'Load' in mutation_name: op = 'load' - class_name = mutation_name.replace('save', '', 1).replace('load', '', 1) + class_name = mutation_name.replace('Save', '', 1).replace('Load', '', 1) func_base_name = convert_camel_case_to_snake(class_name) resolver_name = f'resolve_{func_base_name}' func_sig = '(obj: Any, info: GraphQLResolveInfo, data: Dict)' diff --git a/src/services/api/graphql/graphql/schema/config_file.graphql b/src/services/api/graphql/graphql/schema/config_file.graphql index 3096cf743..31ab26b9e 100644 --- a/src/services/api/graphql/graphql/schema/config_file.graphql +++ b/src/services/api/graphql/graphql/schema/config_file.graphql @@ -1,27 +1,27 @@ -input saveConfigFileInput { +input SaveConfigFileInput { fileName: String } -type saveConfigFile { +type SaveConfigFile { fileName: String } -type saveConfigFileResult { - data: saveConfigFile +type SaveConfigFileResult { + data: SaveConfigFile success: Boolean! errors: [String] } -input loadConfigFileInput { +input LoadConfigFileInput { fileName: String! } -type loadConfigFile { +type LoadConfigFile { fileName: String! } -type loadConfigFileResult { - data: loadConfigFile +type LoadConfigFileResult { + data: LoadConfigFile success: Boolean! errors: [String] } diff --git a/src/services/api/graphql/graphql/schema/dhcp_server.graphql b/src/services/api/graphql/graphql/schema/dhcp_server.graphql index 9f741a0a5..25f091bfa 100644 --- a/src/services/api/graphql/graphql/schema/dhcp_server.graphql +++ b/src/services/api/graphql/graphql/schema/dhcp_server.graphql @@ -1,4 +1,4 @@ -input dhcpServerConfigInput { +input DhcpServerConfigInput { sharedNetworkName: String subnet: String defaultRouter: String @@ -13,7 +13,7 @@ input dhcpServerConfigInput { dnsForwardingListenAddress: String } -type dhcpServerConfig { +type DhcpServerConfig { sharedNetworkName: String subnet: String defaultRouter: String @@ -28,8 +28,8 @@ type dhcpServerConfig { dnsForwardingListenAddress: String } -type createDhcpServerResult { - data: dhcpServerConfig +type CreateDhcpServerResult { + data: DhcpServerConfig success: Boolean! errors: [String] } diff --git a/src/services/api/graphql/graphql/schema/interface_ethernet.graphql b/src/services/api/graphql/graphql/schema/interface_ethernet.graphql index fdcf97bad..32438b315 100644 --- a/src/services/api/graphql/graphql/schema/interface_ethernet.graphql +++ b/src/services/api/graphql/graphql/schema/interface_ethernet.graphql @@ -1,18 +1,18 @@ -input interfaceEthernetConfigInput { +input InterfaceEthernetConfigInput { interface: String address: String replace: Boolean = true description: String } -type interfaceEthernetConfig { +type InterfaceEthernetConfig { interface: String address: String description: String } -type createInterfaceEthernetResult { - data: interfaceEthernetConfig +type CreateInterfaceEthernetResult { + data: InterfaceEthernetConfig success: Boolean! errors: [String] } diff --git a/src/services/api/graphql/graphql/schema/schema.graphql b/src/services/api/graphql/graphql/schema/schema.graphql index 4730f24bc..e34a4eadb 100644 --- a/src/services/api/graphql/graphql/schema/schema.graphql +++ b/src/services/api/graphql/graphql/schema/schema.graphql @@ -11,8 +11,8 @@ directive @configure on FIELD_DEFINITION directive @configfile on FIELD_DEFINITION type Mutation { - createDhcpServer(data: dhcpServerConfigInput) : createDhcpServerResult @configure - createInterfaceEthernet(data: interfaceEthernetConfigInput) : createInterfaceEthernetResult @configure - saveConfigFile(data: saveConfigFileInput) : saveConfigFileResult @configfile - loadConfigFile(data: loadConfigFileInput) : loadConfigFileResult @configfile + CreateDhcpServer(data: DhcpServerConfigInput) : CreateDhcpServerResult @configure + CreateInterfaceEthernet(data: InterfaceEthernetConfigInput) : CreateInterfaceEthernetResult @configure + SaveConfigFile(data: SaveConfigFileInput) : SaveConfigFileResult @configfile + LoadConfigFile(data: LoadConfigFileInput) : LoadConfigFileResult @configfile } diff --git a/src/services/api/graphql/recipes/create_dhcp_server.py b/src/services/api/graphql/recipes/create_dhcp_server.py new file mode 100644 index 000000000..ac6f15209 --- /dev/null +++ b/src/services/api/graphql/recipes/create_dhcp_server.py @@ -0,0 +1,13 @@ + +from . recipe import Recipe + +class CreateDhcpServer(Recipe): + def __init__(self, session, command_file): + super().__init__(session, command_file) + + # Define any custom processing of parameters here by overriding + # configure: + # + # def configure(self): + # self.data = transform_data(self.data) + # super().configure() diff --git a/src/services/api/graphql/recipes/create_interface_ethernet.py b/src/services/api/graphql/recipes/create_interface_ethernet.py new file mode 100644 index 000000000..aafb4d55c --- /dev/null +++ b/src/services/api/graphql/recipes/create_interface_ethernet.py @@ -0,0 +1,13 @@ + +from . recipe import Recipe + +class CreateInterfaceEthernet(Recipe): + def __init__(self, session, command_file): + super().__init__(session, command_file) + + # Define any custom processing of parameters here by overriding + # configure: + # + # def configure(self): + # self.data = transform_data(self.data) + # super().configure() diff --git a/src/services/api/graphql/recipes/dhcp_server.py b/src/services/api/graphql/recipes/dhcp_server.py deleted file mode 100644 index 3edb3028e..000000000 --- a/src/services/api/graphql/recipes/dhcp_server.py +++ /dev/null @@ -1,13 +0,0 @@ - -from . recipe import Recipe - -class DhcpServer(Recipe): - def __init__(self, session, command_file): - super().__init__(session, command_file) - - # Define any custom processing of parameters here by overriding - # configure: - # - # def configure(self): - # self.data = transform_data(self.data) - # super().configure() diff --git a/src/services/api/graphql/recipes/interface_ethernet.py b/src/services/api/graphql/recipes/interface_ethernet.py deleted file mode 100644 index f88f5924f..000000000 --- a/src/services/api/graphql/recipes/interface_ethernet.py +++ /dev/null @@ -1,13 +0,0 @@ - -from . recipe import Recipe - -class InterfaceEthernet(Recipe): - def __init__(self, session, command_file): - super().__init__(session, command_file) - - # Define any custom processing of parameters here by overriding - # configure: - # - # def configure(self): - # self.data = transform_data(self.data) - # super().configure() diff --git a/src/services/api/graphql/recipes/templates/create_dhcp_server.tmpl b/src/services/api/graphql/recipes/templates/create_dhcp_server.tmpl new file mode 100644 index 000000000..70de43183 --- /dev/null +++ b/src/services/api/graphql/recipes/templates/create_dhcp_server.tmpl @@ -0,0 +1,9 @@ +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} default-router {{ default_router }} +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} name-server {{ name_server }} +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} domain-name {{ domain_name }} +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} lease {{ lease }} +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} range {{ range }} start {{ start }} +set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} range {{ range }} stop {{ stop }} +set service dns forwarding allow-from {{ dns_forwarding_allow_from }} +set service dns forwarding cache-size {{ dns_forwarding_cache_size }} +set service dns forwarding listen-address {{ dns_forwarding_listen_address }} diff --git a/src/services/api/graphql/recipes/templates/create_interface_ethernet.tmpl b/src/services/api/graphql/recipes/templates/create_interface_ethernet.tmpl new file mode 100644 index 000000000..d9d7ed691 --- /dev/null +++ b/src/services/api/graphql/recipes/templates/create_interface_ethernet.tmpl @@ -0,0 +1,5 @@ +{% if replace %} +delete interfaces ethernet {{ interface }} address +{% endif %} +set interfaces ethernet {{ interface }} address {{ address }} +set interfaces ethernet {{ interface }} description {{ description }} diff --git a/src/services/api/graphql/recipes/templates/dhcp_server.tmpl b/src/services/api/graphql/recipes/templates/dhcp_server.tmpl deleted file mode 100644 index 70de43183..000000000 --- a/src/services/api/graphql/recipes/templates/dhcp_server.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} default-router {{ default_router }} -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} name-server {{ name_server }} -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} domain-name {{ domain_name }} -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} lease {{ lease }} -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} range {{ range }} start {{ start }} -set service dhcp-server shared-network-name {{ shared_network_name }} subnet {{ subnet }} range {{ range }} stop {{ stop }} -set service dns forwarding allow-from {{ dns_forwarding_allow_from }} -set service dns forwarding cache-size {{ dns_forwarding_cache_size }} -set service dns forwarding listen-address {{ dns_forwarding_listen_address }} diff --git a/src/services/api/graphql/recipes/templates/interface_ethernet.tmpl b/src/services/api/graphql/recipes/templates/interface_ethernet.tmpl deleted file mode 100644 index d9d7ed691..000000000 --- a/src/services/api/graphql/recipes/templates/interface_ethernet.tmpl +++ /dev/null @@ -1,5 +0,0 @@ -{% if replace %} -delete interfaces ethernet {{ interface }} address -{% endif %} -set interfaces ethernet {{ interface }} address {{ address }} -set interfaces ethernet {{ interface }} description {{ description }} -- cgit v1.2.3