Skip to content

Commit 5bbca59

Browse files
committed
improve(network): remove unnecessary None checks for network, subnet, port, floating ip, router, security group (#85)
1 parent 986e03b commit 5bbca59

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/openstack_mcp_server/tools/network_tools.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def update_network(
178178

179179
update_args = {}
180180

181-
if name is not None:
181+
if name:
182182
update_args["name"] = name
183-
if description is not None:
183+
if description:
184184
update_args["description"] = description
185185
if is_admin_state_up is not None:
186186
update_args["admin_state_up"] = is_admin_state_up
@@ -312,11 +312,11 @@ def create_subnet(
312312
"ip_version": ip_version,
313313
"enable_dhcp": is_dhcp_enabled,
314314
}
315-
if name is not None:
315+
if name:
316316
subnet_args["name"] = name
317-
if description is not None:
317+
if description:
318318
subnet_args["description"] = description
319-
if gateway_ip is not None:
319+
if gateway_ip:
320320
subnet_args["gateway_ip"] = gateway_ip
321321
if dns_nameservers is not None:
322322
subnet_args["dns_nameservers"] = dns_nameservers
@@ -385,13 +385,13 @@ def update_subnet(
385385
"""
386386
conn = get_openstack_conn()
387387
update_args: dict = {}
388-
if name is not None:
388+
if name:
389389
update_args["name"] = name
390-
if description is not None:
390+
if description:
391391
update_args["description"] = description
392392
if clear_gateway:
393393
update_args["gateway_ip"] = None
394-
elif gateway_ip is not None:
394+
elif gateway_ip:
395395
update_args["gateway_ip"] = gateway_ip
396396
if is_dhcp_enabled is not None:
397397
update_args["enable_dhcp"] = is_dhcp_enabled
@@ -499,9 +499,9 @@ def set_port_binding(
499499
"""
500500
conn = get_openstack_conn()
501501
update_args: dict = {}
502-
if host_id is not None:
502+
if host_id:
503503
update_args["binding_host_id"] = host_id
504-
if vnic_type is not None:
504+
if vnic_type:
505505
update_args["binding_vnic_type"] = vnic_type
506506
if profile is not None:
507507
update_args["binding_profile"] = profile
@@ -538,11 +538,11 @@ def create_port(
538538
"network_id": network_id,
539539
"admin_state_up": is_admin_state_up,
540540
}
541-
if name is not None:
541+
if name:
542542
port_args["name"] = name
543-
if description is not None:
543+
if description:
544544
port_args["description"] = description
545-
if device_id is not None:
545+
if device_id:
546546
port_args["device_id"] = device_id
547547
if fixed_ips is not None:
548548
port_args["fixed_ips"] = fixed_ips
@@ -611,13 +611,13 @@ def update_port(
611611
"""
612612
conn = get_openstack_conn()
613613
update_args: dict = {}
614-
if name is not None:
614+
if name:
615615
update_args["name"] = name
616-
if description is not None:
616+
if description:
617617
update_args["description"] = description
618618
if is_admin_state_up is not None:
619619
update_args["admin_state_up"] = is_admin_state_up
620-
if device_id is not None:
620+
if device_id:
621621
update_args["device_id"] = device_id
622622
if security_group_ids is not None:
623623
update_args["security_groups"] = security_group_ids
@@ -724,13 +724,13 @@ def create_floating_ip(
724724
"""
725725
conn = get_openstack_conn()
726726
ip_args: dict = {"floating_network_id": floating_network_id}
727-
if description is not None:
727+
if description:
728728
ip_args["description"] = description
729-
if fixed_ip_address is not None:
729+
if fixed_ip_address:
730730
ip_args["fixed_ip_address"] = fixed_ip_address
731-
if port_id is not None:
731+
if port_id:
732732
ip_args["port_id"] = port_id
733-
if project_id is not None:
733+
if project_id:
734734
ip_args["project_id"] = project_id
735735
ip = conn.network.create_ip(**ip_args)
736736
return self._convert_to_floating_ip_model(ip)
@@ -751,7 +751,7 @@ def attach_floating_ip_to_port(
751751
"""
752752
conn = get_openstack_conn()
753753
update_args: dict = {"port_id": port_id}
754-
if fixed_ip_address is not None:
754+
if fixed_ip_address:
755755
update_args["fixed_ip_address"] = fixed_ip_address
756756
ip = conn.network.update_ip(floating_ip_id, **update_args)
757757
return self._convert_to_floating_ip_model(ip)
@@ -792,9 +792,9 @@ def update_floating_ip(
792792
update_args: dict = {}
793793
if description is not None:
794794
update_args["description"] = description
795-
if port_id is not None:
795+
if port_id:
796796
update_args["port_id"] = port_id
797-
if fixed_ip_address is not None:
797+
if fixed_ip_address:
798798
update_args["fixed_ip_address"] = fixed_ip_address
799799
else:
800800
if clear_port:
@@ -954,13 +954,13 @@ def create_router(
954954
"""
955955
conn = get_openstack_conn()
956956
router_args: dict = {"admin_state_up": is_admin_state_up}
957-
if name is not None:
957+
if name:
958958
router_args["name"] = name
959-
if description is not None:
959+
if description:
960960
router_args["description"] = description
961961
if is_distributed is not None:
962962
router_args["distributed"] = is_distributed
963-
if project_id is not None:
963+
if project_id:
964964
router_args["project_id"] = project_id
965965
if external_gateway_info is not None:
966966
router_args["external_gateway_info"] = (
@@ -1015,9 +1015,9 @@ def update_router(
10151015
"""
10161016
conn = get_openstack_conn()
10171017
update_args: dict = {}
1018-
if name is not None:
1018+
if name:
10191019
update_args["name"] = name
1020-
if description is not None:
1020+
if description:
10211021
update_args["description"] = description
10221022
if is_admin_state_up is not None:
10231023
update_args["admin_state_up"] = is_admin_state_up
@@ -1121,9 +1121,9 @@ def remove_router_interface(
11211121
"""
11221122
conn = get_openstack_conn()
11231123
args: dict = {}
1124-
if subnet_id is not None:
1124+
if subnet_id:
11251125
args["subnet_id"] = subnet_id
1126-
if port_id is not None:
1126+
if port_id:
11271127
args["port_id"] = port_id
11281128
res = conn.network.remove_interface_from_router(router_id, **args)
11291129
return RouterInterface(
@@ -1210,9 +1210,9 @@ def create_security_group(
12101210
"""
12111211
conn = get_openstack_conn()
12121212
args: dict = {"name": name}
1213-
if description is not None:
1213+
if description:
12141214
args["description"] = description
1215-
if project_id is not None:
1215+
if project_id:
12161216
args["project_id"] = project_id
12171217
sg = conn.network.create_security_group(**args)
12181218
return self._convert_to_security_group_model(sg)

0 commit comments

Comments
 (0)