Class: MythicBeasts::VPS

Inherits:
Object
  • Object
show all
Defined in:
lib/mythic_beasts/vps.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ VPS

Returns a new instance of VPS.



5
6
7
# File 'lib/mythic_beasts/vps.rb', line 5

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/mythic_beasts/vps.rb', line 3

def client
  @client
end

Instance Method Details

#console(server_name) ⇒ Object

Get VPS console access



103
104
105
# File 'lib/mythic_beasts/vps.rb', line 103

def console(server_name)
  client.get("/api/vps/#{server_name}/console")
end

#create(product:, name: nil, ssh_keys: nil, **options) ⇒ Object

Create a new VPS Options:

- product: Server product (e.g., 'VPS-1', 'VPS-2') - REQUIRED
- name: Friendly name for the server
- hostname: Hostname for the server
- ssh_keys: SSH public key(s) for access
- zone: Datacentre code (e.g., 'london', 'cambridge')
- ipv4: Boolean - allocate IPv4 address (default true)
- image: Operating system image name
- disk_size: Disk size in MB
And other optional parameters...


40
41
42
43
44
45
46
47
48
49
# File 'lib/mythic_beasts/vps.rb', line 40

def create(product:, name: nil, ssh_keys: nil, **options)
  body = {
    product: product,
    **options
  }
  body[:name] = name if name
  body[:ssh_keys] = ssh_keys if ssh_keys

  client.post("/beta/vps/servers", body: body)
end

#create_with_identifier(identifier, product:, name: nil, ssh_keys: nil, **options) ⇒ Object

Create a new VPS with a custom identifier Returns 409 Conflict if identifier already exists Options are same as create method



54
55
56
57
58
59
60
61
62
63
# File 'lib/mythic_beasts/vps.rb', line 54

def create_with_identifier(identifier, product:, name: nil, ssh_keys: nil, **options)
  body = {
    product: product,
    **options
  }
  body[:name] = name if name
  body[:ssh_keys] = ssh_keys if ssh_keys

  client.post("/beta/vps/servers/#{identifier}", body: body)
end

#delete(server_name) ⇒ Object

Delete a VPS



93
94
95
# File 'lib/mythic_beasts/vps.rb', line 93

def delete(server_name)
  client.delete("/api/vps/#{server_name}")
end

#disk_sizesObject

List available disk sizes Returns hash with ‘ssd’ and ‘hdd’ keys containing arrays of sizes in MB



125
126
127
# File 'lib/mythic_beasts/vps.rb', line 125

def disk_sizes
  client.get("/beta/vps/disk-sizes")
end

#get(server_name) ⇒ Object

Get details of a specific VPS



20
21
22
# File 'lib/mythic_beasts/vps.rb', line 20

def get(server_name)
  client.get("/api/vps/#{server_name}")
end

#imagesObject

List available OS images for VPS provisioning



119
120
121
# File 'lib/mythic_beasts/vps.rb', line 119

def images
  client.get("/beta/vps/images")
end

#iso_images(server_identifier) ⇒ Object

List available ISO images for a specific server These can be mounted to the server for manual OS installation



109
110
111
# File 'lib/mythic_beasts/vps.rb', line 109

def iso_images(server_identifier)
  client.get("/beta/vps/servers/#{server_identifier}/iso-images")
end

#listObject

List all VPS servers



10
11
12
# File 'lib/mythic_beasts/vps.rb', line 10

def list
  client.get("/api/vps")
end

#productsObject

List available products



130
131
132
# File 'lib/mythic_beasts/vps.rb', line 130

def products
  client.get("/beta/vps/products")
end

#reboot(identifier) ⇒ Object

Reboot a VPS by identifier (newer endpoint)



81
82
83
# File 'lib/mythic_beasts/vps.rb', line 81

def reboot(identifier)
  client.post("/vps/servers/#{identifier}/reboot")
end

#restart(server_name) ⇒ Object

Restart a VPS



76
77
78
# File 'lib/mythic_beasts/vps.rb', line 76

def restart(server_name)
  client.post("/api/vps/#{server_name}/restart")
end

#server(identifier) ⇒ Object

Get details of a specific VPS by identifier (newer endpoint)



25
26
27
# File 'lib/mythic_beasts/vps.rb', line 25

def server(identifier)
  client.get("/vps/servers/#{identifier}")
end

#serversObject

List all VPS servers (newer endpoint)



15
16
17
# File 'lib/mythic_beasts/vps.rb', line 15

def servers
  client.get("/vps/servers")
end

#start(server_name) ⇒ Object

Start a VPS



66
67
68
# File 'lib/mythic_beasts/vps.rb', line 66

def start(server_name)
  client.post("/api/vps/#{server_name}/start")
end

#stop(server_name) ⇒ Object

Stop a VPS



71
72
73
# File 'lib/mythic_beasts/vps.rb', line 71

def stop(server_name)
  client.post("/api/vps/#{server_name}/stop")
end

#unprovision(identifier) ⇒ Object

Unprovision (permanently delete) a VPS by identifier (newer endpoint)



98
99
100
# File 'lib/mythic_beasts/vps.rb', line 98

def unprovision(identifier)
  client.delete("/beta/vps/servers/#{identifier}")
end

#update(identifier, **options) ⇒ Object

Update a VPS (e.g., mount ISO image) Options:

- iso_image: ISO image name to mount


88
89
90
# File 'lib/mythic_beasts/vps.rb', line 88

def update(identifier, **options)
  client.patch("/vps/servers/#{identifier}", body: options)
end

#zonesObject

List available zones/datacenters for VPS provisioning



114
115
116
# File 'lib/mythic_beasts/vps.rb', line 114

def zones
  client.get("/beta/vps/zones")
end