Revision b085ae95 src/sunstone/sunstone-server.rb

View differences:

src/sunstone/sunstone-server.rb
163 163
    @SunstoneServer.create_resource(params[:pool], request.body.read)
164 164
end
165 165

  
166
post '/vm/:id/stopvnc' do
167
    vm = params[:id]
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]
174
        msg = "It seems there is no VNC proxy running for this machine"
175
        return [500, OpenNebula::Error.new(msg).to_json]
176
    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    
186
    end
187
    
188
end
189

  
190
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
    
202
    vnc_hash = session['vnc']
203
    
204
    if !vnc_hash 
205
        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]
208
    end
209
    
210
    session['vnc'][vm]=pipe;
211
    return {:port => port, :password => pw }.to_json
212
    
213
end
214

  
166 215
##############################################################################
167 216
# Perform an action on a Resource
168 217
##############################################################################

Also available in: Unified diff