Class: Ubicloud::Postgres

Inherits:
Model
  • Object
show all
Defined in:
lib/ubicloud/model/postgres.rb

Instance Attribute Summary

Attributes inherited from Model

#adapter, #values

Instance Method Summary collapse

Methods inherited from Model

[], #[], #check_exists, create, #destroy, #id, #info, #initialize, #inspect, list, #location, #name, resolve_associations, #to_h

Constructor Details

This class inherits a constructor from Ubicloud::Model

Instance Method Details

#add_firewall_rule(cidr) ⇒ Object

Allow the given cidr (ip address range) access to the PostgreSQL database port (5432) for this database. Returns a hash for the firewall rule.



22
23
24
25
26
27
28
# File 'lib/ubicloud/model/postgres.rb', line 22

def add_firewall_rule(cidr)
  rule = adapter.post(_path("/firewall-rule"), cidr:)

  self[:firewall_rules]&.<<(rule)

  rule
end

#add_metric_destination(username:, password:, url:) ⇒ Object

Add a metric destination for this database with the given username, password, and URL. Returns a hash for the metric destination.



42
43
44
45
46
47
48
# File 'lib/ubicloud/model/postgres.rb', line 42

def add_metric_destination(username:, password:, url:)
  md = adapter.post(_path("/metric-destination"), username:, password:, url:)

  self[:metric_destinations]&.<<(md)

  md
end

#delete_firewall_rule(rule_id) ⇒ Object

Delete the firewall rule with the given id. Returns nil.



31
32
33
34
35
36
37
38
# File 'lib/ubicloud/model/postgres.rb', line 31

def delete_firewall_rule(rule_id)
  check_no_slash(rule_id, "invalid rule id format")
  adapter.delete(_path("/firewall-rule/#{rule_id}"))

  self[:firewall_rules]&.delete_if { _1[:id] == rule_id }

  nil
end

#delete_metric_destination(md_id) ⇒ Object

Delete the metric destination with the given id. Returns nil.



51
52
53
54
55
56
57
58
# File 'lib/ubicloud/model/postgres.rb', line 51

def delete_metric_destination(md_id)
  check_no_slash(md_id, "invalid metric destination id format")
  adapter.delete(_path("/metric-destination/#{md_id}"))

  self[:metric_destinations]&.delete_if { _1[:id] == md_id }

  nil
end

#reset_superuser_password(password) ⇒ Object

Schedule a password reset for the database superuser (postgres) for the database. Returns self.



62
63
64
# File 'lib/ubicloud/model/postgres.rb', line 62

def reset_superuser_password(password)
  merge_into_values(adapter.post(_path("/reset-superuser-password"), password:))
end

#restartObject

Schedule a restart of the PostgreSQL server. Returns self.



16
17
18
# File 'lib/ubicloud/model/postgres.rb', line 16

def restart
  merge_into_values(adapter.post(_path("/restart")))
end

#restore(name:, restore_target:) ⇒ Object

Schedule a restore of the database at the given restore_target time, to a new database with the given name. Returns a Postgres instance for the restored database.



69
70
71
# File 'lib/ubicloud/model/postgres.rb', line 69

def restore(name:, restore_target:)
  Postgres.new(adapter, adapter.post(_path("/restore"), name:, restore_target:))
end