hcloud-ruby icon indicating copy to clipboard operation
hcloud-ruby copied to clipboard

[Enhancement] Add missing fields / endpoints to Images + Servers

Open Kjarrigan opened this issue 3 years ago • 1 comments

  • Images have Actions
  • Servers have metrics and can change it's rDNS

Kjarrigan avatar Feb 18 '22 06:02 Kjarrigan

Server also as a bunch of more attributes:

  • [x] id
  • [x] created
  • [x] image
  • [x] server_type
  • [x] datacenter
  • [x] included_traffic
  • [x] ingoing_traffic
  • [x] outgoing_traffic
  • [x] locked
  • [x] name
  • [x] primary_disk_size
  • [x] rescue_enabled
  • [x] status
  • [ ] backup_window
  • [ ] iso
  • [ ] labels (currently hash)
  • [ ] load_balancers (currently array)
  • [ ] placement_group
  • [ ] private_net (currently array)
  • [ ] protection ({"delete"=>false, "rebuild"=>false})
  • [ ] public_net (currently hash)
  • [ ] volumes (currently list)

At least load_balancers, private_net, public_net and volumes are collections of resources. The schema defined in entry_loader.rb maps the api response to objects, can't handle collections AFAIK. Either we extend the schema, create a collection resource for each one (VolumesCollection containing Volume objects) or create a generic Collection than can be initialized with the wanted resource schema(volumes: Collection(Volume)).

RaphaelPour avatar Feb 18 '22 09:02 RaphaelPour

Went through the API docs and the code and found the following missing actions:

  • Network
    • change_ip_range
  • Server
    • Get metrics
    • add_to_placement_group
    • change_alias_ips
    • change_dns_ptr
    • remove_from_placement_group

The following attributes on existing actions are missing

  • Firewall
    • labels on update
  • Floating IPs
    • name on create
    • name, labels on update
  • Image
    • status, include_deprecated on get all
    • labels on update
  • Network
    • labels on update
  • Placement Groups
    • label_selector on get all
    • labels on update
  • Server
    • automount, firewalls, placement_group, public_net, volumes on create
    • labels on update
  • SSH key
    • fingerprint on get all
    • labels on update
  • Volume
    • status on get all
    • labels on update

ghost avatar Dec 13 '22 15:12 ghost

It's probably good that the labels fields on :updatable are missing. I just checked what this does, because update(labels: {'foo': 'bar'}) works without problems. :updatable creates attr= methods, so fields can be changed with obj.name = 'new-name'. The changes can then be persisted using obj.save:

obj = client.load_balancers['old-name']
obj.name = 'new-name'
obj.save
# besides: call to save is currently broken, so nobody uses this feature

# alternative (which works):
obj.update({ name: 'new-name' })

For labels being a hash this does not work as expected (at least as I as a user would want to use it). The following code does not save the new label to the Cloud API.

obj = client.load_balancers['old-name']
obj.labels.merge({ 'label' => 'value' })
obj.save

tl;dr: I think we'll have to think a bit more about :updatable to make it work with objects (like hashes) that can be changed in other ways than assignments.

ghost avatar Dec 14 '22 13:12 ghost