Revision 6509e422 src/sunstone/sunstone-server.rb

View differences:

src/sunstone/sunstone-server.rb
164 164
end
165 165

  
166 166
post '/vm/:id/stopvnc' do
167
    vm = params[:id]
167
    vm_id = params[:id]
168 168
    vnc_hash = session['vnc']
169
    
170
    if !vnc_hash
171
        msg = "Ups, no VNC sessions information found. Cannot stop VNC"
172
        return [500, OpenNebula::Error.new(msg).to_json]
173
    elsif !vnc_hash[vm]
169

  
170
    if !vnc_hash || !vnc_hash[vm_id]
174 171
        msg = "It seems there is no VNC proxy running for this machine"
175
        return [500, OpenNebula::Error.new(msg).to_json]
172
        return [403, OpenNebula::Error.new(msg).to_json]
176 173
    end
177
    
178
    pipe = session['vnc'][vm]
179
    rc = @SunstoneServer.stopvnc(vm,pipe)
180
    
181
    if (OpenNebula.is_error?(rc))
182
        return [500, rc.to_json]
183
    else
184
        session['vnc'].delete(vm)
185
        return    
174

  
175
    rc = @SunstoneServer.stopvnc(vm_id, vnc_hash[vm_id])
176
    if rc[0] == 200
177
        session['vnc'].delete(vm_id)
186 178
    end
187
    
179

  
180
    rc
188 181
end
189 182

  
190 183
post '/vm/:id/startvnc' do
191
    vm = params[:id]
192
    info = @SunstoneServer.startvnc(vm)
193
    
194
    if OpenNebula.is_error?(info)
195
        return [500,info.to_json]
196
    end
197
    
198
    port = info[:port] #port to connect to
199
    pw = info[:password]
200
    pipe = info[:pipe]
201
    
184
    vm_id = params[:id]
185

  
202 186
    vnc_hash = session['vnc']
203
    
204
    if !vnc_hash 
187

  
188
    if !vnc_hash
205 189
        session['vnc']= {}
206
    elsif vnc_hash and vnc_hash[vm]
207
        return [500, OpenNebula::Error.new("There is a VNC server running for this VM").to_json]
190
    elsif vnc_hash[vm_id]
191
        msg = "There is a VNC server running for this VM"
192
        return [403, OpenNebula::Error.new(msg).to_json]
193
    end
194

  
195
    rc = @SunstoneServer.startvnc(vm_id)
196
    if rc[0] == 200
197
        info = rc[1]
198
        session['vnc'][vm_id] = info[:pipe]
199
        info.delete(:pipe)
200

  
201
        [200, info.to_json]
202
    else
203
        rc
208 204
    end
209
    
210
    session['vnc'][vm]=pipe;
211
    return {:port => port, :password => pw }.to_json
212
    
213 205
end
214 206

  
215 207
##############################################################################

Also available in: Unified diff