Revision b085ae95 src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb

View differences:

src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb
55 55
                when "restart"      then self.restart
56 56
                when "saveas"       then self.save_as(action_hash['params'])
57 57
                when "shutdown"     then self.shutdown
58
		when "resubmit"     then self.resubmit
58
                when "resubmit"     then self.resubmit
59
                when "startvnc"     then self.startvnc
60
                when "stopvnc"      then self.stopvnc
59 61
                else
60 62
                    error_msg = "#{action_hash['perform']} action not " <<
61 63
                                " available for this resource"
......
118 120

  
119 121
            super(params['disk_id'].to_i, image.id)
120 122
        end
123
        
124
        def startvnc(port)
125
            result = self.info();
126
            if OpenNebula.is_error?(result)
127
                return result
128
            end
129
            
130
            if self['LCM_STATE'] != "3"
131
                return OpenNebula::Error.new("VM is not running");
132
            end
133
            
134
            if self['TEMPLATE/GRAPHICS/TYPE'] != "vnc"
135
                return OpenNebula::Error.new("VM has no VNC configured");
136
            end
137
                      
138
            if self['TEMPLATE/GRAPHICS/PORT']
139
                vnc_port = self['TEMPLATE/GRAPHICS/PORT']
140
            else
141
                return OpenNebula::Error.new("VM has no VNC port set");
142
            end
143
            
144
            if self['TEMPLATE/GRAPHICS/PASSWD']
145
                vnc_pw = self['TEMPLATE/GRAPHICS/PASSWD']
146
            else
147
                vnc_pw = ""
148
            end
149
            
150
            host = self['HISTORY/HOSTNAME']
151
            
152
            #we are ready for the party
153
            
154
            final_port = 29876+port.to_i;
155
            
156
            # puts "Launch noVNC on #{final_port} listenting to #{host}:#{vnc_port}"
157
            # So here we launch the noVNC server listening on the final_port 
158
            # and serving as proxy for the VM host on the configured VNC port.
159
            # TODO - This path is in public...            
160
            pipe = IO.popen("#{File.dirname(__FILE__)}/../../public/vendor/noVNC/utils/launch.sh --listen #{final_port} --vnc #{host}:#{vnc_port}")
161
            
162
            return {:pipe => pipe, :port => final_port, :password => vnc_pw}
163
            
164
        end
165
        
166
        def stopvnc(pipe)
167
            #am I allowed to do something affecting this machine?
168
            result = self.info();
169
            if OpenNebula.is_error?(result)
170
                return result
171
            end
172
            pid = pipe.pid
173
            # puts "Killing noVNC with pid #{pid}"
174
            Process.kill('KILL',pid)
175
            pipe.close
176
            return
177
        end
178
        
121 179
    end
122 180
end

Also available in: Unified diff