updated GraphQL for Netbox 4.4
This commit is contained in:
parent
d25f7aeec3
commit
23fb524f0a
2 changed files with 11 additions and 4 deletions
|
|
@ -21,6 +21,9 @@ from pynetbox_config_helper import build_argparser, resolve_graphql_config
|
||||||
|
|
||||||
import importlib.resources
|
import importlib.resources
|
||||||
|
|
||||||
|
class GraphQlError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -72,6 +75,10 @@ def graphql_query(client: GraphqlClient, query, variables: Optional[Dict] = None
|
||||||
|
|
||||||
data = client.execute(query, variables=variables)
|
data = client.execute(query, variables=variables)
|
||||||
|
|
||||||
|
errors = data.get("errors")
|
||||||
|
if errors:
|
||||||
|
raise GraphQlError(errors)
|
||||||
|
|
||||||
logger.debug(f"received data from GraphQL:\n{pformat(data)}")
|
logger.debug(f"received data from GraphQL:\n{pformat(data)}")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
@ -161,8 +168,8 @@ def build_vm():
|
||||||
query,
|
query,
|
||||||
variables={
|
variables={
|
||||||
"address": str(interface_addr.ip),
|
"address": str(interface_addr.ip),
|
||||||
"prefix_length": str(interface_addr.network.prefixlen),
|
"prefix_length": "/" + str(interface_addr.network.prefixlen),
|
||||||
"vrf": "null",
|
"vrf": None,
|
||||||
},
|
},
|
||||||
)["data"]
|
)["data"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
query Prefixes($address: String, $prefix_length: [String!], $vrf: [String!]) {
|
query Prefixes($address: [String!], $prefix_length: String, $vrf: ID) {
|
||||||
prefixes: prefix_list(
|
prefixes: prefix_list(
|
||||||
filters: {contains: $address, AND: {mask_length: $prefix_length, AND: {vrf: $vrf}}}
|
filters: {contains: $address, AND: {prefix: {ends_with: $prefix_length}, AND: {vrf_id: $vrf}}}
|
||||||
) {
|
) {
|
||||||
prefix
|
prefix
|
||||||
custom_fields
|
custom_fields
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue