forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
executable file
·40 lines (31 loc) · 1.06 KB
/
Copy pathshell.py
File metadata and controls
executable file
·40 lines (31 loc) · 1.06 KB
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
33
34
35
36
37
38
39
40
#!/usr/local/bin/python3
import linode
from linode import config
from linode.linode_client import LinodeClient
from os import path, makedirs
import code
import getpass
no_token_message = """You must have an oauth token to access the api. To generate a token,
see documentation at developer.linode.com
"""
file_path = path.expanduser('~/.linode/api_token')
if not path.isfile(file_path):
print(no_token_message)
token = getpass.getpass('oauth token: ')
if token:
makedirs(path.dirname(file_path), exist_ok=True)
with open(file_path, 'w') as f:
f.write(token)
else:
raise ValueError('You must have an oauth token to use the api shell')
api_token = open(file_path).read().rstrip()
base_path = path.expanduser('~/.linode/base_url')
base_url = None
if path.isfile(base_path):
base_url = open(base_path).read().rstrip()
lc = LinodeClient(api_token, base_url=base_url)
banner="""## DEV MODE ##
>>> import linode
>>> from linode import LinodeClient
>>> lc = LinodeClient( ... )"""
code.interact(local=locals(), banner=banner)