saklient 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +43 -0
  6. data/Rakefile +1 -0
  7. data/config.sh.sample +5 -0
  8. data/example.rb +83 -0
  9. data/example.sh +6 -0
  10. data/lib/saklient/cloud/api.rb +382 -0
  11. data/lib/saklient/cloud/client.rb +111 -0
  12. data/lib/saklient/cloud/enums/eappliance_class.rb +39 -0
  13. data/lib/saklient/cloud/enums/eavailability.rb +79 -0
  14. data/lib/saklient/cloud/enums/edisk_connection.rb +39 -0
  15. data/lib/saklient/cloud/enums/escope.rb +39 -0
  16. data/lib/saklient/cloud/enums/escript_class.rb +39 -0
  17. data/lib/saklient/cloud/enums/eserver_instance_status.rb +44 -0
  18. data/lib/saklient/cloud/enums/estorage_class.rb +34 -0
  19. data/lib/saklient/cloud/errors/access_api_key_disabled_exception.rb +23 -0
  20. data/lib/saklient/cloud/errors/access_sakura_exception.rb +23 -0
  21. data/lib/saklient/cloud/errors/access_staff_exception.rb +23 -0
  22. data/lib/saklient/cloud/errors/access_token_exception.rb +23 -0
  23. data/lib/saklient/cloud/errors/access_xhr_or_api_key_exception.rb +23 -0
  24. data/lib/saklient/cloud/errors/account_not_found_exception.rb +23 -0
  25. data/lib/saklient/cloud/errors/account_not_specified_exception.rb +23 -0
  26. data/lib/saklient/cloud/errors/ambiguous_identifier_exception.rb +23 -0
  27. data/lib/saklient/cloud/errors/ambiguous_zone_exception.rb +23 -0
  28. data/lib/saklient/cloud/errors/api_proxy_timeout_exception.rb +23 -0
  29. data/lib/saklient/cloud/errors/api_proxy_timeout_non_get_exception.rb +23 -0
  30. data/lib/saklient/cloud/errors/archive_is_incomplete_exception.rb +23 -0
  31. data/lib/saklient/cloud/errors/boot_failure_by_lock_exception.rb +23 -0
  32. data/lib/saklient/cloud/errors/boot_failure_in_group_exception.rb +23 -0
  33. data/lib/saklient/cloud/errors/busy_exception.rb +23 -0
  34. data/lib/saklient/cloud/errors/cant_resize_smaller_exception.rb +23 -0
  35. data/lib/saklient/cloud/errors/cdrom_device_locked_exception.rb +23 -0
  36. data/lib/saklient/cloud/errors/cdrom_disabled_exception.rb +23 -0
  37. data/lib/saklient/cloud/errors/cdrom_in_use_exception.rb +23 -0
  38. data/lib/saklient/cloud/errors/cdrom_is_incomplete_exception.rb +23 -0
  39. data/lib/saklient/cloud/errors/connect_to_same_switch_exception.rb +23 -0
  40. data/lib/saklient/cloud/errors/contract_creation_exception.rb +23 -0
  41. data/lib/saklient/cloud/errors/copy_to_itself_exception.rb +23 -0
  42. data/lib/saklient/cloud/errors/delete_disk_b4_template_exception.rb +23 -0
  43. data/lib/saklient/cloud/errors/delete_ip_v6_nets_first_exception.rb +23 -0
  44. data/lib/saklient/cloud/errors/delete_res_b4_account_exception.rb +23 -0
  45. data/lib/saklient/cloud/errors/delete_router_b4_switch_exception.rb +23 -0
  46. data/lib/saklient/cloud/errors/delete_static_route_first_exception.rb +23 -0
  47. data/lib/saklient/cloud/errors/disabled_in_sandbox_exception.rb +23 -0
  48. data/lib/saklient/cloud/errors/disconnect_b4_delete_exception.rb +23 -0
  49. data/lib/saklient/cloud/errors/disconnect_b4_update_exception.rb +23 -0
  50. data/lib/saklient/cloud/errors/disk_connection_limit_exception.rb +23 -0
  51. data/lib/saklient/cloud/errors/disk_is_copying_exception.rb +23 -0
  52. data/lib/saklient/cloud/errors/disk_is_not_available_exception.rb +23 -0
  53. data/lib/saklient/cloud/errors/disk_license_mismatch_exception.rb +23 -0
  54. data/lib/saklient/cloud/errors/disk_or_ss_in_migration_exception.rb +23 -0
  55. data/lib/saklient/cloud/errors/disk_stock_run_out_exception.rb +23 -0
  56. data/lib/saklient/cloud/errors/dns_aaaa_record_not_found_exception.rb +23 -0
  57. data/lib/saklient/cloud/errors/dns_arecord_not_found_exception.rb +23 -0
  58. data/lib/saklient/cloud/errors/dns_ptr_update_failure_exception.rb +23 -0
  59. data/lib/saklient/cloud/errors/dont_create_in_sandbox_exception.rb +23 -0
  60. data/lib/saklient/cloud/errors/duplicate_account_code_exception.rb +23 -0
  61. data/lib/saklient/cloud/errors/duplicate_entry_exception.rb +23 -0
  62. data/lib/saklient/cloud/errors/duplicate_user_code_exception.rb +23 -0
  63. data/lib/saklient/cloud/errors/file_not_uploaded_exception.rb +23 -0
  64. data/lib/saklient/cloud/errors/filter_array_comparison_exception.rb +23 -0
  65. data/lib/saklient/cloud/errors/filter_bad_operator_exception.rb +23 -0
  66. data/lib/saklient/cloud/errors/filter_null_comparison_exception.rb +23 -0
  67. data/lib/saklient/cloud/errors/filter_unknown_operator_exception.rb +23 -0
  68. data/lib/saklient/cloud/errors/ftp_cannot_close_exception.rb +23 -0
  69. data/lib/saklient/cloud/errors/ftp_is_already_close_exception.rb +23 -0
  70. data/lib/saklient/cloud/errors/ftp_is_already_open_exception.rb +23 -0
  71. data/lib/saklient/cloud/errors/ftp_must_be_closed_exception.rb +23 -0
  72. data/lib/saklient/cloud/errors/host_operation_failure_exception.rb +23 -0
  73. data/lib/saklient/cloud/errors/illegal_das_usage_exception.rb +23 -0
  74. data/lib/saklient/cloud/errors/in_migration_exception.rb +23 -0
  75. data/lib/saklient/cloud/errors/invalid_format_exception.rb +23 -0
  76. data/lib/saklient/cloud/errors/invalid_param_comb_exception.rb +23 -0
  77. data/lib/saklient/cloud/errors/invalid_range_exception.rb +23 -0
  78. data/lib/saklient/cloud/errors/invalid_uri_argument_exception.rb +23 -0
  79. data/lib/saklient/cloud/errors/ip_v6_net_already_attached_exception.rb +23 -0
  80. data/lib/saklient/cloud/errors/limit_count_in_account_exception.rb +23 -0
  81. data/lib/saklient/cloud/errors/limit_count_in_member_exception.rb +23 -0
  82. data/lib/saklient/cloud/errors/limit_count_in_network_exception.rb +23 -0
  83. data/lib/saklient/cloud/errors/limit_count_in_router_exception.rb +23 -0
  84. data/lib/saklient/cloud/errors/limit_count_in_zone_exception.rb +23 -0
  85. data/lib/saklient/cloud/errors/limit_memory_in_account_exception.rb +23 -0
  86. data/lib/saklient/cloud/errors/limit_size_in_account_exception.rb +23 -0
  87. data/lib/saklient/cloud/errors/missing_iso_image_exception.rb +23 -0
  88. data/lib/saklient/cloud/errors/missing_param_exception.rb +23 -0
  89. data/lib/saklient/cloud/errors/must_be_of_same_zone_exception.rb +23 -0
  90. data/lib/saklient/cloud/errors/no_display_response_exception.rb +23 -0
  91. data/lib/saklient/cloud/errors/not_for_router_exception.rb +23 -0
  92. data/lib/saklient/cloud/errors/not_replicating_exception.rb +23 -0
  93. data/lib/saklient/cloud/errors/not_with_hybridconn_exception.rb +23 -0
  94. data/lib/saklient/cloud/errors/old_storage_plan_exception.rb +23 -0
  95. data/lib/saklient/cloud/errors/operation_failure_exception.rb +23 -0
  96. data/lib/saklient/cloud/errors/operation_timeout_exception.rb +23 -0
  97. data/lib/saklient/cloud/errors/original_hash_mismatch_exception.rb +23 -0
  98. data/lib/saklient/cloud/errors/packet_filter_applying_exception.rb +23 -0
  99. data/lib/saklient/cloud/errors/packet_filter_version_mismatch_exception.rb +23 -0
  100. data/lib/saklient/cloud/errors/param_ip_not_found_exception.rb +23 -0
  101. data/lib/saklient/cloud/errors/param_res_not_found_exception.rb +23 -0
  102. data/lib/saklient/cloud/errors/payment_credit_card_exception.rb +23 -0
  103. data/lib/saklient/cloud/errors/payment_payment_exception.rb +23 -0
  104. data/lib/saklient/cloud/errors/payment_registration_exception.rb +23 -0
  105. data/lib/saklient/cloud/errors/payment_tel_certification_exception.rb +23 -0
  106. data/lib/saklient/cloud/errors/payment_unpayable_exception.rb +23 -0
  107. data/lib/saklient/cloud/errors/penalty_operation_exception.rb +23 -0
  108. data/lib/saklient/cloud/errors/replica_already_exists_exception.rb +23 -0
  109. data/lib/saklient/cloud/errors/replica_not_found_exception.rb +23 -0
  110. data/lib/saklient/cloud/errors/res_already_connected_exception.rb +23 -0
  111. data/lib/saklient/cloud/errors/res_already_disconnected_exception.rb +23 -0
  112. data/lib/saklient/cloud/errors/res_already_exists_exception.rb +23 -0
  113. data/lib/saklient/cloud/errors/res_used_in_zone_exception.rb +23 -0
  114. data/lib/saklient/cloud/errors/resource_path_not_found_exception.rb +23 -0
  115. data/lib/saklient/cloud/errors/run_out_of_ip_address_exception.rb +23 -0
  116. data/lib/saklient/cloud/errors/same_license_required_exception.rb +23 -0
  117. data/lib/saklient/cloud/errors/server_could_not_stop_exception.rb +23 -0
  118. data/lib/saklient/cloud/errors/server_is_cleaning_exception.rb +23 -0
  119. data/lib/saklient/cloud/errors/server_operation_failure_exception.rb +23 -0
  120. data/lib/saklient/cloud/errors/server_power_must_be_down_exception.rb +23 -0
  121. data/lib/saklient/cloud/errors/server_power_must_be_up_exception.rb +23 -0
  122. data/lib/saklient/cloud/errors/service_temporarily_unavailable_exception.rb +23 -0
  123. data/lib/saklient/cloud/errors/size_mismatch_exception.rb +23 -0
  124. data/lib/saklient/cloud/errors/snapshot_in_migration_exception.rb +23 -0
  125. data/lib/saklient/cloud/errors/still_creating_exception.rb +23 -0
  126. data/lib/saklient/cloud/errors/storage_abnormal_exception.rb +23 -0
  127. data/lib/saklient/cloud/errors/storage_operation_failure_exception.rb +23 -0
  128. data/lib/saklient/cloud/errors/switch_hybrid_connected_exception.rb +23 -0
  129. data/lib/saklient/cloud/errors/template_ftp_is_open_exception.rb +23 -0
  130. data/lib/saklient/cloud/errors/template_is_incomplete_exception.rb +23 -0
  131. data/lib/saklient/cloud/errors/too_many_request_exception.rb +23 -0
  132. data/lib/saklient/cloud/errors/unknown_exception.rb +23 -0
  133. data/lib/saklient/cloud/errors/unknown_os_type_exception.rb +23 -0
  134. data/lib/saklient/cloud/errors/unsupported_res_class_exception.rb +23 -0
  135. data/lib/saklient/cloud/errors/user_not_specified_exception.rb +23 -0
  136. data/lib/saklient/cloud/errors/vnc_proxy_request_failure_exception.rb +23 -0
  137. data/lib/saklient/cloud/models/model.rb +348 -0
  138. data/lib/saklient/cloud/models/model_appliance.rb +161 -0
  139. data/lib/saklient/cloud/models/model_archive.rb +207 -0
  140. data/lib/saklient/cloud/models/model_disk.rb +200 -0
  141. data/lib/saklient/cloud/models/model_disk_plan.rb +156 -0
  142. data/lib/saklient/cloud/models/model_icon.rb +178 -0
  143. data/lib/saklient/cloud/models/model_iface.rb +115 -0
  144. data/lib/saklient/cloud/models/model_ipv6_net.rb +106 -0
  145. data/lib/saklient/cloud/models/model_iso_image.rb +207 -0
  146. data/lib/saklient/cloud/models/model_router.rb +148 -0
  147. data/lib/saklient/cloud/models/model_router_plan.rb +106 -0
  148. data/lib/saklient/cloud/models/model_script.rb +178 -0
  149. data/lib/saklient/cloud/models/model_server.rb +237 -0
  150. data/lib/saklient/cloud/models/model_server_plan.rb +119 -0
  151. data/lib/saklient/cloud/models/model_swytch.rb +138 -0
  152. data/lib/saklient/cloud/models/query_params.rb +44 -0
  153. data/lib/saklient/cloud/product.rb +95 -0
  154. data/lib/saklient/cloud/resources/appliance.rb +551 -0
  155. data/lib/saklient/cloud/resources/archive.rb +861 -0
  156. data/lib/saklient/cloud/resources/disk.rb +802 -0
  157. data/lib/saklient/cloud/resources/disk_config.rb +353 -0
  158. data/lib/saklient/cloud/resources/disk_plan.rb +194 -0
  159. data/lib/saklient/cloud/resources/ftp_info.rb +93 -0
  160. data/lib/saklient/cloud/resources/icon.rb +268 -0
  161. data/lib/saklient/cloud/resources/iface.rb +329 -0
  162. data/lib/saklient/cloud/resources/ipv4_net.rb +275 -0
  163. data/lib/saklient/cloud/resources/ipv6_net.rb +238 -0
  164. data/lib/saklient/cloud/resources/iso_image.rb +666 -0
  165. data/lib/saklient/cloud/resources/resource.rb +287 -0
  166. data/lib/saklient/cloud/resources/router.rb +508 -0
  167. data/lib/saklient/cloud/resources/router_plan.rb +230 -0
  168. data/lib/saklient/cloud/resources/script.rb +554 -0
  169. data/lib/saklient/cloud/resources/server.rb +730 -0
  170. data/lib/saklient/cloud/resources/server_instance.rb +217 -0
  171. data/lib/saklient/cloud/resources/server_plan.rb +285 -0
  172. data/lib/saklient/cloud/resources/swytch.rb +521 -0
  173. data/lib/saklient/errors/exception_factory.rb +532 -0
  174. data/lib/saklient/errors/http_bad_gateway_exception.rb +21 -0
  175. data/lib/saklient/errors/http_bad_request_exception.rb +21 -0
  176. data/lib/saklient/errors/http_conflict_exception.rb +21 -0
  177. data/lib/saklient/errors/http_exception.rb +27 -0
  178. data/lib/saklient/errors/http_expectation_failed_exception.rb +21 -0
  179. data/lib/saklient/errors/http_failed_dependency_exception.rb +21 -0
  180. data/lib/saklient/errors/http_forbidden_exception.rb +21 -0
  181. data/lib/saklient/errors/http_gateway_timeout_exception.rb +21 -0
  182. data/lib/saklient/errors/http_gone_exception.rb +21 -0
  183. data/lib/saklient/errors/http_http_version_not_supported_exception.rb +21 -0
  184. data/lib/saklient/errors/http_insufficient_storage_exception.rb +21 -0
  185. data/lib/saklient/errors/http_internal_server_error_exception.rb +21 -0
  186. data/lib/saklient/errors/http_length_required_exception.rb +21 -0
  187. data/lib/saklient/errors/http_locked_exception.rb +21 -0
  188. data/lib/saklient/errors/http_method_not_allowed_exception.rb +21 -0
  189. data/lib/saklient/errors/http_not_acceptable_exception.rb +21 -0
  190. data/lib/saklient/errors/http_not_extended_exception.rb +21 -0
  191. data/lib/saklient/errors/http_not_found_exception.rb +21 -0
  192. data/lib/saklient/errors/http_not_implemented_exception.rb +21 -0
  193. data/lib/saklient/errors/http_payment_required_exception.rb +21 -0
  194. data/lib/saklient/errors/http_precondition_failed_exception.rb +21 -0
  195. data/lib/saklient/errors/http_proxy_authentication_required_exception.rb +21 -0
  196. data/lib/saklient/errors/http_request_entity_too_large_exception.rb +21 -0
  197. data/lib/saklient/errors/http_request_timeout_exception.rb +21 -0
  198. data/lib/saklient/errors/http_request_uri_too_long_exception.rb +21 -0
  199. data/lib/saklient/errors/http_requested_range_not_satisfiable_exception.rb +21 -0
  200. data/lib/saklient/errors/http_service_unavailable_exception.rb +21 -0
  201. data/lib/saklient/errors/http_unauthorized_exception.rb +21 -0
  202. data/lib/saklient/errors/http_unprocessable_entity_exception.rb +21 -0
  203. data/lib/saklient/errors/http_unsupported_media_type_exception.rb +21 -0
  204. data/lib/saklient/errors/http_upgrade_required_exception.rb +21 -0
  205. data/lib/saklient/errors/http_variant_also_negotiates_exception.rb +21 -0
  206. data/lib/saklient/errors/saklient_exception.rb +22 -0
  207. data/lib/saklient/util.rb +121 -0
  208. data/lib/saklient/version.rb +5 -0
  209. data/saklient.gemspec +24 -0
  210. data/spec/archive_spec.rb +141 -0
  211. data/spec/enum_spec.rb +24 -0
  212. data/spec/exception_spec.rb +25 -0
  213. data/spec/iso_image_spec.rb +172 -0
  214. data/spec/router_spec.rb +124 -0
  215. data/spec/server_spec.rb +261 -0
  216. data/spec/util_spec.rb +72 -0
  217. data/test-sshkey.txt +27 -0
  218. metadata +281 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae24ff7a6b88b279ce5929c8f26d4314c497d3f1
4
+ data.tar.gz: 6115e9a5b55b89686e8a84c2b92823514af1c836
5
+ SHA512:
6
+ metadata.gz: 411f8943577198feb1f30f2a66c3534ab7ed3b34a1bbe047ebb7a6ae890c0a652e886cd40ab62c8ab4e642f77ac34cdf31d6bb4ec6e430392e787cd2bf31b30b
7
+ data.tar.gz: 6950f2f696fde82c47711dca57cde7244c1a2cc20c7a7b870ad5ec4572f8bbefbfc9dde6cc2064dde8810dfb7b269e8058f0d89cff6c3809ce1ce13aeb9ab19a
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ config.sh
19
+ testok
20
+ .project
21
+ .settings
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in saklient.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 SAKURA Internet, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # SAKURA Internet API Client Library for Ruby
2
+
3
+ This library gives you an easy interface to control your resources on
4
+ [SAKURA Cloud](https://secure.sakura.ad.jp/cloud/).
5
+
6
+ ## Table of Contents
7
+
8
+ <!-- This TOC is generated by https://www.npmjs.org/package/readme-toc -->
9
+ <!-- toc -->
10
+ * [Installation](#installation)
11
+ * [How to use this library in your project](#how-to-use-this-library-in-your-project)
12
+ * [Copyright and license](#copyright-and-license)
13
+
14
+ <!-- toc stop -->
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ gem install specific_install
20
+ gem specific_install -l git@github.com:sakura-internet/saklient.rb.git
21
+ ```
22
+
23
+
24
+ ## How to use this library in your project
25
+
26
+
27
+ ```ruby
28
+ require 'saklient/cloud/api'
29
+ api = Saklient::Cloud::API.authorize(YOUR_API_TOKEN, YOUR_API_SECRET)
30
+
31
+ # To access resources in the specified zone
32
+ api_is1b = api.in_zone("is1b")
33
+
34
+ # ...
35
+ ```
36
+
37
+
38
+ ## Copyright and license
39
+
40
+ Copyright (C) 2014 SAKURA Internet, Inc.
41
+
42
+ This library is freely redistributable under [MIT license](http://www.opensource.org/licenses/mit-license.php).
43
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/config.sh.sample ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ export SACLOUD_TOKEN='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
4
+ export SACLOUD_SECRET='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
5
+ # export SACLOUD_ZONE='is1b'
data/example.rb ADDED
@@ -0,0 +1,83 @@
1
+ #require 'saklient/cloud/api'
2
+ require './lib/saklient/cloud/api.rb'
3
+ require 'JSON'
4
+
5
+ api = Saklient::Cloud::API.authorize(ARGV[0], ARGV[1])
6
+
7
+ server = api.server.create
8
+ server.name = 'saklient.rb'
9
+ server.description = 'This instance was created by saklient.rb example'
10
+ server.tags = ['saklient-test']
11
+ server.plan = api.product.server.get_by_spec(1, 1)
12
+ server.save
13
+ servers = api.server.with_name_like('saklient.rb').find
14
+ printf "%s\n", servers[0].name
15
+ printf "%s\n", servers[0].description
16
+ printf "%s\n", servers[0].tags[0]
17
+ server.destroy
18
+
19
+
20
+ # printf "%s\n", Saklient::Cloud::Enums::EServerInstanceStatus.down
21
+ # printf "%s\n", Saklient::Cloud::Enums::EServerInstanceStatus.compare("aaa", "down").nil?
22
+ # printf "%s\n", Saklient::Cloud::Enums::EServerInstanceStatus.compare("up", "down")
23
+ # printf "%s\n", Saklient::Cloud::Enums::EServerInstanceStatus.compare("down", "up")
24
+
25
+
26
+ # # 停止中のサーバに接続されているディスクを一覧
27
+ # servers = api.server.with_status("down").find
28
+ # for server in servers
29
+ # next if server.tags.empty?
30
+ # puts ""
31
+ # printf "server [%s] %s at %s\n", server.id, server.instance.status, server.instance.status_changed_at.to_s
32
+ # printf " tags: %s\n", server.tags.join(', ')
33
+ # #puts JSON.pretty_unparse(server.dump())
34
+ # for iface in server.ifaces
35
+ # printf " iface [%s] %s %s\n", iface.id, iface.mac_address, iface.ip_address || iface.user_ip_address
36
+ # end
37
+ # disks = server.find_disks # same as: disks = api.disk.with_server_id(server.id).find
38
+ # for disk in disks
39
+ # printf " disk [%s] %s\n", disk.id, disk.name
40
+ # end
41
+ # end
42
+
43
+
44
+ # # 特定のタグを持つサーバの説明に現在時刻を追記
45
+ # servers = api.server.with_tag("abc").find
46
+ # for server in servers
47
+ # printf "server [%s] %s\n", server.id, server.name
48
+ # server.description += "\n" + Time.now.strftime("%Y/%m/%d %H:%M:%S")
49
+ # server.save
50
+ # printf "%s\n\n", server.description
51
+ # end
52
+
53
+
54
+ # icons = api.icon.with_name_like('cent').limit(1).find
55
+ # abort 'icon not found' if icons.empty?
56
+ # icon = icons[0]
57
+ # printf "icon [%s] %s\n\n", icon.id, icon.name
58
+ #
59
+ # servers = api.server.with_name_like('cent').find
60
+ # for server in servers
61
+ # printf "server [%s] %s\n", server.id, server.name
62
+ # server.icon = nil
63
+ # server.save
64
+ # printf " changed icon to nothing: %s\n", (server.icon.nil? ? 'OK' : 'NG')
65
+ # server.icon = icon
66
+ # server.save
67
+ # printf " changed icon to: [%s] %s\n\n", server.icon.id, server.icon.name
68
+ # end
69
+
70
+
71
+ # plan_from = api.product.server.get_by_spec(2, 4)
72
+ # printf "plan from: [%s] %dcore %dGB\n", plan_from.id, plan_from.cpu, plan_from.memory_gib
73
+ # plan_to = api.product.server.get_by_spec(4, 8)
74
+ # printf "plan to: [%s] %dcore %dGB\n", plan_to.id, plan_to.cpu, plan_to.memory_gib
75
+ # printf "\n"
76
+ #
77
+ # servers = api.server.with_plan(plan_from).find()
78
+ # for server in servers
79
+ # printf "server [%s] %dcore %dGB '%s'\n", server.id, server.plan.cpu, server.plan.memory_gib, server.name
80
+ # server.change_plan(plan_to)
81
+ # printf " -> [%s] %dcore %dGB\n\n", server.id, server.plan.cpu, server.plan.memory_gib
82
+ # end
83
+
data/example.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+
3
+ cd `dirname $0`
4
+ source config.sh
5
+ ruby example.rb "$SACLOUD_TOKEN" "$SACLOUD_SECRET"
6
+
@@ -0,0 +1,382 @@
1
+ # -*- encoding: UTF-8 -*-
2
+
3
+ require_relative '../util'
4
+ require_relative 'client'
5
+ require_relative 'product'
6
+ require_relative 'models/model_icon'
7
+ require_relative 'models/model_server'
8
+ require_relative 'models/model_disk'
9
+ require_relative 'models/model_appliance'
10
+ require_relative 'models/model_archive'
11
+ require_relative 'models/model_iso_image'
12
+ require_relative 'models/model_iface'
13
+ require_relative 'models/model_swytch'
14
+ require_relative 'models/model_router'
15
+ require_relative 'models/model_ipv6_net'
16
+ require_relative 'models/model_script'
17
+
18
+ module Saklient
19
+ module Cloud
20
+
21
+ # さくらのクラウドAPIクライアントを利用する際, 最初にアクセスすべきルートとなるクラス.
22
+ #
23
+ # @see API.authorize
24
+ class API
25
+
26
+ protected
27
+
28
+ # @private
29
+ # @return [Client]
30
+ attr_accessor :_client
31
+
32
+ # @private
33
+ # @return [Client]
34
+ def get_client
35
+ return @_client
36
+ end
37
+
38
+ public
39
+
40
+ # @private
41
+ # @return [Client]
42
+ attr_reader :client
43
+
44
+ def client
45
+ get_client
46
+ end
47
+
48
+ protected
49
+
50
+ # @private
51
+ # @return [Product]
52
+ attr_accessor :_product
53
+
54
+ # @private
55
+ # @return [Product]
56
+ def get_product
57
+ return @_product
58
+ end
59
+
60
+ public
61
+
62
+ # 商品情報にアクセスするためのモデルを集めたオブジェクト.
63
+ #
64
+ # @return [Product]
65
+ attr_reader :product
66
+
67
+ def product
68
+ get_product
69
+ end
70
+
71
+ protected
72
+
73
+ # @private
74
+ # @return [Saklient::Cloud::Models::Model_Icon]
75
+ attr_accessor :_icon
76
+
77
+ # @private
78
+ # @return [Saklient::Cloud::Models::Model_Icon]
79
+ def get_icon
80
+ return @_icon
81
+ end
82
+
83
+ public
84
+
85
+ # アイコンにアクセスするためのモデル.
86
+ #
87
+ # @return [Saklient::Cloud::Models::Model_Icon]
88
+ attr_reader :icon
89
+
90
+ def icon
91
+ get_icon
92
+ end
93
+
94
+ protected
95
+
96
+ # @private
97
+ # @return [Saklient::Cloud::Models::Model_Server]
98
+ attr_accessor :_server
99
+
100
+ # @private
101
+ # @return [Saklient::Cloud::Models::Model_Server]
102
+ def get_server
103
+ return @_server
104
+ end
105
+
106
+ public
107
+
108
+ # サーバにアクセスするためのモデル.
109
+ #
110
+ # @return [Saklient::Cloud::Models::Model_Server]
111
+ attr_reader :server
112
+
113
+ def server
114
+ get_server
115
+ end
116
+
117
+ protected
118
+
119
+ # @private
120
+ # @return [Saklient::Cloud::Models::Model_Disk]
121
+ attr_accessor :_disk
122
+
123
+ # @private
124
+ # @return [Saklient::Cloud::Models::Model_Disk]
125
+ def get_disk
126
+ return @_disk
127
+ end
128
+
129
+ public
130
+
131
+ # ディスクにアクセスするためのモデル.
132
+ #
133
+ # @return [Saklient::Cloud::Models::Model_Disk]
134
+ attr_reader :disk
135
+
136
+ def disk
137
+ get_disk
138
+ end
139
+
140
+ protected
141
+
142
+ # @private
143
+ # @return [Saklient::Cloud::Models::Model_Appliance]
144
+ attr_accessor :_appliance
145
+
146
+ # @private
147
+ # @return [Saklient::Cloud::Models::Model_Appliance]
148
+ def get_appliance
149
+ return @_appliance
150
+ end
151
+
152
+ public
153
+
154
+ # アプライアンスにアクセスするためのモデル.
155
+ #
156
+ # @return [Saklient::Cloud::Models::Model_Appliance]
157
+ attr_reader :appliance
158
+
159
+ def appliance
160
+ get_appliance
161
+ end
162
+
163
+ protected
164
+
165
+ # @private
166
+ # @return [Saklient::Cloud::Models::Model_Archive]
167
+ attr_accessor :_archive
168
+
169
+ # @private
170
+ # @return [Saklient::Cloud::Models::Model_Archive]
171
+ def get_archive
172
+ return @_archive
173
+ end
174
+
175
+ public
176
+
177
+ # アーカイブにアクセスするためのモデル.
178
+ #
179
+ # @return [Saklient::Cloud::Models::Model_Archive]
180
+ attr_reader :archive
181
+
182
+ def archive
183
+ get_archive
184
+ end
185
+
186
+ protected
187
+
188
+ # @private
189
+ # @return [Saklient::Cloud::Models::Model_IsoImage]
190
+ attr_accessor :_iso_image
191
+
192
+ # @private
193
+ # @return [Saklient::Cloud::Models::Model_IsoImage]
194
+ def get_iso_image
195
+ return @_iso_image
196
+ end
197
+
198
+ public
199
+
200
+ # ISOイメージにアクセスするためのモデル.
201
+ #
202
+ # @return [Saklient::Cloud::Models::Model_IsoImage]
203
+ attr_reader :iso_image
204
+
205
+ def iso_image
206
+ get_iso_image
207
+ end
208
+
209
+ protected
210
+
211
+ # @private
212
+ # @return [Saklient::Cloud::Models::Model_Iface]
213
+ attr_accessor :_iface
214
+
215
+ # @private
216
+ # @return [Saklient::Cloud::Models::Model_Iface]
217
+ def get_iface
218
+ return @_iface
219
+ end
220
+
221
+ public
222
+
223
+ # インタフェースにアクセスするためのモデル.
224
+ #
225
+ # @return [Saklient::Cloud::Models::Model_Iface]
226
+ attr_reader :iface
227
+
228
+ def iface
229
+ get_iface
230
+ end
231
+
232
+ protected
233
+
234
+ # @private
235
+ # @return [Saklient::Cloud::Models::Model_Swytch]
236
+ attr_accessor :_swytch
237
+
238
+ # @private
239
+ # @return [Saklient::Cloud::Models::Model_Swytch]
240
+ def get_swytch
241
+ return @_swytch
242
+ end
243
+
244
+ public
245
+
246
+ # スイッチにアクセスするためのモデル.
247
+ #
248
+ # @return [Saklient::Cloud::Models::Model_Swytch]
249
+ attr_reader :swytch
250
+
251
+ def swytch
252
+ get_swytch
253
+ end
254
+
255
+ protected
256
+
257
+ # @private
258
+ # @return [Saklient::Cloud::Models::Model_Router]
259
+ attr_accessor :_router
260
+
261
+ # @private
262
+ # @return [Saklient::Cloud::Models::Model_Router]
263
+ def get_router
264
+ return @_router
265
+ end
266
+
267
+ public
268
+
269
+ # ルータにアクセスするためのモデル.
270
+ #
271
+ # @return [Saklient::Cloud::Models::Model_Router]
272
+ attr_reader :router
273
+
274
+ def router
275
+ get_router
276
+ end
277
+
278
+ protected
279
+
280
+ # @private
281
+ # @return [Saklient::Cloud::Models::Model_Ipv6Net]
282
+ attr_accessor :_ipv6_net
283
+
284
+ # @private
285
+ # @return [Saklient::Cloud::Models::Model_Ipv6Net]
286
+ def get_ipv6_net
287
+ return @_ipv6_net
288
+ end
289
+
290
+ public
291
+
292
+ # IPv6ネットワークにアクセスするためのモデル.
293
+ #
294
+ # @return [Saklient::Cloud::Models::Model_Ipv6Net]
295
+ attr_reader :ipv6_net
296
+
297
+ def ipv6_net
298
+ get_ipv6_net
299
+ end
300
+
301
+ protected
302
+
303
+ # @private
304
+ # @return [Saklient::Cloud::Models::Model_Script]
305
+ attr_accessor :_script
306
+
307
+ # @private
308
+ # @return [Saklient::Cloud::Models::Model_Script]
309
+ def get_script
310
+ return @_script
311
+ end
312
+
313
+ public
314
+
315
+ # スクリプトにアクセスするためのモデル.
316
+ #
317
+ # @return [Saklient::Cloud::Models::Model_Script]
318
+ attr_reader :script
319
+
320
+ def script
321
+ get_script
322
+ end
323
+
324
+ protected
325
+
326
+ # @private
327
+ # @param [Client] client
328
+ def initialize(client)
329
+ Saklient::Util::validate_type(client, 'Saklient::Cloud::Client')
330
+ @_client = client
331
+ @_product = Saklient::Cloud::Product.new(client)
332
+ @_icon = Saklient::Cloud::Models::Model_Icon.new(client)
333
+ @_server = Saklient::Cloud::Models::Model_Server.new(client)
334
+ @_disk = Saklient::Cloud::Models::Model_Disk.new(client)
335
+ @_appliance = Saklient::Cloud::Models::Model_Appliance.new(client)
336
+ @_archive = Saklient::Cloud::Models::Model_Archive.new(client)
337
+ @_iso_image = Saklient::Cloud::Models::Model_IsoImage.new(client)
338
+ @_iface = Saklient::Cloud::Models::Model_Iface.new(client)
339
+ @_swytch = Saklient::Cloud::Models::Model_Swytch.new(client)
340
+ @_router = Saklient::Cloud::Models::Model_Router.new(client)
341
+ @_ipv6_net = Saklient::Cloud::Models::Model_Ipv6Net.new(client)
342
+ @_script = Saklient::Cloud::Models::Model_Script.new(client)
343
+ end
344
+
345
+ public
346
+
347
+ # 指定した認証情報を用いてアクセスを行うAPIクライアントを作成します.
348
+ #
349
+ # 必要な認証情報は, コントロールパネル右上にあるアカウントのプルダウンから
350
+ # 「設定」を選択し, 「APIキー」のページにて作成できます.
351
+ #
352
+ # @param [String] token ACCESS TOKEN
353
+ # @param [String] secret ACCESS TOKEN SECRET
354
+ # @param [String] zone ゾーン名
355
+ # @return [API] APIクライアント
356
+ def self.authorize(token, secret, zone = nil)
357
+ Saklient::Util::validate_type(token, 'String')
358
+ Saklient::Util::validate_type(secret, 'String')
359
+ Saklient::Util::validate_type(zone, 'String')
360
+ c = Saklient::Cloud::Client.new(token, secret)
361
+ ret = Saklient::Cloud::API.new(c)
362
+ return !(zone).nil? ? ret.in_zone(zone) : ret
363
+ end
364
+
365
+ # 認証情報を引き継ぎ, 指定したゾーンへのアクセスを行うAPIクライアントを作成します.
366
+ #
367
+ # @param [String] name ゾーン名
368
+ # @return [API] APIクライアント
369
+ def in_zone(name)
370
+ Saklient::Util::validate_type(name, 'String')
371
+ ret = Saklient::Cloud::API.new(@_client.clone_instance)
372
+ suffix = ''
373
+ suffix = '-test' if name == 'is1x' || name == 'is1y'
374
+ ret._client.set_api_root('https://secure.sakura.ad.jp/cloud' + suffix + '/')
375
+ ret._client.set_api_root_suffix('zone/' + name)
376
+ return ret
377
+ end
378
+
379
+ end
380
+
381
+ end
382
+ end
@@ -0,0 +1,111 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'uri'
5
+ require_relative '../errors/exception_factory'
6
+
7
+ module Saklient
8
+ module Cloud
9
+
10
+ # @private
11
+ class Client
12
+
13
+ def initialize(token, secret)
14
+ @config = {
15
+ api_root: 'https://secure.sakura.ad.jp/cloud/',
16
+ api_root_suffix: nil
17
+ }
18
+ set_access_key token, secret
19
+ self
20
+ end
21
+
22
+ def println(msg)
23
+ $stderr.puts msg
24
+ end
25
+
26
+ def clone_instance
27
+ instance = self.class.new(@config[:token], @config[:secret])
28
+ instance.set_api_root @config[:api_root]
29
+ instance.set_api_root_suffix @config[:api_root_suffix]
30
+
31
+ instance
32
+ end
33
+
34
+ def set_api_root(url)
35
+ @config[:api_root] = url
36
+ end
37
+
38
+ def set_api_root_suffix(suffix)
39
+ @config[:api_root_suffix] = suffix
40
+ end
41
+
42
+ def set_access_key(token, secret)
43
+ @config[:token] = token
44
+ @config[:secret] = secret
45
+ end
46
+
47
+ def request(method, path, params={})
48
+ json = params.to_json
49
+
50
+ unless path =~ /^http/
51
+ url_root = @config[:api_root]
52
+ if @config[:api_root_suffix]
53
+ url_root += @config[:api_root_suffix]
54
+ url_root = url_root.sub %r|/?$|, '/'
55
+ end
56
+ url = url_root + 'api/cloud/1.1' + path
57
+ end
58
+
59
+ url += '?' + URI.escape(json) if method == 'GET' and !params.empty?
60
+
61
+ #println '// APIリクエスト中: #{method} #{path}'
62
+
63
+ parsed_url = URI.parse url
64
+
65
+ if method == 'GET'
66
+ req = Net::HTTP::Get.new parsed_url
67
+ else
68
+ req = Net::HTTP::Post.new parsed_url
69
+ req.body = json
70
+ end
71
+
72
+ req.basic_auth @config[:token], @config[:secret]
73
+
74
+ extra_headers = {
75
+ 'Content-Type' => 'application/x-www-form-urlencoded',
76
+ 'User-Agent' => 'sacloud-client-ruby',
77
+ 'X-Requested-With' => 'XMLHttpRequest',
78
+ 'X-Sakura-HTTP-Method' => method,
79
+ 'X-Sakura-Error-Level' => 'warning',
80
+ 'X-Sakura-Request-Format' => 'json',
81
+ 'X-Sakura-Response-Format' => 'json',
82
+ 'X-Sakura-No-Authenticate-Header' => '1'
83
+ }
84
+
85
+ #println parsed_url
86
+
87
+ extra_headers.each do |key, value|
88
+ req[key] = value
89
+ end
90
+
91
+ http = Net::HTTP.new parsed_url.host, parsed_url.scheme == 'https' ? 443 : 80
92
+ # http.set_debug_output($stderr) # for debugging
93
+ if parsed_url.scheme == 'https'
94
+ http.use_ssl = true
95
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
96
+ end
97
+ res = http.start {|conn| conn.request req }
98
+
99
+ ret = JSON.parse(res.body, {:symbolize_names => true})
100
+ status = res.code.to_i
101
+ unless 200 <= status && status < 300 then
102
+ raise Saklient::Errors::ExceptionFactory.create(status, ret[:error_code], ret[:error_msg])
103
+ end
104
+
105
+ ret
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+ end