|
| 1 | +import sys |
| 2 | +import time |
| 3 | +import paperspace |
| 4 | + |
| 5 | +def errorcheck(res): |
| 6 | + if 'error' in res: |
| 7 | + paperspace.print_json_pretty(res) |
| 8 | + sys.exit(1) |
| 9 | +""" |
| 10 | +print("paperspace.machines.availability({'region': 'East Coast (NY2)', 'machineType': 'P4000'})") |
| 11 | +res = paperspace.machines.availability({'region': 'East Coast (NY2)', 'machineType': 'P4000'}) |
| 12 | +errorcheck(res) |
| 13 | +paperspace.print_json_pretty(res) |
| 14 | +
|
| 15 | +print("paperspace.networks.list()") |
| 16 | +networks = paperspace.networks.list() |
| 17 | +if 'error' in res: |
| 18 | + paperspace.print_json_pretty(res) |
| 19 | +else: |
| 20 | + for network in networks: |
| 21 | + paperspace.print_json_pretty(network) |
| 22 | +
|
| 23 | +print("paperspace.templates.list()") |
| 24 | +templates = paperspace.templates.list() |
| 25 | +errorcheck(templates) |
| 26 | +for template in templates: |
| 27 | + paperspace.print_json_pretty(template) |
| 28 | +
|
| 29 | +print("paperspace.users.list()") |
| 30 | +users = paperspace.users.list() |
| 31 | +errorcheck(users) |
| 32 | +for user in users: |
| 33 | + paperspace.print_json_pretty(user) |
| 34 | +
|
| 35 | +print("paperspace.scripts.create(...)") |
| 36 | +script = paperspace.scripts.create({'scriptName': 'My Python Script', 'scriptText': 'python --version'}) |
| 37 | +errorcheck(script) |
| 38 | +paperspace.print_json_pretty(script) |
| 39 | +scriptId = script['id'] |
| 40 | +
|
| 41 | +print("paperspace.scripts.show(...)") |
| 42 | +script = paperspace.scripts.show({'scriptId': scriptId}) |
| 43 | +errorcheck(script) |
| 44 | +paperspace.print_json_pretty(script) |
| 45 | +
|
| 46 | +print("paperspace.scripts.destroy(...)") |
| 47 | +res = paperspace.scripts.destroy({'scriptId': scriptId}) |
| 48 | +errorcheck(res) |
| 49 | +paperspace.print_json_pretty(res) |
| 50 | +
|
| 51 | +print("paperspace.scripts.list()") |
| 52 | +scripts = paperspace.scripts.list() |
| 53 | +errorcheck(scripts) |
| 54 | +scriptId = None |
| 55 | +last_script = None |
| 56 | +for script in scripts: |
| 57 | + #paperspace.print_json_pretty(script) |
| 58 | + scriptId = script['id'] |
| 59 | + last_script = script |
| 60 | +if last_script: |
| 61 | + paperspace.print_json_pretty(last_script) |
| 62 | +
|
| 63 | +print("paperspace.scripts.show(...)") |
| 64 | +script = paperspace.scripts.show({'scriptId': scriptId}) |
| 65 | +errorcheck(script) |
| 66 | +paperspace.print_json_pretty(script) |
| 67 | +
|
| 68 | +print("paperspace.scripts.text(...)") |
| 69 | +script = paperspace.scripts.text({'scriptId': scriptId}) |
| 70 | +errorcheck(script) |
| 71 | +paperspace.print_json_pretty(script) |
| 72 | +
|
| 73 | +print("paperspace.machines.create(...)") |
| 74 | +machine = paperspace.machines.create({'machineType': 'C1', 'region': 'East Coast (NY2)', 'billingType': 'hourly', |
| 75 | + 'machineName': 'pythoncreate4', 'templateId': 'tqalmii', 'size': '50', 'dynamicPublicIp': True}) #prod: 'tbludl2' |
| 76 | +errorcheck(machine) |
| 77 | +paperspace.print_json_pretty(machine) |
| 78 | +
|
| 79 | +machineId = machine['id'] |
| 80 | +
|
| 81 | +machine = paperspace.machines.waitfor({'machineId': machineId, 'state': 'ready'}) |
| 82 | +errorcheck(machine) |
| 83 | +paperspace.print_json_pretty(machine) |
| 84 | +
|
| 85 | +print("paperspace.machines.show(...)") |
| 86 | +machine = paperspace.machines.show({'machineId': machineId}) |
| 87 | +errorcheck(machine) |
| 88 | +paperspace.print_json_pretty(machine) |
| 89 | +
|
| 90 | +print("paperspace.machines.list()") |
| 91 | +machines = paperspace.machines.list() |
| 92 | +errorcheck(machines) |
| 93 | +paperspace.print_json_pretty(machine) |
| 94 | +found = False |
| 95 | +for machine in machines: |
| 96 | + if machine['id'] == machineId: |
| 97 | + found = True |
| 98 | + print('found machineId %s in machines list' % machine['id']) |
| 99 | +if not found: |
| 100 | + print('failed to find machineId %s in machines list' % machineId) |
| 101 | + sys.exit(1) |
| 102 | +
|
| 103 | +print("paperspace.machines.stop(...)") |
| 104 | +res = paperspace.machines.stop({'machineId': machineId}) |
| 105 | +errorcheck(res) |
| 106 | +paperspace.print_json_pretty(res) |
| 107 | +
|
| 108 | +machine = paperspace.machines.waitfor({'machineId': machineId, 'state': 'off'}) |
| 109 | +errorcheck(machine) |
| 110 | +paperspace.print_json_pretty(machine) |
| 111 | +
|
| 112 | +print("paperspace.machines.update(...)") |
| 113 | +res = paperspace.machines.update({'machineId': machineId, 'machineName': 'pythoncreate-6', 'dynamicPublicIp': False}) |
| 114 | +errorcheck(res) |
| 115 | +paperspace.print_json_pretty(res) |
| 116 | +
|
| 117 | +print("paperspace.machines.show(...)") |
| 118 | +machine = paperspace.machines.show({'machineId': machineId}) |
| 119 | +errorcheck(machine) |
| 120 | +paperspace.print_json_pretty(machine) |
| 121 | +
|
| 122 | +print("paperspace.machines.start(...)") |
| 123 | +res = paperspace.machines.start({'machineId': machineId}) |
| 124 | +errorcheck(res) |
| 125 | +paperspace.print_json_pretty(res) |
| 126 | +
|
| 127 | +machine = paperspace.machines.waitfor({'machineId': machineId, 'state': 'ready'}) |
| 128 | +errorcheck(machine) |
| 129 | +paperspace.print_json_pretty(machine) |
| 130 | +
|
| 131 | +print("paperspace.machines.restart(...)") |
| 132 | +res = paperspace.machines.restart({'machineId': machineId}) |
| 133 | +errorcheck(res) |
| 134 | +paperspace.print_json_pretty(res) |
| 135 | +
|
| 136 | +time.sleep(10) |
| 137 | +
|
| 138 | +machine = paperspace.machines.waitfor({'machineId': machineId, 'state': 'ready'}) |
| 139 | +errorcheck(machine) |
| 140 | +paperspace.print_json_pretty(machine) |
| 141 | +
|
| 142 | +print("paperspace.machines.stop(...)") |
| 143 | +res = paperspace.machines.stop({'machineId': machineId}) |
| 144 | +errorcheck(res) |
| 145 | +paperspace.print_json_pretty(res) |
| 146 | +
|
| 147 | +machine = paperspace.machines.waitfor({'machineId': machineId, 'state': 'off'}) |
| 148 | +errorcheck(machine) |
| 149 | +paperspace.print_json_pretty(machine) |
| 150 | +
|
| 151 | +print("paperspace.machines.destroy(...)") |
| 152 | +res = paperspace.machines.destroy({'machineId': machineId}) |
| 153 | +errorcheck(res) |
| 154 | +paperspace.print_json_pretty(res) |
| 155 | +
|
| 156 | +print("paperspace.machines.utilization(...)") |
| 157 | +res = paperspace.machines.utilization({'machineId': machineId, 'billingMonth': '2018-04'}) |
| 158 | +errorcheck(res) |
| 159 | +paperspace.print_json_pretty(res) |
| 160 | +""" |
0 commit comments