Revision f58bf9f4 src/com/rackspace/cloud/servers/api/client/ServerManager.java
b/src/com/rackspace/cloud/servers/api/client/ServerManager.java | ||
---|---|---|
18 | 18 |
import org.apache.http.client.methods.HttpDelete; |
19 | 19 |
import org.apache.http.client.methods.HttpGet; |
20 | 20 |
import org.apache.http.client.methods.HttpPost; |
21 |
import org.apache.http.client.methods.HttpPut; |
|
21 | 22 |
import org.apache.http.entity.StringEntity; |
22 | 23 |
import org.apache.http.impl.client.BasicResponseHandler; |
23 | 24 |
import org.apache.http.impl.client.DefaultHttpClient; |
... | ... | |
312 | 313 |
} |
313 | 314 |
return resp; |
314 | 315 |
} |
316 |
|
|
317 |
public HttpResponse rename(Server server, String name) throws CloudServersException{ |
|
318 |
HttpResponse resp = null; |
|
319 |
DefaultHttpClient httpclient = new DefaultHttpClient(); |
|
320 |
HttpPut put = new HttpPut(Account.getServerUrl() + "/servers/" + server.getId() + ".xml"); |
|
321 |
|
|
322 |
put.addHeader("X-Auth-Token", Account.getAuthToken()); |
|
323 |
put.addHeader("Content-Type", "application/xml"); |
|
324 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); //*******FIND OUT WITH THIS DOES? |
|
325 |
|
|
326 |
StringEntity tmp = null; |
|
327 |
try { |
|
328 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" name=\"" + name + "\"/>"); |
|
329 |
} catch (UnsupportedEncodingException e) { |
|
330 |
CloudServersException cse = new CloudServersException(); |
|
331 |
cse.setMessage(e.getLocalizedMessage()); |
|
332 |
throw cse; |
|
333 |
} |
|
334 |
put.setEntity(tmp); |
|
335 |
|
|
336 |
try { |
|
337 |
resp = httpclient.execute(put); |
|
338 |
} catch (ClientProtocolException e) { |
|
339 |
CloudServersException cse = new CloudServersException(); |
|
340 |
cse.setMessage(e.getLocalizedMessage()); |
|
341 |
throw cse; |
|
342 |
} catch (IOException e) { |
|
343 |
CloudServersException cse = new CloudServersException(); |
|
344 |
cse.setMessage(e.getLocalizedMessage()); |
|
345 |
throw cse; |
|
346 |
} catch (FactoryConfigurationError e) { |
|
347 |
CloudServersException cse = new CloudServersException(); |
|
348 |
cse.setMessage(e.getLocalizedMessage()); |
|
349 |
throw cse; |
|
350 |
} |
|
351 |
return resp; |
|
352 |
} |
|
353 |
|
|
354 |
public HttpResponse rebuild(Server server, int imageId) throws CloudServersException { |
|
355 |
HttpResponse resp = null; |
|
356 |
DefaultHttpClient httpclient = new DefaultHttpClient(); |
|
357 |
HttpPost post = new HttpPost(Account.getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
|
358 |
|
|
359 |
post.addHeader("X-Auth-Token", Account.getAuthToken()); |
|
360 |
post.addHeader("Content-Type", "application/xml"); |
|
361 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
362 |
|
|
363 |
StringEntity tmp = null; |
|
364 |
try { |
|
365 |
tmp = new StringEntity("<rebuild xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" imageId=\"" + imageId + "\"/>"); |
|
366 |
} catch (UnsupportedEncodingException e) { |
|
367 |
CloudServersException cse = new CloudServersException(); |
|
368 |
cse.setMessage(e.getLocalizedMessage()); |
|
369 |
throw cse; |
|
370 |
} |
|
371 |
post.setEntity(tmp); |
|
372 |
|
|
373 |
try { |
|
374 |
resp = httpclient.execute(post); |
|
375 |
} catch (ClientProtocolException e) { |
|
376 |
CloudServersException cse = new CloudServersException(); |
|
377 |
cse.setMessage(e.getLocalizedMessage()); |
|
378 |
throw cse; |
|
379 |
} catch (IOException e) { |
|
380 |
CloudServersException cse = new CloudServersException(); |
|
381 |
cse.setMessage(e.getLocalizedMessage()); |
|
382 |
throw cse; |
|
383 |
} catch (FactoryConfigurationError e) { |
|
384 |
CloudServersException cse = new CloudServersException(); |
|
385 |
cse.setMessage(e.getLocalizedMessage()); |
|
386 |
throw cse; |
|
387 |
} |
|
388 |
return resp; |
|
389 |
} |
|
315 | 390 |
|
391 |
public HttpResponse backup(Server server, String weeklyValue, String dailyValue, boolean enabled) throws CloudServersException { |
|
392 |
HttpResponse resp = null; |
|
393 |
DefaultHttpClient httpclient = new DefaultHttpClient(); |
|
394 |
HttpPost post = new HttpPost(Account.getServerUrl() + "/servers/" + server.getId() + "/backup_schedule.xml"); |
|
395 |
|
|
396 |
post.addHeader("X-Auth-Token", Account.getAuthToken()); |
|
397 |
post.addHeader("Content-Type", "application/xml"); |
|
398 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
399 |
|
|
400 |
StringEntity tmp = null; |
|
401 |
try { |
|
402 |
tmp = new StringEntity("<backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
|
403 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
|
404 |
|
|
405 |
} catch (UnsupportedEncodingException e) { |
|
406 |
CloudServersException cse = new CloudServersException(); |
|
407 |
cse.setMessage(e.getLocalizedMessage()); |
|
408 |
throw cse; |
|
409 |
} |
|
410 |
post.setEntity(tmp); |
|
411 |
|
|
412 |
try { |
|
413 |
resp = httpclient.execute(post); |
|
414 |
} catch (ClientProtocolException e) { |
|
415 |
CloudServersException cse = new CloudServersException(); |
|
416 |
cse.setMessage(e.getLocalizedMessage()); |
|
417 |
throw cse; |
|
418 |
} catch (IOException e) { |
|
419 |
CloudServersException cse = new CloudServersException(); |
|
420 |
cse.setMessage(e.getLocalizedMessage()); |
|
421 |
throw cse; |
|
422 |
} catch (FactoryConfigurationError e) { |
|
423 |
CloudServersException cse = new CloudServersException(); |
|
424 |
cse.setMessage(e.getLocalizedMessage()); |
|
425 |
throw cse; |
|
426 |
} |
|
427 |
return resp; |
|
428 |
} |
|
429 |
|
|
430 |
public HttpResponse changePassword(Server server, String password) throws CloudServersException{ |
|
431 |
HttpResponse resp = null; |
|
432 |
DefaultHttpClient httpclient = new DefaultHttpClient(); |
|
433 |
HttpPut put = new HttpPut(Account.getServerUrl() + "/servers/" + server.getId() + ".xml"); |
|
434 |
|
|
435 |
put.addHeader("X-Auth-Token", Account.getAuthToken()); |
|
436 |
put.addHeader("Content-Type", "application/xml"); |
|
437 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
|
438 |
|
|
439 |
StringEntity tmp = null; |
|
440 |
try { |
|
441 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" adminPass=\"" + password + "\"/>"); |
|
442 |
} catch (UnsupportedEncodingException e) { |
|
443 |
CloudServersException cse = new CloudServersException(); |
|
444 |
cse.setMessage(e.getLocalizedMessage()); |
|
445 |
throw cse; |
|
446 |
} |
|
447 |
put.setEntity(tmp); |
|
448 |
|
|
449 |
try { |
|
450 |
resp = httpclient.execute(put); |
|
451 |
} catch (ClientProtocolException e) { |
|
452 |
CloudServersException cse = new CloudServersException(); |
|
453 |
cse.setMessage(e.getLocalizedMessage()); |
|
454 |
throw cse; |
|
455 |
} catch (IOException e) { |
|
456 |
CloudServersException cse = new CloudServersException(); |
|
457 |
cse.setMessage(e.getLocalizedMessage()); |
|
458 |
throw cse; |
|
459 |
} catch (FactoryConfigurationError e) { |
|
460 |
CloudServersException cse = new CloudServersException(); |
|
461 |
cse.setMessage(e.getLocalizedMessage()); |
|
462 |
throw cse; |
|
463 |
} |
|
464 |
return resp; |
|
465 |
} |
|
466 |
|
|
316 | 467 |
} |
Also available in: Unified diff