Class: IIJ::Sakagura::GP::GC

Inherits:
Object
  • Object
show all
Defined in:
lib/iij/sakagura/gp/gc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, gp_service_code, gc_service_code) ⇒ GC

Returns a new instance of GC.



7
8
9
10
11
# File 'lib/iij/sakagura/gp/gc.rb', line 7

def initialize(client, gp_service_code, gc_service_code)
  @client = client
  @gp_service_code = gp_service_code
  @gc_service_code = gc_service_code
end

Instance Attribute Details

#gc_service_codeObject (readonly)

Returns the value of attribute gc_service_code.



13
14
15
# File 'lib/iij/sakagura/gp/gc.rb', line 13

def gc_service_code
  @gc_service_code
end

#gp_service_codeObject (readonly)

Returns the value of attribute gp_service_code.



12
13
14
# File 'lib/iij/sakagura/gp/gc.rb', line 12

def gp_service_code
  @gp_service_code
end

Instance Method Details

#[](attr) ⇒ Object



40
41
42
# File 'lib/iij/sakagura/gp/gc.rb', line 40

def [](attr)
  info[attr]
end

#attach_fwlb(gl_service_code) ⇒ Object



106
107
108
# File 'lib/iij/sakagura/gp/gc.rb', line 106

def attach_fwlb(gl_service_code)
  call('AttachFwLb', "GlServiceCode" => gl_service_code)
end

#call(api_name, params = {}) ⇒ Object



132
133
134
# File 'lib/iij/sakagura/gp/gc.rb', line 132

def call(api_name, params = {})
  @client.post(api_name, default_args.merge(params))
end

#change_vm_type(vm_type) ⇒ Object



102
103
104
# File 'lib/iij/sakagura/gp/gc.rb', line 102

def change_vm_type(vm_type)
  call('ChangeVirtualMachineType', "VirtualMachineType" => vm_type)
end

#contract_status(opts = {}) ⇒ Object



48
49
50
51
52
# File 'lib/iij/sakagura/gp/gc.rb', line 48

def contract_status(opts = {})
  @contract_status = nil if opts[:force]
  @contract_status ||= get_contract_status
  @contract_status
end

#contract_status!Object



54
55
56
# File 'lib/iij/sakagura/gp/gc.rb', line 54

def contract_status!
  contract_status(:force => true)
end

#default_argsObject



19
20
21
22
23
24
# File 'lib/iij/sakagura/gp/gc.rb', line 19

def default_args
  {
    "GpServiceCode" => gp_service_code,
    "GcServiceCode" => gc_service_code
  }
end

#describe_virtual_machineObject



26
27
28
# File 'lib/iij/sakagura/gp/gc.rb', line 26

def describe_virtual_machine
  call('DescribeVirtualMachine')
end

#detach_fwlb(gl_service_code) ⇒ Object



110
111
112
# File 'lib/iij/sakagura/gp/gc.rb', line 110

def detach_fwlb(gl_service_code)
  call('DetachFwLb', "GlServiceCode" => gl_service_code)
end

#get_contract_statusObject



44
45
46
# File 'lib/iij/sakagura/gp/gc.rb', line 44

def get_contract_status
  call('GetContractStatus')['Status']
end

#get_virtual_machine_statusObject



58
59
60
# File 'lib/iij/sakagura/gp/gc.rb', line 58

def get_virtual_machine_status
  call('GetVirtualMachineStatus')['Status']
end

#import_ssh_public_key(public_key) ⇒ Object



90
91
92
# File 'lib/iij/sakagura/gp/gc.rb', line 90

def import_ssh_public_key(public_key)
  call('ImportRootSshPublicKey', "PublicKey" => public_key)
end

#info(opts = {}) ⇒ Object



30
31
32
33
34
# File 'lib/iij/sakagura/gp/gc.rb', line 30

def info(opts = {})
  @info = nil if opts[:force]
  @info ||= describe_virtual_machine
  @info
end

#info!Object



36
37
38
# File 'lib/iij/sakagura/gp/gc.rb', line 36

def info!
  info(:force => true)
end

#initialize_vm(var_device_name = nil) ⇒ Object



84
85
86
87
88
# File 'lib/iij/sakagura/gp/gc.rb', line 84

def initialize_vm(var_device_name = nil)
  opts = {}
  opts["VarDeviceName"] = var_device_name if var_device_name
  call('InitializeVirtualMachine', opts)
end

#inspectObject



15
16
17
# File 'lib/iij/sakagura/gp/gc.rb', line 15

def inspect
  %[#<#{self.class.name} @gp_service_code="#{gp_service_code}", @gc_service_code="#{gc_service_code}">]
end

#rebootObject



80
81
82
# File 'lib/iij/sakagura/gp/gc.rb', line 80

def reboot
  call('RebootVirtualMachine')
end

#set_label(label) ⇒ Object Also known as: label=



94
95
96
97
98
99
# File 'lib/iij/sakagura/gp/gc.rb', line 94

def set_label(label)
  @client.post("SetLabel",
               "GpServiceCode" => gp_service_code,
               "ServiceCode" => gc_service_code,
               "Label" => label)
end

#startObject



72
73
74
# File 'lib/iij/sakagura/gp/gc.rb', line 72

def start
  call('StartVirtualMachine')
end

#status(opts = {}) ⇒ Object



62
63
64
65
66
# File 'lib/iij/sakagura/gp/gc.rb', line 62

def status(opts = {})
  @status = nil if opts[:force]
  @status ||= get_virtual_machine_status
  @status
end

#status!Object



68
69
70
# File 'lib/iij/sakagura/gp/gc.rb', line 68

def status!
  status(:force => true)
end

#stop(force = false) ⇒ Object



76
77
78
# File 'lib/iij/sakagura/gp/gc.rb', line 76

def stop(force = false)
  call('StopVirtualMachine', { "Force" => force ? "Yes" : "No" })
end

#wait_for_start(opts = {}, &block) ⇒ Object



114
115
116
# File 'lib/iij/sakagura/gp/gc.rb', line 114

def wait_for_start(opts = {}, &block)
  wait_while(proc { status! == "Starting" }, opts, &block)
end

#wait_for_stop(opts = {}, &block) ⇒ Object



118
119
120
# File 'lib/iij/sakagura/gp/gc.rb', line 118

def wait_for_stop(opts = {}, &block)
  wait_while(proc { status! == "Stopping" }, opts, &block)
end

#wait_while(checker, opts = {}, &block) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/iij/sakagura/gp/gc.rb', line 122

def wait_while(checker, opts = {}, &block)
  opts[:wait_sec] ||= 10
  catch(:abort) do
    while checker.call
      block.call if block
      sleep opts[:wait_sec]
    end
  end
end