-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
32 lines (23 loc) · 829 Bytes
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
def get_droplet_by_name(manager, name):
"""Returns a droplet for the given name, or None"""
my_droplets = manager.get_all_droplets()
for droplet in my_droplets:
if droplet.name == name:
return droplet
return None
def get_image_by_name(manager, name):
"""Returns the image object with the given name, or None if not found"""
my_images = manager.get_my_images()
for image in my_images:
if image.name == name:
return image
return None
def get_ssh_keylist_by_name(manager, name):
"""Returns a keylist with the given named key, or empty if not found"""
all_ssh_keys = manager.get_all_sshkeys()
ssh_keys = []
for key in all_ssh_keys:
if key.name == name:
ssh_keys.append(key)
return ssh_keys