Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package version 0.2 #1

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 143 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,24 @@ import json

master = cherry.Master(auth_token="api_token")

plans = master.get_plans("28519")
plans = master.get_plans(team_id="28519")

for plan in plans:
p = json.dumps(plan)
parse_p = json.loads(p)
print("Plan id: %s -> Plan name: %s -> Av: %s" % (parse_p['id'],
parse_p['name'],
parse_p['available_regions']))
```

#### Get only bare metal plans
```
import cherry
import json

master = cherry.Master(auth_token="api_token")

plans = master.get_plans(team_id="28519", **{'type[]':'baremetal'})

for plan in plans:
p = json.dumps(plan)
Expand All @@ -51,7 +68,7 @@ import json

master = cherry.Master(auth_token="api_token")

images = master.get_images("161")
images = master.get_images(plan_id="161")

for image in images:
i = json.dumps(image)
Expand All @@ -68,7 +85,7 @@ import json

master = cherry.Master(auth_token="api_token")

projects = master.get_projects("28519")
projects = master.get_projects(team_id="28519")

for project in projects:
p = json.dumps(project)
Expand Down Expand Up @@ -98,7 +115,7 @@ import json

master = cherry.Master(auth_token="api_token")

servers = master.get_servers("79813")
servers = master.get_servers(project_id="79813")

for server in servers:
sr = json.dumps(server)
Expand All @@ -107,14 +124,26 @@ for server in servers:
print("Server ID: %s -> IP: %s" % (parse_sr['id'], parse_sr['ip_addresses']))
```

### Get specific server info
#### Get server info
```
import cherry
import json

master = cherry.Master(auth_token="api_token")

server = master.get_server(server_id="165903")

print(server)
```

#### Get specific server info
```
import cherry
import json

master = cherry.Master(auth_token="api_token")

server = master.get_server("165903")
server = master.get_server(server_id="165903", fields="power,state,termination_date")

print(server)
```
Expand All @@ -133,21 +162,127 @@ server = master.create_server(project_id="79813",
name="super-duper",
hostname="bla.com",
image="Ubuntu 16.04 64bit",
region="EU-East-1",
region="EU-Nord-1",
ip_addresses=ips,
ssh_keys=ssh_keys,
plan_id="161")

print("Server: %s" % server)
```

#### Order first available server from spot market
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
plans = master.get_plans(team_id="28519", fields="id,name,available_regions,region")

for plan in plans:
for region in plan['available_regions']:
if region['spot_qty'] > 0:
server = master.create_server(project_id="79813",
region=region['name'],
plan_id=plan['id'],
spot_market="1")
print("%s server (ID %s) deployment has just been started from spot market" % (plan['name'], server['id']))
exit()
print("No available servers in spot market")
```

#### Terminate server
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
server = master.terminate_server(server_id="165760")

server = master.terminate_server("165760")
print("Delete server: %s" % server)
```

#### Order IP subnet
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
subnet = master.create_ip_subnet(project_id="46776",
quantity="8",
region="EU-Nord-1")
print("Subnet: %s" % subnet)
```

#### Assign subnet IP addresses to a server
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
subnet = master.get_ip_subnet(project_id=46776, subnet_id="377432", fields="subnet,id")
server_id = "377441"

for subnet_ip in subnet["addresses"]:
master.update_ip_address(project_id=46776, ip_address_id=subnet_ip["id"], assigned_to=server_id)

print("Subnet IP %s assigned to a server %s" % (subnet_ip, server_id))
```

#### Remove subnet IP addresses from a server
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
subnet = master.get_ip_subnet(project_id=46776, subnet_id="377432", fields="subnet,id,assigned_to")

for subnet_ip in subnet["addresses"]:
if subnet_ip["assigned_to"]:
master.update_ip_address(project_id=46776, ip_address_id=subnet_ip["id"], assigned_to="")
print("Subnet IP %s removed from a server %s" % (subnet_ip["id"], subnet_ip["assigned_to"]["id"]))
```

#### Order storage volume
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
size_in_gb = 100
storage = master.create_storage_volume(project_id=46776, region="EU-Nord-1", size=size_in_gb)

print("Storage: %s" % storage)
```

#### Attach storage volume to a server
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
storage = master.attach_storage_volume(project_id=46776, storage_id=377447, server_id="377441")

print("Storage attached to: %s" % storage["attached_to"]["href"])
```

#### Detach storage volume from a server
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
storage = master.detach_storage_volume(project_id=46776, storage_id=377447)

print("Storage detached")
```
#### Increase storage volume size
```
import cherry
import json

master = cherry.Master(auth_token="api_token")
size_in_gb = 200
storage = master.update_storage_volume(project_id=46776, storage_id=377457, size=size_in_gb)

print("Storage size upgraded")
```
Loading