Files
ubicloud/lib/hosting/apis.rb
Furkan Sahin b48756e163 Replace references of HetznerHost with HostProvider
We are replacing the HetznerHost references with HostProvider so that we
can support multiple provider entities with a single reference. This
way, we will be able to implement further provider APIs without
requiring individual provider model references.
2025-01-31 14:24:34 +01:00

49 lines
1.6 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# frozen_string_literal: true
require "excon"
class Hosting::Apis
def self.pull_ips(vm_host)
if vm_host.provider_name == HostProvider::HETZNER_PROVIDER_NAME
vm_host.provider.api.pull_ips
else
raise "unknown provider #{vm_host.provider_name}"
end
end
def self.reimage_server(vm_host)
if vm_host.provider_name == HostProvider::HETZNER_PROVIDER_NAME
vm_host.provider.api.reimage(vm_host.provider.server_identifier)
else
raise "unknown provider #{vm_host.provider_name}"
end
end
# Cuts power to a Server and starts it again. This forcefully stops it
# without giving the Server operating system time to gracefully stop. This
# may lead to data loss, its equivalent to pulling the power cord and
# plugging it in again. Reset should only be used when reboot does not work.
def self.hardware_reset_server(vm_host)
if vm_host.provider_name == HostProvider::HETZNER_PROVIDER_NAME
vm_host.provider.api.reset(vm_host.provider.server_identifier)
else
raise "unknown provider #{vm_host.provider_name}"
end
end
def self.pull_data_center(vm_host)
if vm_host.provider_name == HostProvider::HETZNER_PROVIDER_NAME
vm_host.provider.api.pull_dc(vm_host.provider.server_identifier)
else
raise "unknown provider #{vm_host.provider_name}"
end
end
def self.set_server_name(vm_host)
if vm_host.provider_name == HostProvider::HETZNER_PROVIDER_NAME
vm_host.provider.api.set_server_name(vm_host.provider.server_identifier, vm_host.ubid)
else
raise "unknown provider #{vm_host.provider_name}"
end
end
end