Skip to content

Commit b468966

Browse files
add examples for getting the password and IPv4 (#328)
* add examples for getting the password and IPv4 Add three examples: 1. Output the new_linode root password 2. Output the new_linode IPv4 address 3. Delete the new_linode * amplify warning * Update IPv4 example * Make format --------- Co-authored-by: Lena Garber <lgarber@akamai.com> Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
1 parent 4c3f306 commit b468966

File tree

10 files changed

+90
-54
lines changed

10 files changed

+90
-54
lines changed

linode_api4/groups/linode.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def instance_create(
141141
a :any:`Type`, a :any:`Region`, and an :any:`Image`. All three of
142142
these fields may be provided as either the ID or the appropriate object.
143143
In this mode, a root password will be generated and returned with the
144-
new Instance object. For example::
144+
new Instance object.
145+
146+
For example::
145147
146148
new_linode, password = client.linode.instance_create(
147149
"g6-standard-2",
@@ -157,6 +159,15 @@ def instance_create(
157159
region,
158160
image=image)
159161
162+
To output the password from the above example:
163+
print(password)
164+
165+
To output the first IPv4 address of the new Linode:
166+
print(new_linode.ipv4[0])
167+
168+
To delete the new_linode (WARNING: this immediately destroys the Linode):
169+
new_linode.delete()
170+
160171
**Create an Instance from StackScript**
161172
162173
When creating an Instance from a :any:`StackScript`, an :any:`Image` that
@@ -295,9 +306,11 @@ def instance_create(
295306
params = {
296307
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
297308
"region": region.id if issubclass(type(region), Base) else region,
298-
"image": (image.id if issubclass(type(image), Base) else image)
299-
if image
300-
else None,
309+
"image": (
310+
(image.id if issubclass(type(image), Base) else image)
311+
if image
312+
else None
313+
),
301314
"authorized_keys": authorized_keys,
302315
}
303316

linode_api4/groups/lke.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
9393
for c in node_pools:
9494
if isinstance(c, dict):
9595
new_pool = {
96-
"type": c["type"].id
97-
if "type" in c and issubclass(type(c["type"]), Base)
98-
else c.get("type"),
96+
"type": (
97+
c["type"].id
98+
if "type" in c and issubclass(type(c["type"]), Base)
99+
else c.get("type")
100+
),
99101
"count": c.get("count"),
100102
}
101103

@@ -105,9 +107,11 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
105107
"label": label,
106108
"region": region.id if issubclass(type(region), Base) else region,
107109
"node_pools": pools,
108-
"k8s_version": kube_version.id
109-
if issubclass(type(kube_version), Base)
110-
else kube_version,
110+
"k8s_version": (
111+
kube_version.id
112+
if issubclass(type(kube_version), Base)
113+
else kube_version
114+
),
111115
}
112116
params.update(kwargs)
113117

linode_api4/groups/networking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def ip_addresses_share(self, ips, linode):
310310

311311
params = {
312312
"ips": shared_ips,
313-
"linode_id": linode
314-
if not isinstance(linode, Instance)
315-
else linode.id,
313+
"linode_id": (
314+
linode if not isinstance(linode, Instance) else linode.id
315+
),
316316
}
317317

318318
self.client.post("/networking/ips/share", model=self, data=params)

linode_api4/groups/obj.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ def keys_create(self, label, bucket_access=None):
104104
{
105105
"permissions": c.get("permissions"),
106106
"bucket_name": c.get("bucket_name"),
107-
"cluster": c.id
108-
if "cluster" in c and issubclass(type(c["cluster"]), Base)
109-
else c.get("cluster"),
107+
"cluster": (
108+
c.id
109+
if "cluster" in c
110+
and issubclass(type(c["cluster"]), Base)
111+
else c.get("cluster")
112+
),
110113
}
111114
for c in bucket_access
112115
]

linode_api4/groups/object_storage.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ def keys_create(self, label, bucket_access=None):
114114
{
115115
"permissions": c.get("permissions"),
116116
"bucket_name": c.get("bucket_name"),
117-
"cluster": c.id
118-
if "cluster" in c and issubclass(type(c["cluster"]), Base)
119-
else c.get("cluster"),
117+
"cluster": (
118+
c.id
119+
if "cluster" in c
120+
and issubclass(type(c["cluster"]), Base)
121+
else c.get("cluster")
122+
),
120123
}
121124
for c in bucket_access
122125
]

linode_api4/groups/volume.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def create(self, label, region=None, linode=None, size=20, **kwargs):
5656
"label": label,
5757
"size": size,
5858
"region": region.id if issubclass(type(region), Base) else region,
59-
"linode_id": linode.id
60-
if issubclass(type(linode), Base)
61-
else linode,
59+
"linode_id": (
60+
linode.id if issubclass(type(linode), Base) else linode
61+
),
6262
}
6363
params.update(kwargs)
6464

linode_api4/objects/linode.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def restore_to(self, linode, **kwargs):
8282
"""
8383

8484
d = {
85-
"linode_id": linode.id
86-
if issubclass(type(linode), Base)
87-
else linode,
85+
"linode_id": (
86+
linode.id if issubclass(type(linode), Base) else linode
87+
),
8888
}
8989
d.update(kwargs)
9090

@@ -379,9 +379,11 @@ def _serialize(self):
379379
"purpose": "vpc",
380380
"primary": self.primary,
381381
"subnet_id": self.subnet_id,
382-
"ipv4": self.ipv4.dict
383-
if isinstance(self.ipv4, ConfigInterfaceIPv4)
384-
else self.ipv4,
382+
"ipv4": (
383+
self.ipv4.dict
384+
if isinstance(self.ipv4, ConfigInterfaceIPv4)
385+
else self.ipv4
386+
),
385387
"ip_ranges": self.ip_ranges,
386388
},
387389
}
@@ -1117,9 +1119,11 @@ def config_create(
11171119

11181120
params = {
11191121
"kernel": kernel.id if issubclass(type(kernel), Base) else kernel,
1120-
"label": label
1121-
if label
1122-
else "{}_config_{}".format(self.label, len(self.configs)),
1122+
"label": (
1123+
label
1124+
if label
1125+
else "{}_config_{}".format(self.label, len(self.configs))
1126+
),
11231127
"devices": device_map,
11241128
"interfaces": param_interfaces,
11251129
}
@@ -1190,9 +1194,11 @@ def disk_create(
11901194

11911195
params = {
11921196
"size": size,
1193-
"label": label
1194-
if label
1195-
else "{}_disk_{}".format(self.label, len(self.disks)),
1197+
"label": (
1198+
label
1199+
if label
1200+
else "{}_disk_{}".format(self.label, len(self.disks))
1201+
),
11961202
"read_only": read_only,
11971203
"filesystem": filesystem,
11981204
"authorized_keys": authorized_keys,
@@ -1202,9 +1208,9 @@ def disk_create(
12021208
if image:
12031209
params.update(
12041210
{
1205-
"image": image.id
1206-
if issubclass(type(image), Base)
1207-
else image,
1211+
"image": (
1212+
image.id if issubclass(type(image), Base) else image
1213+
),
12081214
"root_pass": root_pass,
12091215
}
12101216
)
@@ -1629,13 +1635,15 @@ def clone(
16291635
dids = [d.id if issubclass(type(d), Base) else d for d in disks]
16301636

16311637
params = {
1632-
"linode_id": to_linode.id
1633-
if issubclass(type(to_linode), Base)
1634-
else to_linode,
1638+
"linode_id": (
1639+
to_linode.id if issubclass(type(to_linode), Base) else to_linode
1640+
),
16351641
"region": region.id if issubclass(type(region), Base) else region,
1636-
"type": instance_type.id
1637-
if issubclass(type(instance_type), Base)
1638-
else instance_type,
1642+
"type": (
1643+
instance_type.id
1644+
if issubclass(type(instance_type), Base)
1645+
else instance_type
1646+
),
16391647
"configs": cids if cids else None,
16401648
"disks": dids if dids else None,
16411649
"label": label,

linode_api4/objects/lke.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ def _populate(self, json):
8383
"""
8484
if json is not None and json != {}:
8585
new_nodes = [
86-
LKENodePoolNode(self._client, c)
87-
if not isinstance(c, dict)
88-
else c
86+
(
87+
LKENodePoolNode(self._client, c)
88+
if not isinstance(c, dict)
89+
else c
90+
)
8991
for c in json["nodes"]
9092
]
9193
json["nodes"] = new_nodes

linode_api4/objects/volume.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ def attach(self, to_linode, config=None):
4545
"{}/attach".format(Volume.api_endpoint),
4646
model=self,
4747
data={
48-
"linode_id": to_linode.id
49-
if issubclass(type(to_linode), Base)
50-
else to_linode,
51-
"config": None
52-
if not config
53-
else config.id
54-
if issubclass(type(config), Base)
55-
else config,
48+
"linode_id": (
49+
to_linode.id
50+
if issubclass(type(to_linode), Base)
51+
else to_linode
52+
),
53+
"config": (
54+
None
55+
if not config
56+
else config.id if issubclass(type(config), Base) else config
57+
),
5658
},
5759
)
5860

linode_api4/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Contains various utility functions.
33
"""
4+
45
from typing import Any, Dict
56

67

0 commit comments

Comments
 (0)