Class: Dcmgr::Rpc::HvaHandler
Instance Method Summary
collapse
#find_nic, #nic_state, #valid_nic?
Methods included from KvmHelper
#connect_monitor
#sh, #tryagain
Methods included from Logger
create, default_logdev, included
Instance Method Details
#attach_volume_to_host ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 38
def attach_volume_to_host
get_linux_dev_path
tryagain do
next true if File.exist?(@os_devpath)
sh("iscsiadm -m discovery -t sendtargets -p %s", [@vol[:storage_pool][:ipaddr]])
sh("iscsiadm -m node -l -T '%s' --portal '%s'",
[@vol[:transport_information][:iqn], @vol[:storage_pool][:ipaddr]])
sleep 1
end
rpc.request('sta-collector', 'update_volume', @vol_id, {
:state=>:attaching,
:attached_at => nil,
:host_device_name => @os_devpath})
end
|
#check_interface ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 87
def check_interface
vnic = @inst[:instance_nics].first
unless vnic.nil?
network_map = rpc.request('hva-collector', 'get_network', @inst[:instance_nics].first[:network_id])
physical_if = find_nic(@node.manifest.config.hv_ifindex)
raise "UnknownPhysicalNIC" if physical_if.nil?
if network_map[:vlan_id] == 0
bridge_if = @node.manifest.config.bridge_novlan
unless valid_nic?(bridge_if)
sh("/usr/sbin/brctl addbr %s", [bridge_if])
sh("/usr/sbin/brctl addif %s %s", [bridge_if, physical_if])
end
else
vlan_if = "#{physical_if}.#{network_map[:vlan_id]}"
unless valid_nic?(vlan_if)
sh("/sbin/vconfig add #{physical_if} #{network_map[:vlan_id]}")
end
bridge_if = "#{@node.manifest.config.bridge_prefix}-#{physical_if}.#{network_map[:vlan_id]}"
unless valid_nic?(bridge_if)
sh("/usr/sbin/brctl addbr %s", [bridge_if])
sh("/usr/sbin/brctl addif %s %s", [bridge_if, vlan_if])
end
end
[ vlan_if, bridge_if ].each do |ifname|
if nic_state(ifname) == "down"
sh("/sbin/ifconfig #{ifname} 0.0.0.0 up")
end
end
sleep 1
bridge_if
end
end
|
#detach_volume_from_host ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 58
def detach_volume_from_host
sh("iscsiadm -m node -T '%s' --logout", [@vol[:transport_information][:iqn]])
rpc.request('sta-collector', 'update_volume', @vol_id, {
:state=>:available,
:host_device_name=>nil,
:instance_id=>nil,
:detached_at => Time.now.utc,
})
event.publish('hva/volume_detached', :args=>[@inst_id, @vol_id])
end
|
#event ⇒ Object
346
347
348
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 346
def event
@event ||= Isono::NodeModules::EventChannel.new(@node)
end
|
#get_linux_dev_path ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 130
def get_linux_dev_path
@os_devpath = "/dev/disk/by-path/ip-%s-iscsi-%s-lun-%d" % ["#{@vol[:storage_pool][:ipaddr]}:3260",
@vol[:transport_information][:iqn],
@vol[:transport_information][:lun]]
end
|
#jobreq ⇒ Object
342
343
344
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 342
def jobreq
@jobreq ||= Isono::NodeModules::JobChannel.new(@node)
end
|
#rpc ⇒ Object
338
339
340
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 338
def rpc
@rpc ||= Isono::NodeModules::RpcChannel.new(@node)
end
|
#select_hypervisor ⇒ Object
34
35
36
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 34
def select_hypervisor
@hv = Dcmgr::Drivers::Hypervisor.select_hypervisor(@inst[:instance_spec][:hypervisor])
end
|
#terminate_instance ⇒ Object
70
71
72
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 70
def terminate_instance
@hv.terminate_instance(HvaContext.new(self))
end
|
#update_instance_state(opts, ev) ⇒ Object
75
76
77
78
79
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 75
def update_instance_state(opts, ev)
raise "Can't update instance info without setting @inst_id" if @inst_id.nil?
rpc.request('hva-collector', 'update_instance', @inst_id, opts)
event.publish(ev, :args=>[@inst_id])
end
|
#update_volume_state(opts, ev) ⇒ Object
81
82
83
84
85
|
# File 'lib/dcmgr/rpc/hva_handler.rb', line 81
def update_volume_state(opts, ev)
raise "Can't update volume info without setting @vol_id" if @vol_id.nil?
rpc.request('sta-collector', 'update_volume', @vol_id, opts)
event.publish(ev, :args=>[@vol_id])
end
|