Class: Saklient::Cloud::Resources::Server
- Defined in:
- lib/saklient/cloud/resources/server.rb
Overview
サーバの実体1つに対応し, 属性の取得や操作を行うためのクラス.
Instance Attribute Summary collapse
-
#activity ⇒ ServerActivity
readonly
アクティビティ.
-
#availability ⇒ String
readonly
有効状態 Enums::EAvailability.
-
#description ⇒ String
説明.
-
#host_name ⇒ String
ホスト名.
-
#icon ⇒ Icon
アイコン.
-
#id ⇒ String
readonly
ID.
-
#ifaces ⇒ Array<Iface>
readonly
インタフェース.
-
#instance ⇒ ServerInstance
readonly
インスタンス情報.
-
#name ⇒ String
名前.
-
#plan ⇒ ServerPlan
プラン.
-
#tags ⇒ Array<String>
タグ文字列の配列.
Attributes inherited from Resource
Instance Method Summary collapse
- #_class_name ⇒ String
- #_id ⇒ String
-
#add_iface ⇒ Iface
サーバにインタフェースを1つ増設し, それを取得します.
-
#boot ⇒ Server
サーバを起動します.
-
#change_plan(planTo) ⇒ Server
サーバプランを変更します.
-
#easy_duplicate(userIpAddress = nil, diskSource = nil, sshKey = nil, hostName = nil, name = nil) ⇒ Server
サーバ および そのサーバに接続されている1台目のディスクを複製し, 同一ネットワークに接続します.
-
#eject_iso_image ⇒ Server
サーバに挿入されているISOイメージを排出します.
-
#find_disks ⇒ Array<Disk>
サーバに接続されているディスクのリストを取得します.
- #get_activity ⇒ ServerActivity
-
#initialize(client, obj, wrapped = false) ⇒ Server
constructor
A new instance of Server.
-
#insert_iso_image(iso) ⇒ Server
サーバにISOイメージを挿入します.
-
#is_down ⇒ bool
サーバが停止しているときtrueを返します.
-
#is_up ⇒ bool
サーバが起動しているときtrueを返します.
-
#reboot ⇒ Server
サーバを強制再起動します.
-
#reload ⇒ Server
最新のリソース情報を再取得します.
-
#save ⇒ Server
このローカルオブジェクトに現在設定されているリソース情報をAPIに送信し, 新規作成または上書き保存します.
-
#shutdown ⇒ Server
サーバをシャットダウンします.
-
#sleep_until_down(timeoutSec = 180) ⇒ bool
サーバが停止するまで待機します.
-
#sleep_until_up(timeoutSec = 180) ⇒ bool
サーバが起動するまで待機します.
-
#sleep_while_copying(timeoutSec = 3600) ⇒ bool
サーバに接続されているコピー中のディスクが利用可能になるまで待機します.
-
#stop ⇒ Server
サーバを強制停止します.
Methods inherited from Resource
#api_deserialize, #api_serialize, create_with, #destroy, #dump, #exists, #request_retry, #set_param
Constructor Details
#initialize(client, obj, wrapped = false) ⇒ Server
Returns a new instance of Server.
158 159 160 161 162 163 164 |
# File 'lib/saklient/cloud/resources/server.rb', line 158 def initialize(client, obj, wrapped = false) super(client) Saklient::Util::validate_type(client, 'Saklient::Cloud::Client') Saklient::Util::validate_type(wrapped, 'bool') @_activity = Saklient::Cloud::Resources::ServerActivity.new(client) api_deserialize(obj, wrapped) end |
Instance Attribute Details
#activity ⇒ ServerActivity (readonly)
アクティビティ
148 149 150 |
# File 'lib/saklient/cloud/resources/server.rb', line 148 def activity @activity end |
#availability ⇒ String (readonly)
有効状態 Enums::EAvailability
851 852 853 |
# File 'lib/saklient/cloud/resources/server.rb', line 851 def availability @availability end |
#description ⇒ String
説明
613 614 615 |
# File 'lib/saklient/cloud/resources/server.rb', line 613 def description @description end |
#host_name ⇒ String
ホスト名
823 824 825 |
# File 'lib/saklient/cloud/resources/server.rb', line 823 def host_name @host_name end |
#icon ⇒ Icon
アイコン
694 695 696 |
# File 'lib/saklient/cloud/resources/server.rb', line 694 def icon @icon end |
#id ⇒ String (readonly)
ID
537 538 539 |
# File 'lib/saklient/cloud/resources/server.rb', line 537 def id @id end |
#ifaces ⇒ Array<Iface> (readonly)
インタフェース
763 764 765 |
# File 'lib/saklient/cloud/resources/server.rb', line 763 def ifaces @ifaces end |
#instance ⇒ ServerInstance (readonly)
インスタンス情報
787 788 789 |
# File 'lib/saklient/cloud/resources/server.rb', line 787 def instance @instance end |
#name ⇒ String
名前
573 574 575 |
# File 'lib/saklient/cloud/resources/server.rb', line 573 def name @name end |
#plan ⇒ ServerPlan
プラン
735 736 737 |
# File 'lib/saklient/cloud/resources/server.rb', line 735 def plan @plan end |
#tags ⇒ Array<String>
タグ文字列の配列
654 655 656 |
# File 'lib/saklient/cloud/resources/server.rb', line 654 def @tags end |
Instance Method Details
#_class_name ⇒ String
107 108 109 |
# File 'lib/saklient/cloud/resources/server.rb', line 107 def _class_name return 'Server' end |
#_id ⇒ String
113 114 115 |
# File 'lib/saklient/cloud/resources/server.rb', line 113 def _id return get_id end |
#add_iface ⇒ Iface
サーバにインタフェースを1つ増設し, それを取得します.
458 459 460 461 462 463 464 465 |
# File 'lib/saklient/cloud/resources/server.rb', line 458 def add_iface model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Iface', [@_client]) res = model.create res.server_id = _id res.save reload return res end |
#boot ⇒ Server
サーバを起動します.
355 356 357 358 |
# File 'lib/saklient/cloud/resources/server.rb', line 355 def boot @_client.request('PUT', _api_path + '/' + Saklient::Util::url_encode(_id) + '/power') return reload end |
#change_plan(planTo) ⇒ Server
サーバプランを変更します.
成功時はリソースIDが変わることにご注意ください.
439 440 441 442 443 444 445 |
# File 'lib/saklient/cloud/resources/server.rb', line 439 def change_plan(planTo) Saklient::Util::validate_type(planTo, 'Saklient::Cloud::Resources::ServerPlan') path = _api_path + '/' + Saklient::Util::url_encode(_id) + '/to/plan/' + Saklient::Util::url_encode(planTo._id) result = @_client.request('PUT', path) api_deserialize(result, true) return self end |
#easy_duplicate(userIpAddress = nil, diskSource = nil, sshKey = nil, hostName = nil, name = nil) ⇒ Server
サーバ および そのサーバに接続されている1台目のディスクを複製し, 同一ネットワークに接続します. ディスクのコピー中は待機し, 完了してからreturnします.
共有セグメントに接続されている場合はAPIによって自動的に割り当てられるため, 省略またはnullを指定してください.
trueを指定した場合は, 複製元の現在のディスク#1から直接クローンします.
省略またはnullを指定した場合は, 複製元のディスク#1が作成された時のコピー元リソースから再度クローンを試みます.
既に削除されている場合は, 複製元の現在のディスク#1からの直接クローンにフォールバックします.
いずれの場合も, 作成されるディスクのプランとサイズは複製元のサーバの1台目のディスクと同一のものが選択されます.
作成されるディスクは1台目だけで, 2台目以降は無視されます.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/saklient/cloud/resources/server.rb', line 183 def easy_duplicate(userIpAddress = nil, diskSource = nil, sshKey = nil, hostName = nil, name = nil) Saklient::Util::validate_type(userIpAddress, 'String') Saklient::Util::validate_type(sshKey, 'String') Saklient::Util::validate_type(hostName, 'String') Saklient::Util::validate_type(name, 'String') server = Saklient::Cloud::Resources::Server.new(@_client, nil) names = [] hostNames = [] if (name).nil? || (hostName).nil? model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Server', [@_client]) servers = model.limit(0).find s = nil for s in servers names << s.get_name hostNames << s.get_host_name end end name = Saklient::Util::auto_rename(self.name, names) if (name).nil? hostName = Saklient::Util::auto_rename(self.host_name, hostNames) if (hostName).nil? server.set_name(name) server.set_host_name(hostName) server.set_description(self.description) server.(self.) server.set_icon(self.icon) server.set_plan(self.plan) iface = nil if 0 < self.ifaces.length iface = self.ifaces[0] iface.reload if (iface.ip_address).nil? raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the disconnected interface is not allowed') if (userIpAddress).nil? && (iface.swytch_id).nil? else raise Saklient::Errors::SaklientException.new('invalid_data', 'Setting an IP address to the interface connected to a shared segment is not allowed') if !(userIpAddress).nil? end end srcDisks = find_disks if 0 < srcDisks.length direct = Saklient::Util::are_same(diskSource, true) if (diskSource).nil? || direct diskSource = srcDisks[0].source if !direct if diskSource.is_a?(Saklient::Cloud::Resources::Archive) begin diskSource.reload rescue Saklient::Errors::HttpNotFoundException diskSource = srcDisks[0] end else if diskSource.is_a?(Saklient::Cloud::Resources::Disk) begin diskSource.reload rescue Saklient::Errors::HttpNotFoundException diskSource = srcDisks[0] end end end end end if diskSource.is_a?(Saklient::Cloud::Resources::Archive) diskSource.reload else diskSource.reload if diskSource.is_a?(Saklient::Cloud::Resources::Disk) end end server.save disk = nil if !(diskSource).nil? && diskSource.is_a?(Saklient::Cloud::Resources::Resource) disk = Saklient::Cloud::Resources::Disk.new(@_client, nil) disk.source = diskSource disk.name = (name).nil? ? srcDisks[0].name : name disk.description = srcDisks[0].description disk. = srcDisks[0]. disk.icon = srcDisks[0].icon disk.plan = srcDisks[0].plan disk.size_mib = srcDisks[0].size_mib disk.server = server disk.save end iface1st = nil userSwytch = nil for iface in self.ifaces iface.reload newIface = server.add_iface if (iface1st).nil? if !(iface.ip_address).nil? newIface.connect_to_shared_segment else newIface.connect_to_swytch_by_id(iface.swytch_id) if !(iface.swytch_id).nil? if !(userIpAddress).nil? newIface.user_ip_address = userIpAddress newIface.save end userSwytch = iface.find_swytch iface1st = iface end else newIface.connect_to_swytch_by_id(iface.swytch_id) if !(iface.swytch_id).nil? end end if !(disk).nil? disk. diskconf = disk.create_config diskconf.host_name = hostName diskconf.ssh_key = sshKey diskconf.ip_address = userIpAddress if !(userSwytch).nil? if 0 < userSwytch.ipv4_nets.length net = userSwytch.ipv4_nets[0] diskconf.default_route = net.default_route diskconf.network_mask_len = net.mask_len else diskconf.default_route = userSwytch.user_default_route diskconf.network_mask_len = userSwytch.user_mask_len end end diskconf.write end server.reload return server end |
#eject_iso_image ⇒ Server
サーバに挿入されているISOイメージを排出します.
483 484 485 486 487 488 |
# File 'lib/saklient/cloud/resources/server.rb', line 483 def eject_iso_image path = _api_path + '/' + Saklient::Util::url_encode(_id) + '/cdrom' @_client.request('DELETE', path) reload return self end |
#find_disks ⇒ Array<Disk>
サーバに接続されているディスクのリストを取得します.
450 451 452 453 |
# File 'lib/saklient/cloud/resources/server.rb', line 450 def find_disks model = Saklient::Util::create_class_instance('saklient.cloud.models.Model_Disk', [@_client]) return model.with_server_id(_id).sort_by_connection_order.find end |
#get_activity ⇒ ServerActivity
141 142 143 |
# File 'lib/saklient/cloud/resources/server.rb', line 141 def get_activity return @_activity end |
#insert_iso_image(iso) ⇒ Server
サーバにISOイメージを挿入します.
471 472 473 474 475 476 477 478 |
# File 'lib/saklient/cloud/resources/server.rb', line 471 def insert_iso_image(iso) Saklient::Util::validate_type(iso, 'Saklient::Cloud::Resources::IsoImage') path = _api_path + '/' + Saklient::Util::url_encode(_id) + '/cdrom' q = { CDROM: { ID: iso._id } } @_client.request('PUT', path, q) reload return self end |
#is_down ⇒ bool
サーバが停止しているときtrueを返します.
348 349 350 |
# File 'lib/saklient/cloud/resources/server.rb', line 348 def is_down return get_instance.is_down end |
#is_up ⇒ bool
サーバが起動しているときtrueを返します.
341 342 343 |
# File 'lib/saklient/cloud/resources/server.rb', line 341 def is_up return get_instance.is_up end |
#reboot ⇒ Server
サーバを強制再起動します.
379 380 381 382 |
# File 'lib/saklient/cloud/resources/server.rb', line 379 def reboot @_client.request('PUT', _api_path + '/' + Saklient::Util::url_encode(_id) + '/reset') return reload end |
#reload ⇒ Server
最新のリソース情報を再取得します.
127 128 129 |
# File 'lib/saklient/cloud/resources/server.rb', line 127 def reload return _reload end |
#save ⇒ Server
このローカルオブジェクトに現在設定されているリソース情報をAPIに送信し, 新規作成または上書き保存します.
120 121 122 |
# File 'lib/saklient/cloud/resources/server.rb', line 120 def save return _save end |
#shutdown ⇒ Server
サーバをシャットダウンします.
363 364 365 366 |
# File 'lib/saklient/cloud/resources/server.rb', line 363 def shutdown @_client.request('DELETE', _api_path + '/' + Saklient::Util::url_encode(_id) + '/power') return reload end |
#sleep_until_down(timeoutSec = 180) ⇒ bool
サーバが停止するまで待機します.
397 398 399 400 |
# File 'lib/saklient/cloud/resources/server.rb', line 397 def sleep_until_down(timeoutSec = 180) Saklient::Util::validate_type(timeoutSec, 'Fixnum') return sleep_until(Saklient::Cloud::Enums::EServerInstanceStatus::down, timeoutSec) end |
#sleep_until_up(timeoutSec = 180) ⇒ bool
サーバが起動するまで待機します.
388 389 390 391 |
# File 'lib/saklient/cloud/resources/server.rb', line 388 def sleep_until_up(timeoutSec = 180) Saklient::Util::validate_type(timeoutSec, 'Fixnum') return sleep_until(Saklient::Cloud::Enums::EServerInstanceStatus::up, timeoutSec) end |
#sleep_while_copying(timeoutSec = 3600) ⇒ bool
サーバに接続されているコピー中のディスクが利用可能になるまで待機します.
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/saklient/cloud/resources/server.rb', line 494 def (timeoutSec = 3600) Saklient::Util::validate_type(timeoutSec, 'Fixnum') step = 10 disks = find_disks while 0 < timeoutSec do disk = nil begin reload for disk in disks disk.reload end rescue Saklient::Errors::HttpException {} end result = get_availability == Saklient::Cloud::Enums::EAvailability::available for disk in disks result = false if disk.availability != Saklient::Cloud::Enums::EAvailability::available end return true if result timeoutSec -= step sleep(step) if 0 < timeoutSec end return false end |
#stop ⇒ Server
サーバを強制停止します.
371 372 373 374 |
# File 'lib/saklient/cloud/resources/server.rb', line 371 def stop @_client.request('DELETE', _api_path + '/' + Saklient::Util::url_encode(_id) + '/power', { Force: true }) return reload end |