Skip to content

Commit

Permalink
make format
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Jan 30, 2024
1 parent 5b82233 commit a4ecb3b
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 53 deletions.
8 changes: 5 additions & 3 deletions linode_api4/groups/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ def instance_create(
params = {
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
"region": region.id if issubclass(type(region), Base) else region,
"image": (image.id if issubclass(type(image), Base) else image)
if image
else None,
"image": (
(image.id if issubclass(type(image), Base) else image)
if image
else None
),
"authorized_keys": authorized_keys,
}

Expand Down
16 changes: 10 additions & 6 deletions linode_api4/groups/lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
for c in node_pools:
if isinstance(c, dict):
new_pool = {
"type": c["type"].id
if "type" in c and issubclass(type(c["type"]), Base)
else c.get("type"),
"type": (
c["type"].id
if "type" in c and issubclass(type(c["type"]), Base)
else c.get("type")
),
"count": c.get("count"),
}

Expand All @@ -105,9 +107,11 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
"label": label,
"region": region.id if issubclass(type(region), Base) else region,
"node_pools": pools,
"k8s_version": kube_version.id
if issubclass(type(kube_version), Base)
else kube_version,
"k8s_version": (
kube_version.id
if issubclass(type(kube_version), Base)
else kube_version
),
}
params.update(kwargs)

Expand Down
6 changes: 3 additions & 3 deletions linode_api4/groups/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ def ip_addresses_share(self, ips, linode):

params = {
"ips": shared_ips,
"linode_id": linode
if not isinstance(linode, Instance)
else linode.id,
"linode_id": (
linode if not isinstance(linode, Instance) else linode.id
),
}

self.client.post("/networking/ips/share", model=self, data=params)
Expand Down
9 changes: 6 additions & 3 deletions linode_api4/groups/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ def keys_create(self, label, bucket_access=None):
{
"permissions": c.get("permissions"),
"bucket_name": c.get("bucket_name"),
"cluster": c.id
if "cluster" in c and issubclass(type(c["cluster"]), Base)
else c.get("cluster"),
"cluster": (
c.id
if "cluster" in c
and issubclass(type(c["cluster"]), Base)
else c.get("cluster")
),
}
for c in bucket_access
]
Expand Down
9 changes: 6 additions & 3 deletions linode_api4/groups/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ def keys_create(self, label, bucket_access=None):
{
"permissions": c.get("permissions"),
"bucket_name": c.get("bucket_name"),
"cluster": c.id
if "cluster" in c and issubclass(type(c["cluster"]), Base)
else c.get("cluster"),
"cluster": (
c.id
if "cluster" in c
and issubclass(type(c["cluster"]), Base)
else c.get("cluster")
),
}
for c in bucket_access
]
Expand Down
6 changes: 3 additions & 3 deletions linode_api4/groups/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def create(self, label, region=None, linode=None, size=20, **kwargs):
"label": label,
"size": size,
"region": region.id if issubclass(type(region), Base) else region,
"linode_id": linode.id
if issubclass(type(linode), Base)
else linode,
"linode_id": (
linode.id if issubclass(type(linode), Base) else linode
),
}
params.update(kwargs)

Expand Down
50 changes: 29 additions & 21 deletions linode_api4/objects/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def restore_to(self, linode, **kwargs):
"""

d = {
"linode_id": linode.id
if issubclass(type(linode), Base)
else linode,
"linode_id": (
linode.id if issubclass(type(linode), Base) else linode
),
}
d.update(kwargs)

Expand Down Expand Up @@ -379,9 +379,11 @@ def _serialize(self):
"purpose": "vpc",
"primary": self.primary,
"subnet_id": self.subnet_id,
"ipv4": self.ipv4.dict
if isinstance(self.ipv4, ConfigInterfaceIPv4)
else self.ipv4,
"ipv4": (
self.ipv4.dict
if isinstance(self.ipv4, ConfigInterfaceIPv4)
else self.ipv4
),
"ip_ranges": self.ip_ranges,
},
}
Expand Down Expand Up @@ -1117,9 +1119,11 @@ def config_create(

params = {
"kernel": kernel.id if issubclass(type(kernel), Base) else kernel,
"label": label
if label
else "{}_config_{}".format(self.label, len(self.configs)),
"label": (
label
if label
else "{}_config_{}".format(self.label, len(self.configs))
),
"devices": device_map,
"interfaces": param_interfaces,
}
Expand Down Expand Up @@ -1190,9 +1194,11 @@ def disk_create(

params = {
"size": size,
"label": label
if label
else "{}_disk_{}".format(self.label, len(self.disks)),
"label": (
label
if label
else "{}_disk_{}".format(self.label, len(self.disks))
),
"read_only": read_only,
"filesystem": filesystem,
"authorized_keys": authorized_keys,
Expand All @@ -1202,9 +1208,9 @@ def disk_create(
if image:
params.update(
{
"image": image.id
if issubclass(type(image), Base)
else image,
"image": (
image.id if issubclass(type(image), Base) else image
),
"root_pass": root_pass,
}
)
Expand Down Expand Up @@ -1629,13 +1635,15 @@ def clone(
dids = [d.id if issubclass(type(d), Base) else d for d in disks]

params = {
"linode_id": to_linode.id
if issubclass(type(to_linode), Base)
else to_linode,
"linode_id": (
to_linode.id if issubclass(type(to_linode), Base) else to_linode
),
"region": region.id if issubclass(type(region), Base) else region,
"type": instance_type.id
if issubclass(type(instance_type), Base)
else instance_type,
"type": (
instance_type.id
if issubclass(type(instance_type), Base)
else instance_type
),
"configs": cids if cids else None,
"disks": dids if dids else None,
"label": label,
Expand Down
8 changes: 5 additions & 3 deletions linode_api4/objects/lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ def _populate(self, json):
"""
if json is not None and json != {}:
new_nodes = [
LKENodePoolNode(self._client, c)
if not isinstance(c, dict)
else c
(
LKENodePoolNode(self._client, c)
if not isinstance(c, dict)
else c
)
for c in json["nodes"]
]
json["nodes"] = new_nodes
Expand Down
18 changes: 10 additions & 8 deletions linode_api4/objects/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ def attach(self, to_linode, config=None):
"{}/attach".format(Volume.api_endpoint),
model=self,
data={
"linode_id": to_linode.id
if issubclass(type(to_linode), Base)
else to_linode,
"config": None
if not config
else config.id
if issubclass(type(config), Base)
else config,
"linode_id": (
to_linode.id
if issubclass(type(to_linode), Base)
else to_linode
),
"config": (
None
if not config
else config.id if issubclass(type(config), Base) else config
),
},
)

Expand Down
1 change: 1 addition & 0 deletions linode_api4/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains various utility functions.
"""

from typing import Any, Dict


Expand Down

0 comments on commit a4ecb3b

Please sign in to comment.