From ee58967e96b5c1eb3573feccf918ca75902167d3 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Tue, 1 Feb 2022 17:03:48 +0100 Subject: [PATCH] M #-: add more methods to Vultr API (#1729) (cherry picked from commit f1da69b04a6f3a438db08ef882f26d89fd05d3ba) --- .../provider_apis/vultr/lib/vultr.rb | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/oneprovision/provider_apis/vultr/lib/vultr.rb b/src/oneprovision/provider_apis/vultr/lib/vultr.rb index 1fd896e1e4..f07c03f6a7 100644 --- a/src/oneprovision/provider_apis/vultr/lib/vultr.rb +++ b/src/oneprovision/provider_apis/vultr/lib/vultr.rb @@ -47,6 +47,9 @@ class Vultr # API instances URL INSTANCE_URL = "#{BASE_URL}/instances" + # API bare-metal instances + BAREMETAL_URL = "#{BASE_URL}/bare-metals" + # API networks URL NETWORK_URL = "#{BASE_URL}/reserved-ips" @@ -60,10 +63,33 @@ class Vultr @key = key end + ############################################################################ + # Baremetal Methods + ############################################################################ + def list_metals + get(BAREMETAL_URL) + end + + # Delete baremetal + # + # @param id [String] Baremetal ID + # + # @return [Nil, Error] nil if no error, error othwerise + def delete_metal(id) + delete("#{BAREMETAL_URL}/#{id}") + end + ############################################################################ # Instances Methods ############################################################################ + # List instances + # + # @return [Hash, Error] hash with instances, error otherwise + def list_instances + get(INSTANCE_URL) + end + # Get instances information # # @param id [String] Instances ID @@ -77,6 +103,15 @@ class Vultr JSON.parse(rc)['instance'] end + # Delete instance + # + # @param id [String] Instances ID + # + # @return [Nil, Error] nil if no error, error othwerise + def delete_instance(id) + delete("#{INSTANCE_URL}/#{id}") + end + # Attach Reserved IP to an Instance # # @param id [String] Instance ID @@ -107,6 +142,13 @@ class Vultr # Network methods ############################################################################ + # List IPs + # + # @return [Hash, Error] hash with IPs, error otherwise + def list_ips + get(NETWORK_URL) + end + # Create a new Reserved IP in a region # # @param region [String] Create the Reserved IP in this Region id