vultr 0.4.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +32 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +5 -10
- data/README.md +306 -136
- data/Rakefile +10 -6
- data/bin/console +21 -0
- data/bin/setup +8 -0
- data/bin/test +6 -0
- data/lib/vultr/client.rb +111 -0
- data/lib/vultr/collection.rb +22 -0
- data/lib/vultr/error.rb +4 -0
- data/lib/vultr/object.rb +19 -0
- data/lib/vultr/objects/account.rb +4 -0
- data/lib/vultr/objects/application.rb +4 -0
- data/lib/vultr/objects/backup.rb +4 -0
- data/lib/vultr/objects/bare_metal.rb +4 -0
- data/lib/vultr/objects/block_storage.rb +4 -0
- data/lib/vultr/objects/domain.rb +4 -0
- data/lib/vultr/objects/firewall_group.rb +4 -0
- data/lib/vultr/objects/instance.rb +4 -0
- data/lib/vultr/objects/iso.rb +4 -0
- data/lib/vultr/objects/kubernetes_cluster.rb +4 -0
- data/lib/vultr/objects/load_balancer.rb +4 -0
- data/lib/vultr/objects/object_storage.rb +4 -0
- data/lib/vultr/objects/operating_system.rb +4 -0
- data/lib/vultr/objects/plan.rb +4 -0
- data/lib/vultr/objects/private_network.rb +4 -0
- data/lib/vultr/objects/region.rb +4 -0
- data/lib/vultr/objects/reserved_ip.rb +4 -0
- data/lib/vultr/objects/snapshot.rb +4 -0
- data/lib/vultr/objects/ssh_key.rb +4 -0
- data/lib/vultr/objects/startup_script.rb +4 -0
- data/lib/vultr/objects/user.rb +4 -0
- data/lib/vultr/resource.rb +52 -0
- data/lib/vultr/resources/account.rb +7 -0
- data/lib/vultr/resources/applications.rb +8 -0
- data/lib/vultr/resources/backups.rb +12 -0
- data/lib/vultr/resources/bare_metal.rb +79 -0
- data/lib/vultr/resources/block_storage.rb +32 -0
- data/lib/vultr/resources/dns.rb +58 -0
- data/lib/vultr/resources/firewall.rb +42 -0
- data/lib/vultr/resources/instances.rb +145 -0
- data/lib/vultr/resources/iso.rb +25 -0
- data/lib/vultr/resources/kubernetes.rb +61 -0
- data/lib/vultr/resources/load_balancers.rb +50 -0
- data/lib/vultr/resources/object_storage.rb +33 -0
- data/lib/vultr/resources/operating_systems.rb +8 -0
- data/lib/vultr/resources/plans.rb +13 -0
- data/lib/vultr/resources/private_networks.rb +24 -0
- data/lib/vultr/resources/regions.rb +12 -0
- data/lib/vultr/resources/reserved_ips.rb +32 -0
- data/lib/vultr/resources/snapshots.rb +28 -0
- data/lib/vultr/resources/ssh_keys.rb +24 -0
- data/lib/vultr/resources/startup_scripts.rb +24 -0
- data/lib/vultr/resources/users.rb +24 -0
- data/lib/vultr/version.rb +1 -8
- data/lib/vultr.rb +56 -887
- data/test/fixtures/account/info.json +11 -0
- data/test/fixtures/applications/list.json +29 -0
- data/test/fixtures/backups/list.json +18 -0
- data/test/fixtures/backups/retrieve.json +9 -0
- data/test/fixtures/bare_metals/bandwidth.json +12 -0
- data/test/fixtures/bare_metals/create.json +26 -0
- data/test/fixtures/bare_metals/list.json +36 -0
- data/test/fixtures/bare_metals/list_ipv4.json +18 -0
- data/test/fixtures/bare_metals/list_ipv6.json +17 -0
- data/test/fixtures/bare_metals/reinstall.json +25 -0
- data/test/fixtures/bare_metals/retrieve.json +26 -0
- data/test/fixtures/bare_metals/update.json +26 -0
- data/test/fixtures/bare_metals/upgrades.json +47 -0
- data/test/fixtures/bare_metals/user_data.json +5 -0
- data/test/fixtures/bare_metals/vnc.json +5 -0
- data/test/fixtures/block_storage/attach.json +4 -0
- data/test/fixtures/block_storage/create.json +13 -0
- data/test/fixtures/block_storage/detach.json +4 -0
- data/test/fixtures/block_storage/list.json +22 -0
- data/test/fixtures/block_storage/retrieve.json +13 -0
- data/test/fixtures/domains/create.json +6 -0
- data/test/fixtures/domains/dnssec.json +7 -0
- data/test/fixtures/domains/list.json +15 -0
- data/test/fixtures/domains/record.json +10 -0
- data/test/fixtures/domains/records.json +19 -0
- data/test/fixtures/domains/retrieve.json +6 -0
- data/test/fixtures/domains/soa.json +6 -0
- data/test/fixtures/firewall/create.json +11 -0
- data/test/fixtures/firewall/create_rule.json +9 -0
- data/test/fixtures/firewall/delete.json +1 -0
- data/test/fixtures/firewall/delete_rule.json +1 -0
- data/test/fixtures/firewall/list.json +20 -0
- data/test/fixtures/firewall/list_rules.json +22 -0
- data/test/fixtures/firewall/retrieve.json +11 -0
- data/test/fixtures/firewall/retrieve_rule.json +13 -0
- data/test/fixtures/firewall/update.json +1 -0
- data/test/fixtures/instances/attach_iso.json +6 -0
- data/test/fixtures/instances/attach_private_network.json +1 -0
- data/test/fixtures/instances/backup_schedule.json +10 -0
- data/test/fixtures/instances/bandwidth.json +12 -0
- data/test/fixtures/instances/create.json +36 -0
- data/test/fixtures/instances/create_ipv4_reverse.json +1 -0
- data/test/fixtures/instances/create_ipv6_reverse.json +1 -0
- data/test/fixtures/instances/delete.json +1 -0
- data/test/fixtures/instances/delete_ipv4.json +1 -0
- data/test/fixtures/instances/delete_ipv6.json +1 -0
- data/test/fixtures/instances/detach_iso.json +5 -0
- data/test/fixtures/instances/detach_private_network.json +1 -0
- data/test/fixtures/instances/halt.json +1 -0
- data/test/fixtures/instances/halt_instances.json +1 -0
- data/test/fixtures/instances/ipv4.json +9 -0
- data/test/fixtures/instances/ipv6_reverse.json +15 -0
- data/test/fixtures/instances/iso.json +6 -0
- data/test/fixtures/instances/list.json +44 -0
- data/test/fixtures/instances/list_ipv4.json +32 -0
- data/test/fixtures/instances/list_ipv6.json +17 -0
- data/test/fixtures/instances/list_private_networks.json +16 -0
- data/test/fixtures/instances/neighbors.json +6 -0
- data/test/fixtures/instances/reboot.json +1 -0
- data/test/fixtures/instances/reboot_instances.json +1 -0
- data/test/fixtures/instances/reinstall.json +35 -0
- data/test/fixtures/instances/restore.json +7 -0
- data/test/fixtures/instances/retrieve.json +35 -0
- data/test/fixtures/instances/set_backup_schedule.json +1 -0
- data/test/fixtures/instances/set_default_reverse_dns_entry.json +1 -0
- data/test/fixtures/instances/start.json +1 -0
- data/test/fixtures/instances/start_instances.json +1 -0
- data/test/fixtures/instances/update.json +1 -0
- data/test/fixtures/instances/upgrades.json +55 -0
- data/test/fixtures/instances/user_data.json +5 -0
- data/test/fixtures/isos/create.json +8 -0
- data/test/fixtures/isos/list.json +20 -0
- data/test/fixtures/isos/list_public.json +17 -0
- data/test/fixtures/isos/retrieve.json +11 -0
- data/test/fixtures/kubernetes/config.json +3 -0
- data/test/fixtures/kubernetes/create.json +39 -0
- data/test/fixtures/kubernetes/create_node_pool.json +25 -0
- data/test/fixtures/kubernetes/list.json +85 -0
- data/test/fixtures/kubernetes/list_node_pools.json +56 -0
- data/test/fixtures/kubernetes/list_resources.json +26 -0
- data/test/fixtures/kubernetes/retrieve.json +39 -0
- data/test/fixtures/kubernetes/retrieve_node_pool.json +25 -0
- data/test/fixtures/kubernetes/update_node_pool.json +19 -0
- data/test/fixtures/load_balancers/create.json +48 -0
- data/test/fixtures/load_balancers/create_forwarding_rule.json +1 -0
- data/test/fixtures/load_balancers/delete.json +1 -0
- data/test/fixtures/load_balancers/delete_forwarding_rule.json +1 -0
- data/test/fixtures/load_balancers/list.json +57 -0
- data/test/fixtures/load_balancers/list_firewall_rules.json +17 -0
- data/test/fixtures/load_balancers/list_forwarding_rules.json +18 -0
- data/test/fixtures/load_balancers/retrieve.json +48 -0
- data/test/fixtures/load_balancers/retrieve_firewall_rule.json +8 -0
- data/test/fixtures/load_balancers/retrieve_forwarding_rule.json +9 -0
- data/test/fixtures/load_balancers/update.json +1 -0
- data/test/fixtures/object_storage/create.json +14 -0
- data/test/fixtures/object_storage/delete.json +1 -0
- data/test/fixtures/object_storage/list.json +22 -0
- data/test/fixtures/object_storage/list_clusters.json +17 -0
- data/test/fixtures/object_storage/regenerate_keys.json +7 -0
- data/test/fixtures/object_storage/retrieve.json +13 -0
- data/test/fixtures/object_storage/update.json +1 -0
- data/test/fixtures/operating_systems/list.json +17 -0
- data/test/fixtures/plans/list.json +22 -0
- data/test/fixtures/plans/list_metal.json +24 -0
- data/test/fixtures/private_networks/create.json +10 -0
- data/test/fixtures/private_networks/delete.json +1 -0
- data/test/fixtures/private_networks/list.json +19 -0
- data/test/fixtures/private_networks/retrieve.json +10 -0
- data/test/fixtures/private_networks/update.json +1 -0
- data/test/fixtures/regions/list.json +20 -0
- data/test/fixtures/regions/list_availability.json +24 -0
- data/test/fixtures/reserved_ips/attach.json +1 -0
- data/test/fixtures/reserved_ips/convert.json +11 -0
- data/test/fixtures/reserved_ips/create.json +11 -0
- data/test/fixtures/reserved_ips/delete.json +1 -0
- data/test/fixtures/reserved_ips/detach.json +1 -0
- data/test/fixtures/reserved_ips/list.json +29 -0
- data/test/fixtures/reserved_ips/retrieve.json +11 -0
- data/test/fixtures/snapshots/create.json +11 -0
- data/test/fixtures/snapshots/create_from_url.json +11 -0
- data/test/fixtures/snapshots/delete.json +1 -0
- data/test/fixtures/snapshots/list.json +20 -0
- data/test/fixtures/snapshots/retrieve.json +11 -0
- data/test/fixtures/snapshots/update.json +1 -0
- data/test/fixtures/ssh_keys/create.json +8 -0
- data/test/fixtures/ssh_keys/delete.json +1 -0
- data/test/fixtures/ssh_keys/list.json +17 -0
- data/test/fixtures/ssh_keys/retrieve.json +8 -0
- data/test/fixtures/ssh_keys/update.json +1 -0
- data/test/fixtures/startup_scripts/create.json +10 -0
- data/test/fixtures/startup_scripts/delete.json +1 -0
- data/test/fixtures/startup_scripts/list.json +18 -0
- data/test/fixtures/startup_scripts/retrieve.json +10 -0
- data/test/fixtures/startup_scripts/update.json +1 -0
- data/test/fixtures/users/create.json +9 -0
- data/test/fixtures/users/delete.json +1 -0
- data/test/fixtures/users/list.json +29 -0
- data/test/fixtures/users/retrieve.json +20 -0
- data/test/fixtures/users/update.json +1 -0
- data/test/test_helper.rb +18 -5
- data/test/vultr/client_test.rb +8 -0
- data/test/vultr/object_test.rb +21 -0
- data/test/vultr/resources/account_test.rb +12 -0
- data/test/vultr/resources/applications_test.rb +15 -0
- data/test/vultr/resources/backups_test.rb +24 -0
- data/test/vultr/resources/bare_metal_test.rb +267 -0
- data/test/vultr/resources/block_storage_test.rb +85 -0
- data/test/vultr/resources/dns_test.rb +134 -0
- data/test/vultr/resources/firewall_test.rb +88 -0
- data/test/vultr/resources/instances_test.rb +325 -0
- data/test/vultr/resources/iso_test.rb +58 -0
- data/test/vultr/resources/kubernetes_test.rb +185 -0
- data/test/vultr/resources/load_balancers_test.rb +110 -0
- data/test/vultr/resources/object_storage_test.rb +71 -0
- data/test/vultr/resources/operating_systems_test.rb +15 -0
- data/test/vultr/resources/plans_test.rb +25 -0
- data/test/vultr/resources/private_networks_test.rb +50 -0
- data/test/vultr/resources/regions_test.rb +26 -0
- data/test/vultr/resources/reserved_ips_test.rb +67 -0
- data/test/vultr/resources/snapshots_test.rb +60 -0
- data/test/vultr/resources/ssh_keys_test.rb +50 -0
- data/test/vultr/resources/startup_scripts_test.rb +50 -0
- data/test/vultr/resources/users_test.rb +50 -0
- data/vultr.gemspec +17 -17
- metadata +394 -48
- data/test/vultr/vultr_account_test.rb +0 -29
- data/test/vultr/vultr_app_test.rb +0 -26
- data/test/vultr/vultr_backup_test.rb +0 -22
- data/test/vultr/vultr_iso_test.rb +0 -27
- data/test/vultr/vultr_os_test.rb +0 -21
- data/test/vultr/vultr_plan_test.rb +0 -22
- data/test/vultr/vultr_region_test.rb +0 -33
- data/test/vultr/vultr_snapshot_test.rb +0 -30
- data/test/vultr/vultr_sshkey_test.rb +0 -50
- data/test/vultr/vultr_startupscript_test.rb +0 -53
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class FirewallResourceTest < Minitest::Test
|
6
|
+
def test_list
|
7
|
+
stub = stub_request("firewalls", response: stub_response(fixture: "firewall/list"))
|
8
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
9
|
+
firewall_group = client.firewall.list
|
10
|
+
|
11
|
+
assert_equal Vultr::Collection, firewall_group.class
|
12
|
+
assert_equal Vultr::FirewallGroup, firewall_group.data.first.class
|
13
|
+
assert_equal 1, firewall_group.total
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
body = {description: "Example Firewall Group"}
|
18
|
+
stub = stub_request("firewalls", method: :post, body: body, response: stub_response(fixture: "firewall/create"))
|
19
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
20
|
+
firewall_group = client.firewall.create(**body)
|
21
|
+
|
22
|
+
assert_equal Vultr::FirewallGroup, firewall_group.class
|
23
|
+
assert_equal "Example Firewall Group", firewall_group.description
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_retrieve
|
27
|
+
id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
28
|
+
stub = stub_request("firewalls/#{id}", response: stub_response(fixture: "firewall/retrieve"))
|
29
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
30
|
+
firewall_group = client.firewall.retrieve(firewall_group_id: id)
|
31
|
+
|
32
|
+
assert_equal Vultr::FirewallGroup, firewall_group.class
|
33
|
+
assert_equal "Example Firewall Group", firewall_group.description
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_update
|
37
|
+
id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
38
|
+
body = {description: "Example Firewall Group"}
|
39
|
+
stub = stub_request("firewalls/#{id}", method: :put, body: body, response: stub_response(fixture: "firewall/update"))
|
40
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
41
|
+
assert client.firewall.update(firewall_group_id: id, **body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_delete
|
45
|
+
id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
46
|
+
stub = stub_request("firewalls/#{id}", method: :delete, response: stub_response(fixture: "firewall/delete"))
|
47
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
48
|
+
assert client.firewall.delete(firewall_group_id: id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_list_rules
|
52
|
+
id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
53
|
+
stub = stub_request("firewalls/#{id}/rules", response: stub_response(fixture: "firewall/list_rules"))
|
54
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
55
|
+
rules = client.firewall.list_rules(firewall_group_id: id)
|
56
|
+
|
57
|
+
assert Vultr::Collection, rules.class
|
58
|
+
assert Vultr::Object, rules.data.first.class
|
59
|
+
assert 1, rules.total
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_create_rule
|
63
|
+
id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
64
|
+
body = {ip_type: "v4", protocol: "tcp", subnet: "192.0.2.0", subnet_size: 24}
|
65
|
+
stub = stub_request("firewalls/#{id}/rules", method: :post, body: body, response: stub_response(fixture: "firewall/create_rule"))
|
66
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
67
|
+
assert client.firewall.create_rule(firewall_group_id: id, **body)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_retrieve_rule
|
71
|
+
firewall_id = "id"
|
72
|
+
rule_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
73
|
+
stub = stub_request("firewalls/#{firewall_id}/rules/#{rule_id}", response: stub_response(fixture: "firewall/retrieve_rule"))
|
74
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
75
|
+
rule = client.firewall.retrieve_rule(firewall_group_id: firewall_id, firewall_rule_id: rule_id)
|
76
|
+
|
77
|
+
assert Vultr::Object, rule.class
|
78
|
+
assert "tcp", rule.protocol
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_delete_forwarding_rule
|
82
|
+
firewall_id = "id"
|
83
|
+
rule_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
84
|
+
stub = stub_request("firewalls/#{firewall_id}/rules/#{rule_id}", method: :delete, response: stub_response(fixture: "firewall/delete_rule"))
|
85
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
86
|
+
assert client.firewall.delete_rule(firewall_group_id: firewall_id, firewall_rule_id: rule_id)
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,325 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class InstancesResourceTest < Minitest::Test
|
6
|
+
def test_list
|
7
|
+
stub = stub_request("instances", response: stub_response(fixture: "instances/list", status: 200))
|
8
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
9
|
+
instances = client.instances.list
|
10
|
+
|
11
|
+
assert_equal Vultr::Collection, instances.class
|
12
|
+
assert_equal Vultr::Instance, instances.data.first.class
|
13
|
+
assert_equal 3, instances.total
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
body = {region: "ewr", plan: "vc2-6c-16gb", label: "Example Instance", os_id: 215, user_data: "QmFzZTY0IEV4YW1wbGUgRGF0YQ==", backups: "enabled"}
|
18
|
+
stub = stub_request("instances", method: :post, body: body, response: stub_response(fixture: "instances/create", status: 202))
|
19
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
20
|
+
instance = client.instances.create(**body)
|
21
|
+
|
22
|
+
assert_equal Vultr::Instance, instance.class
|
23
|
+
assert_equal "Example Instance", instance.label
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_retrieve
|
27
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
28
|
+
stub = stub_request("instances/#{instance_id}", response: stub_response(fixture: "instances/retrieve"))
|
29
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
30
|
+
instance = client.instances.retrieve(instance_id: instance_id)
|
31
|
+
|
32
|
+
assert_equal Vultr::Instance, instance.class
|
33
|
+
assert_equal "Example Instance", instance.label
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_update
|
37
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
38
|
+
body = {label: "Example Instance", tag: "Example Tag", plan: "vc2-24c-97gb"}
|
39
|
+
stub = stub_request("instances/#{instance_id}", method: :patch, body: body, response: stub_response(fixture: "instances/update", status: 202))
|
40
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
41
|
+
assert client.instances.update(instance_id: instance_id, **body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_delete
|
45
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
46
|
+
stub = stub_request("instances/#{instance_id}", method: :delete, response: stub_response(fixture: "instances/delete", status: 204))
|
47
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
48
|
+
assert client.instances.delete(instance_id: instance_id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_start
|
52
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
53
|
+
stub = stub_request("instances/#{instance_id}/start", method: :post, response: stub_response(fixture: "instances/start", status: 204))
|
54
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
55
|
+
assert client.instances.start(instance_id: instance_id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_reboot
|
59
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
60
|
+
stub = stub_request("instances/#{instance_id}/reboot", method: :post, response: stub_response(fixture: "instances/reboot", status: 204))
|
61
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
62
|
+
assert client.instances.reboot(instance_id: instance_id)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_reinstall
|
66
|
+
body = {hostname: "Example Instance"}
|
67
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
68
|
+
stub = stub_request("instances/#{instance_id}/reinstall", method: :post, body: body, response: stub_response(fixture: "instances/reinstall", status: 204))
|
69
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
70
|
+
instance = client.instances.reinstall(instance_id: instance_id, **body)
|
71
|
+
|
72
|
+
assert_equal Vultr::Instance, instance.class
|
73
|
+
assert_equal "Example Instance", instance.label
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_restore
|
77
|
+
body = {backup_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
|
78
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
79
|
+
stub = stub_request("instances/#{instance_id}/restore", method: :post, body: body, response: stub_response(fixture: "instances/restore", status: 202))
|
80
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
81
|
+
instance = client.instances.restore(instance_id: instance_id, **body)
|
82
|
+
|
83
|
+
assert_equal Vultr::Object, instance.class
|
84
|
+
assert_equal "backup_id", instance.restore_type
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_halt
|
88
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
89
|
+
stub = stub_request("instances/#{instance_id}/halt", method: :post, response: stub_response(fixture: "instances/halt", status: 204))
|
90
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
91
|
+
assert client.instances.halt(instance_id: instance_id)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_bandwidth
|
95
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
96
|
+
stub = stub_request("instances/#{instance_id}/bandwidth", response: stub_response(fixture: "instances/bandwidth"))
|
97
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
98
|
+
instance = client.instances.bandwidth(instance_id: instance_id)
|
99
|
+
|
100
|
+
assert_equal Vultr::Object, instance.class
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_neighbors
|
104
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
105
|
+
stub = stub_request("instances/#{instance_id}/neighbors", response: stub_response(fixture: "instances/neighbors"))
|
106
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
107
|
+
instance = client.instances.neighbors(instance_id: instance_id)
|
108
|
+
|
109
|
+
assert_equal Array, instance.class
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_user_data
|
113
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
114
|
+
stub = stub_request("instances/#{instance_id}/user-data", response: stub_response(fixture: "instances/user_data"))
|
115
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
116
|
+
instance = client.instances.user_data(instance_id: instance_id)
|
117
|
+
|
118
|
+
assert_equal Vultr::Object, instance.class
|
119
|
+
assert_equal "QmFzZTY0IEV4YW1wbGUgRGF0YQ==", instance.data
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_upgrades
|
123
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
124
|
+
stub = stub_request("instances/#{instance_id}/upgrades", response: stub_response(fixture: "instances/upgrades"))
|
125
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
126
|
+
instance = client.instances.upgrades(instance_id: instance_id)
|
127
|
+
|
128
|
+
assert_equal Vultr::Object, instance.class
|
129
|
+
assert_equal "Example CentOS 6 x64", instance.os.first["name"]
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_list_ipv4
|
133
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
134
|
+
stub = stub_request("instances/#{instance_id}/ipv4", response: stub_response(fixture: "instances/list_ipv4"))
|
135
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
136
|
+
instance = client.instances.list_ipv4(instance_id: instance_id)
|
137
|
+
|
138
|
+
assert_equal Vultr::Collection, instance.class
|
139
|
+
assert_equal 3, instance.total
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_create_ipv4
|
143
|
+
body = {reboot: true}
|
144
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
145
|
+
stub = stub_request("instances/#{instance_id}/ipv4", method: :post, body: body, response: stub_response(fixture: "instances/ipv4", status: 202))
|
146
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
147
|
+
instance = client.instances.create_ipv4(instance_id: instance_id, **body)
|
148
|
+
|
149
|
+
assert_equal Vultr::Object, instance.class
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_delete_ipv4
|
153
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
154
|
+
ipv4_id = "192.0.2.123"
|
155
|
+
stub = stub_request("instances/#{instance_id}/ipv4/#{ipv4_id}", method: :delete, response: stub_response(fixture: "instances/delete_ipv4", status: 204))
|
156
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
157
|
+
assert client.instances.delete_ipv4(instance_id: instance_id, ipv4: ipv4_id)
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_create_ipv4_reverse
|
161
|
+
body = {ip: "192.0.2.123", reverse: "foo.example.com"}
|
162
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
163
|
+
stub = stub_request("instances/#{instance_id}/ipv4/reverse", method: :post, body: body, response: stub_response(fixture: "instances/create_ipv4_reverse", status: 202))
|
164
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
165
|
+
assert client.instances.create_ipv4_reverse(instance_id: instance_id, **body)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_set_default_reverse_dns_entry
|
169
|
+
body = {ip: "192.0.2.123"}
|
170
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
171
|
+
stub = stub_request("instances/#{instance_id}/ipv4/reverse/default", method: :post, body: body, response: stub_response(fixture: "instances/set_default_reverse_dns_entry"))
|
172
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
173
|
+
assert client.instances.set_default_reverse_dns_entry(instance_id: instance_id, **body)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_list_ipv6
|
177
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
178
|
+
stub = stub_request("instances/#{instance_id}/ipv6", response: stub_response(fixture: "instances/list_ipv6"))
|
179
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
180
|
+
instance = client.instances.list_ipv6(instance_id: instance_id)
|
181
|
+
|
182
|
+
assert_equal Vultr::Collection, instance.class
|
183
|
+
assert_equal 1, instance.total
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_ipv6_reverse
|
187
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
188
|
+
stub = stub_request("instances/#{instance_id}/ipv6/reverse", response: stub_response(fixture: "instances/ipv6_reverse"))
|
189
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
190
|
+
instance = client.instances.ipv6_reverse(instance_id: instance_id)
|
191
|
+
|
192
|
+
assert_equal Vultr::Collection, instance.class
|
193
|
+
assert_equal 1, instance.total
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_create_ipv6_reverse
|
197
|
+
body = {ip: "2001:0db8:0005:6bb0:5400:2ff0:fee5:0002", reverse: "foo.example.com"}
|
198
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
199
|
+
stub = stub_request("instances/#{instance_id}/ipv6/reverse", method: :post, body: body, response: stub_response(fixture: "instances/create_ipv6_reverse", status: 202))
|
200
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
201
|
+
assert client.instances.create_ipv6_reverse(instance_id: instance_id, **body)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_delete_ipv6_reverse
|
205
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
206
|
+
ipv6_id = "2001:0db8:0005:6bb0:5400:2ff0:fee5:0002"
|
207
|
+
stub = stub_request("instances/#{instance_id}/ipv6/reverse/#{ipv6_id}", method: :delete, response: stub_response(fixture: "instances/delete_ipv6", status: 204))
|
208
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
209
|
+
assert client.instances.delete_ipv6_reverse(instance_id: instance_id, ipv6: ipv6_id)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_list_private_networks
|
213
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
214
|
+
stub = stub_request("instances/#{instance_id}/private-networks", response: stub_response(fixture: "instances/list_private_networks"))
|
215
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
216
|
+
instance = client.instances.list_private_networks(instance_id: instance_id)
|
217
|
+
|
218
|
+
assert_equal Vultr::Collection, instance.class
|
219
|
+
assert_equal 1, instance.total
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_attach_private_network
|
223
|
+
body = {network_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
|
224
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
225
|
+
stub = stub_request("instances/#{instance_id}/private-networks/attach", method: :post, body: body, response: stub_response(fixture: "instances/attach_private_network"))
|
226
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
227
|
+
assert client.instances.attach_private_network(instance_id: instance_id, **body)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_detach_private_network
|
231
|
+
body = {network_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
|
232
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
233
|
+
stub = stub_request("instances/#{instance_id}/private-networks/detach", method: :post, body: body, response: stub_response(fixture: "instances/detach_private_network"))
|
234
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
235
|
+
assert client.instances.detach_private_network(instance_id: instance_id, **body)
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_iso
|
239
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
240
|
+
stub = stub_request("instances/#{instance_id}/iso", response: stub_response(fixture: "instances/iso"))
|
241
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
242
|
+
instance = client.instances.iso(instance_id: instance_id)
|
243
|
+
|
244
|
+
assert_equal Vultr::Object, instance.class
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_attach_iso
|
248
|
+
body = {iso_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
|
249
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
250
|
+
stub = stub_request("instances/#{instance_id}/iso/attach", method: :post, body: body, response: stub_response(fixture: "instances/attach_iso", status: 204))
|
251
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
252
|
+
instance = client.instances.attach_iso(instance_id: instance_id, iso_id: body[:iso_id])
|
253
|
+
|
254
|
+
assert_equal Vultr::Object, instance.class
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_detach_iso
|
258
|
+
body = {iso_id: "cb676a46-66fd-4dfb-b839-443f2e6c0b60"}
|
259
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
260
|
+
stub = stub_request("instances/#{instance_id}/iso/detach", method: :post, body: body, response: stub_response(fixture: "instances/detach_iso"))
|
261
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
262
|
+
instance = client.instances.detach_iso(instance_id: instance_id, iso_id: body[:iso_id])
|
263
|
+
|
264
|
+
assert_equal Vultr::Object, instance.class
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_backup_schedule
|
268
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
269
|
+
stub = stub_request("instances/#{instance_id}/backup-schedule", response: stub_response(fixture: "instances/backup_schedule"))
|
270
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
271
|
+
instance = client.instances.backup_schedule(instance_id: instance_id)
|
272
|
+
|
273
|
+
assert_equal Vultr::Object, instance.class
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_set_backup_schedule
|
277
|
+
body = {type: "daily", hour: 10, dow: 1, dom: 1}
|
278
|
+
instance_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b60"
|
279
|
+
stub = stub_request("instances/#{instance_id}/backup-schedule", method: :post, body: body, response: stub_response(fixture: "instances/set_backup_schedule"))
|
280
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
281
|
+
assert client.instances.set_backup_schedule(instance_id: instance_id, **body)
|
282
|
+
end
|
283
|
+
|
284
|
+
def test_halt_instances
|
285
|
+
body = {
|
286
|
+
instance_ids: [
|
287
|
+
"cb676a46-66fd-4dfb-b839-443f2e6c0b60",
|
288
|
+
"1d651bd2-b93c-4bb6-8b91-0546fd765f15",
|
289
|
+
"c2790719-278d-474c-8dff-cb35d6e5503f"
|
290
|
+
]
|
291
|
+
}
|
292
|
+
|
293
|
+
stub = stub_request("instances/halt", method: :post, body: body, response: stub_response(fixture: "instances/halt_instances"))
|
294
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
295
|
+
assert client.instances.halt_instances(instance_ids: body[:instance_ids], **body)
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_reboot_instances
|
299
|
+
body = {
|
300
|
+
instance_ids: [
|
301
|
+
"cb676a46-66fd-4dfb-b839-443f2e6c0b60",
|
302
|
+
"1d651bd2-b93c-4bb6-8b91-0546fd765f15",
|
303
|
+
"c2790719-278d-474c-8dff-cb35d6e5503f"
|
304
|
+
]
|
305
|
+
}
|
306
|
+
|
307
|
+
stub = stub_request("instances/reboot", method: :post, body: body, response: stub_response(fixture: "instances/reboot_instances"))
|
308
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
309
|
+
assert client.instances.reboot_instances(instance_ids: body[:instance_ids], **body)
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_start_instances
|
313
|
+
body = {
|
314
|
+
instance_ids: [
|
315
|
+
"cb676a46-66fd-4dfb-b839-443f2e6c0b60",
|
316
|
+
"1d651bd2-b93c-4bb6-8b91-0546fd765f15",
|
317
|
+
"c2790719-278d-474c-8dff-cb35d6e5503f"
|
318
|
+
]
|
319
|
+
}
|
320
|
+
|
321
|
+
stub = stub_request("instances/start", method: :post, body: body, response: stub_response(fixture: "instances/start_instances"))
|
322
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
323
|
+
assert client.instances.start_instances(instance_ids: body[:instance_ids], **body)
|
324
|
+
end
|
325
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class IsoResourceTest < Minitest::Test
|
4
|
+
def test_list
|
5
|
+
stub = stub_request("iso", response: stub_response(fixture: "isos/list"))
|
6
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
7
|
+
iso = client.iso.list
|
8
|
+
|
9
|
+
keys = [:id, :date_created, :filename, :size, :md5sum, :sha512sum, :status]
|
10
|
+
assert_equal Vultr::Collection, iso.class
|
11
|
+
assert_equal Vultr::Iso, iso.data.first.class
|
12
|
+
assert_equal keys, iso.data.first.to_h.keys
|
13
|
+
assert_equal 1, iso.total
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
body = {url: "http://example.com/my-iso.iso"}
|
18
|
+
stub = stub_request("iso", method: :post, body: body, response: stub_response(fixture: "isos/create", status: 201))
|
19
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
20
|
+
iso = client.iso.create(**body)
|
21
|
+
|
22
|
+
assert_equal "cb676a46-66fd-4dfb-b839-443f2e6c0b60", iso.id
|
23
|
+
assert_equal Time.parse("2020-10-10T01:56:20+00:00"), iso.date_created
|
24
|
+
assert_equal "my-iso.iso", iso.filename
|
25
|
+
assert_equal "pending", iso.status
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_retrieve
|
29
|
+
iso_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b604"
|
30
|
+
stub = stub_request("iso/#{iso_id}", response: stub_response(fixture: "isos/retrieve"))
|
31
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
32
|
+
iso = client.iso.retrieve(iso_id: iso_id)
|
33
|
+
|
34
|
+
keys = [:id, :date_created, :filename, :size, :md5sum, :sha512sum, :status]
|
35
|
+
assert_equal Vultr::Iso, iso.class
|
36
|
+
assert_equal keys, iso.to_h.keys
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_delete
|
40
|
+
iso_id = "cb676a46-66fd-4dfb-b839-443f2e6c0b604"
|
41
|
+
stub = stub_request("iso/#{iso_id}", method: :delete, response: {})
|
42
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
43
|
+
|
44
|
+
assert client.iso.delete(iso_id: iso_id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_list_public
|
48
|
+
stub = stub_request("iso-public", response: stub_response(fixture: "isos/list_public"))
|
49
|
+
client = Vultr::Client.new(api_key: "fake", adapter: :test, stubs: stub)
|
50
|
+
iso = client.iso.list_public
|
51
|
+
|
52
|
+
keys = [:id, :name, :description, :md5sum]
|
53
|
+
assert_equal Vultr::Collection, iso.class
|
54
|
+
assert_equal Vultr::Iso, iso.data.first.class
|
55
|
+
assert_equal keys, iso.data.first.to_h.keys
|
56
|
+
assert_equal 1, iso.total
|
57
|
+
end
|
58
|
+
end
|