root / src / com / rackspace / cloud / servers / api / client / ServerManager.java @ 51fdecfb
History | View | Annotate | Download (21.4 kB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.rackspace.cloud.servers.api.client; |
5 |
|
6 |
import java.io.IOException; |
7 |
import java.io.StringReader; |
8 |
import java.io.UnsupportedEncodingException; |
9 |
import java.util.ArrayList; |
10 |
|
11 |
import javax.xml.parsers.FactoryConfigurationError; |
12 |
import javax.xml.parsers.ParserConfigurationException; |
13 |
import javax.xml.parsers.SAXParser; |
14 |
import javax.xml.parsers.SAXParserFactory; |
15 |
|
16 |
import org.apache.http.HttpResponse; |
17 |
import org.apache.http.client.ClientProtocolException; |
18 |
import org.apache.http.client.methods.HttpDelete; |
19 |
import org.apache.http.client.methods.HttpGet; |
20 |
import org.apache.http.client.methods.HttpPost; |
21 |
import org.apache.http.client.methods.HttpPut; |
22 |
import org.apache.http.entity.StringEntity; |
23 |
import org.apache.http.impl.client.BasicResponseHandler; |
24 |
import org.apache.http.protocol.RequestExpectContinue; |
25 |
import org.xml.sax.InputSource; |
26 |
import org.xml.sax.SAXException; |
27 |
import org.xml.sax.XMLReader; |
28 |
|
29 |
import android.content.Context; |
30 |
import android.util.Log; |
31 |
|
32 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
33 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
34 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
35 |
import com.rackspace.cloud.servers.api.client.parsers.ServersXMLParser; |
36 |
|
37 |
/**
|
38 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus
|
39 |
*
|
40 |
*/
|
41 |
public class ServerManager extends EntityManager { |
42 |
|
43 |
public static final String SOFT_REBOOT = "SOFT"; |
44 |
public static final String HARD_REBOOT = "HARD"; |
45 |
|
46 |
public void create(Server entity, Context context) throws CloudServersException { |
47 |
|
48 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
49 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers.xml"); |
50 |
|
51 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
52 |
post.addHeader("Content-Type", "application/xml"); |
53 |
|
54 |
StringEntity tmp = null;
|
55 |
try {
|
56 |
tmp = new StringEntity(entity.toXML());
|
57 |
} catch (UnsupportedEncodingException e) { |
58 |
CloudServersException cse = new CloudServersException();
|
59 |
cse.setMessage(e.getLocalizedMessage()); |
60 |
throw cse;
|
61 |
} |
62 |
post.setEntity(tmp); |
63 |
|
64 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
65 |
|
66 |
try {
|
67 |
HttpResponse resp = httpclient.execute(post); |
68 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
69 |
String body = responseHandler.handleResponse(resp);
|
70 |
|
71 |
if (resp.getStatusLine().getStatusCode() == 202) { |
72 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
73 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
74 |
XMLReader xmlReader = saxParser.getXMLReader(); |
75 |
xmlReader.setContentHandler(serversXMLParser); |
76 |
xmlReader.parse(new InputSource(new StringReader(body))); |
77 |
entity = serversXMLParser.getServer(); |
78 |
} else {
|
79 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
80 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
81 |
XMLReader xmlReader = saxParser.getXMLReader(); |
82 |
xmlReader.setContentHandler(parser); |
83 |
xmlReader.parse(new InputSource(new StringReader(body))); |
84 |
CloudServersException cse = parser.getException(); |
85 |
throw cse;
|
86 |
} |
87 |
} catch (ClientProtocolException e) {
|
88 |
CloudServersException cse = new CloudServersException();
|
89 |
cse.setMessage(e.getLocalizedMessage()); |
90 |
throw cse;
|
91 |
} catch (IOException e) { |
92 |
CloudServersException cse = new CloudServersException();
|
93 |
cse.setMessage(e.getLocalizedMessage()); |
94 |
throw cse;
|
95 |
} catch (FactoryConfigurationError e) { |
96 |
CloudServersException cse = new CloudServersException();
|
97 |
cse.setMessage(e.getLocalizedMessage()); |
98 |
throw cse;
|
99 |
} catch (ParserConfigurationException e) { |
100 |
CloudServersException cse = new CloudServersException();
|
101 |
cse.setMessage(e.getLocalizedMessage()); |
102 |
throw cse;
|
103 |
} catch (SAXException e) {
|
104 |
CloudServersException cse = new CloudServersException();
|
105 |
cse.setMessage(e.getLocalizedMessage()); |
106 |
throw cse;
|
107 |
} |
108 |
} |
109 |
|
110 |
public ArrayList<Server> createList(boolean detail, Context context) throws CloudServersException { |
111 |
|
112 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
113 |
HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/servers/detail.xml" + cacheBuster()); |
114 |
ArrayList<Server> servers = new ArrayList<Server>(); |
115 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
116 |
|
117 |
try {
|
118 |
HttpResponse resp = httpclient.execute(get); |
119 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
120 |
String body = responseHandler.handleResponse(resp);
|
121 |
|
122 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) { |
123 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
124 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
125 |
XMLReader xmlReader = saxParser.getXMLReader(); |
126 |
xmlReader.setContentHandler(serversXMLParser); |
127 |
xmlReader.parse(new InputSource(new StringReader(body))); |
128 |
servers = serversXMLParser.getServers(); |
129 |
} else {
|
130 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
131 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
132 |
XMLReader xmlReader = saxParser.getXMLReader(); |
133 |
xmlReader.setContentHandler(parser); |
134 |
xmlReader.parse(new InputSource(new StringReader(body))); |
135 |
CloudServersException cse = parser.getException(); |
136 |
throw cse;
|
137 |
} |
138 |
} catch (ClientProtocolException e) {
|
139 |
CloudServersException cse = new CloudServersException();
|
140 |
cse.setMessage(e.getLocalizedMessage()); |
141 |
throw cse;
|
142 |
} catch (IOException e) { |
143 |
CloudServersException cse = new CloudServersException();
|
144 |
cse.setMessage(e.getLocalizedMessage()); |
145 |
throw cse;
|
146 |
} catch (ParserConfigurationException e) { |
147 |
CloudServersException cse = new CloudServersException();
|
148 |
cse.setMessage(e.getLocalizedMessage()); |
149 |
throw cse;
|
150 |
} catch (SAXException e) {
|
151 |
CloudServersException cse = new CloudServersException();
|
152 |
cse.setMessage(e.getLocalizedMessage()); |
153 |
throw cse;
|
154 |
} catch (FactoryConfigurationError e) { |
155 |
CloudServersException cse = new CloudServersException();
|
156 |
cse.setMessage(e.getLocalizedMessage()); |
157 |
throw cse;
|
158 |
} |
159 |
|
160 |
|
161 |
return servers;
|
162 |
} |
163 |
|
164 |
public Server find(long id, Context context) throws CloudServersException { |
165 |
|
166 |
Server server = null;
|
167 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
168 |
HttpGet get = new HttpGet(Account.getAccount().getServerUrl() + "/servers/" + id + ".xml" + cacheBuster()); |
169 |
get.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
170 |
|
171 |
try {
|
172 |
HttpResponse resp = httpclient.execute(get); |
173 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
174 |
String body = responseHandler.handleResponse(resp);
|
175 |
|
176 |
if (resp.getStatusLine().getStatusCode() == 200 || resp.getStatusLine().getStatusCode() == 203) { |
177 |
ServersXMLParser serversXMLParser = new ServersXMLParser();
|
178 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
179 |
XMLReader xmlReader = saxParser.getXMLReader(); |
180 |
xmlReader.setContentHandler(serversXMLParser); |
181 |
xmlReader.parse(new InputSource(new StringReader(body))); |
182 |
server = serversXMLParser.getServer(); |
183 |
} else {
|
184 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
185 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
186 |
XMLReader xmlReader = saxParser.getXMLReader(); |
187 |
xmlReader.setContentHandler(parser); |
188 |
xmlReader.parse(new InputSource(new StringReader(body))); |
189 |
CloudServersException cse = parser.getException(); |
190 |
throw cse;
|
191 |
} |
192 |
} catch (ClientProtocolException e) {
|
193 |
CloudServersException cse = new CloudServersException();
|
194 |
cse.setMessage(e.getLocalizedMessage()); |
195 |
throw cse;
|
196 |
} catch (IOException e) { |
197 |
CloudServersException cse = new CloudServersException();
|
198 |
cse.setMessage(e.getLocalizedMessage()); |
199 |
throw cse;
|
200 |
} catch (ParserConfigurationException e) { |
201 |
CloudServersException cse = new CloudServersException();
|
202 |
cse.setMessage(e.getLocalizedMessage()); |
203 |
throw cse;
|
204 |
} catch (SAXException e) {
|
205 |
CloudServersException cse = new CloudServersException();
|
206 |
cse.setMessage(e.getLocalizedMessage()); |
207 |
throw cse;
|
208 |
} catch (FactoryConfigurationError e) { |
209 |
CloudServersException cse = new CloudServersException();
|
210 |
cse.setMessage(e.getLocalizedMessage()); |
211 |
throw cse;
|
212 |
} |
213 |
|
214 |
return server;
|
215 |
} |
216 |
|
217 |
public HttpBundle reboot(Server server, String rebootType, Context context) throws CloudServersException { |
218 |
HttpResponse resp = null;
|
219 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
220 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
221 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
222 |
post.addHeader("Content-Type", "application/xml"); |
223 |
|
224 |
StringEntity tmp = null;
|
225 |
try {
|
226 |
tmp = new StringEntity("<reboot xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" type=\"" + rebootType + "\"/>"); |
227 |
} catch (UnsupportedEncodingException e) { |
228 |
CloudServersException cse = new CloudServersException();
|
229 |
cse.setMessage(e.getLocalizedMessage()); |
230 |
throw cse;
|
231 |
} |
232 |
post.setEntity(tmp); |
233 |
|
234 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
235 |
|
236 |
HttpBundle bundle = new HttpBundle();
|
237 |
bundle.setCurlRequest(post); |
238 |
|
239 |
try {
|
240 |
resp = httpclient.execute(post); |
241 |
bundle.setHttpResponse(resp); |
242 |
} catch (ClientProtocolException e) {
|
243 |
CloudServersException cse = new CloudServersException();
|
244 |
cse.setMessage(e.getLocalizedMessage()); |
245 |
throw cse;
|
246 |
} catch (IOException e) { |
247 |
CloudServersException cse = new CloudServersException();
|
248 |
cse.setMessage(e.getLocalizedMessage()); |
249 |
throw cse;
|
250 |
} catch (FactoryConfigurationError e) { |
251 |
CloudServersException cse = new CloudServersException();
|
252 |
cse.setMessage(e.getLocalizedMessage()); |
253 |
throw cse;
|
254 |
} |
255 |
return bundle;
|
256 |
} |
257 |
|
258 |
public HttpBundle resize(Server server, int flavorId, Context context) throws CloudServersException { |
259 |
HttpResponse resp = null;
|
260 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
261 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
262 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
263 |
post.addHeader("Content-Type", "application/xml"); |
264 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
265 |
|
266 |
StringEntity tmp = null;
|
267 |
try {
|
268 |
tmp = new StringEntity("<resize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" flavorId=\"" + flavorId + "\"/>"); |
269 |
} catch (UnsupportedEncodingException e) { |
270 |
CloudServersException cse = new CloudServersException();
|
271 |
cse.setMessage(e.getLocalizedMessage()); |
272 |
throw cse;
|
273 |
} |
274 |
post.setEntity(tmp); |
275 |
|
276 |
HttpBundle bundle = new HttpBundle();
|
277 |
bundle.setCurlRequest(post); |
278 |
|
279 |
try {
|
280 |
resp = httpclient.execute(post); |
281 |
bundle.setHttpResponse(resp); |
282 |
} catch (ClientProtocolException e) {
|
283 |
CloudServersException cse = new CloudServersException();
|
284 |
cse.setMessage(e.getLocalizedMessage()); |
285 |
throw cse;
|
286 |
} catch (IOException e) { |
287 |
CloudServersException cse = new CloudServersException();
|
288 |
cse.setMessage(e.getLocalizedMessage()); |
289 |
throw cse;
|
290 |
} catch (FactoryConfigurationError e) { |
291 |
CloudServersException cse = new CloudServersException();
|
292 |
cse.setMessage(e.getLocalizedMessage()); |
293 |
throw cse;
|
294 |
} |
295 |
return bundle;
|
296 |
} |
297 |
|
298 |
public HttpBundle confirmResize(Server server, Context context) throws CloudServersException { |
299 |
HttpResponse resp = null;
|
300 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
301 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
302 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
303 |
post.addHeader("Content-Type", "application/xml"); |
304 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
305 |
|
306 |
StringEntity tmp = null;
|
307 |
try {
|
308 |
tmp = new StringEntity("<confirmResize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\"/>"); |
309 |
} catch (UnsupportedEncodingException e) { |
310 |
CloudServersException cse = new CloudServersException();
|
311 |
cse.setMessage(e.getLocalizedMessage()); |
312 |
throw cse;
|
313 |
} |
314 |
post.setEntity(tmp); |
315 |
|
316 |
HttpBundle bundle = new HttpBundle();
|
317 |
bundle.setCurlRequest(post); |
318 |
|
319 |
try {
|
320 |
resp = httpclient.execute(post); |
321 |
bundle.setHttpResponse(resp); |
322 |
} catch (ClientProtocolException e) {
|
323 |
CloudServersException cse = new CloudServersException();
|
324 |
cse.setMessage(e.getLocalizedMessage()); |
325 |
throw cse;
|
326 |
} catch (IOException e) { |
327 |
CloudServersException cse = new CloudServersException();
|
328 |
cse.setMessage(e.getLocalizedMessage()); |
329 |
throw cse;
|
330 |
} catch (FactoryConfigurationError e) { |
331 |
CloudServersException cse = new CloudServersException();
|
332 |
cse.setMessage(e.getLocalizedMessage()); |
333 |
throw cse;
|
334 |
} |
335 |
return bundle;
|
336 |
} |
337 |
|
338 |
public HttpBundle revertResize(Server server, Context context) throws CloudServersException { |
339 |
HttpResponse resp = null;
|
340 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
341 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
342 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
343 |
post.addHeader("Content-Type", "application/xml"); |
344 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
345 |
|
346 |
StringEntity tmp = null;
|
347 |
try {
|
348 |
tmp = new StringEntity("<revertResize xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\"/>"); |
349 |
} catch (UnsupportedEncodingException e) { |
350 |
CloudServersException cse = new CloudServersException();
|
351 |
cse.setMessage(e.getLocalizedMessage()); |
352 |
throw cse;
|
353 |
} |
354 |
post.setEntity(tmp); |
355 |
|
356 |
HttpBundle bundle = new HttpBundle();
|
357 |
bundle.setCurlRequest(post); |
358 |
|
359 |
try {
|
360 |
resp = httpclient.execute(post); |
361 |
bundle.setHttpResponse(resp); |
362 |
} catch (ClientProtocolException e) {
|
363 |
CloudServersException cse = new CloudServersException();
|
364 |
cse.setMessage(e.getLocalizedMessage()); |
365 |
throw cse;
|
366 |
} catch (IOException e) { |
367 |
CloudServersException cse = new CloudServersException();
|
368 |
cse.setMessage(e.getLocalizedMessage()); |
369 |
throw cse;
|
370 |
} catch (FactoryConfigurationError e) { |
371 |
CloudServersException cse = new CloudServersException();
|
372 |
cse.setMessage(e.getLocalizedMessage()); |
373 |
throw cse;
|
374 |
} |
375 |
return bundle;
|
376 |
} |
377 |
|
378 |
public HttpBundle delete(Server server, Context context) throws CloudServersException { |
379 |
HttpResponse resp = null;
|
380 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
381 |
HttpDelete delete = new HttpDelete(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
382 |
delete.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
383 |
delete.addHeader("Content-Type", "application/xml"); |
384 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
385 |
|
386 |
HttpBundle bundle = new HttpBundle();
|
387 |
bundle.setCurlRequest(delete); |
388 |
|
389 |
try {
|
390 |
resp = httpclient.execute(delete); |
391 |
bundle.setHttpResponse(resp); |
392 |
} catch (ClientProtocolException e) {
|
393 |
CloudServersException cse = new CloudServersException();
|
394 |
cse.setMessage(e.getLocalizedMessage()); |
395 |
throw cse;
|
396 |
} catch (IOException e) { |
397 |
CloudServersException cse = new CloudServersException();
|
398 |
cse.setMessage(e.getLocalizedMessage()); |
399 |
throw cse;
|
400 |
} catch (FactoryConfigurationError e) { |
401 |
CloudServersException cse = new CloudServersException();
|
402 |
cse.setMessage(e.getLocalizedMessage()); |
403 |
throw cse;
|
404 |
} |
405 |
return bundle;
|
406 |
} |
407 |
|
408 |
public HttpBundle rename(Server server, String name, Context context) throws CloudServersException{ |
409 |
HttpResponse resp = null;
|
410 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
411 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
412 |
|
413 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
414 |
put.addHeader("Content-Type", "application/xml"); |
415 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
416 |
|
417 |
StringEntity tmp = null;
|
418 |
try {
|
419 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" name=\"" + name + "\"/>"); |
420 |
} catch (UnsupportedEncodingException e) { |
421 |
CloudServersException cse = new CloudServersException();
|
422 |
cse.setMessage(e.getLocalizedMessage()); |
423 |
throw cse;
|
424 |
} |
425 |
put.setEntity(tmp); |
426 |
|
427 |
HttpBundle bundle = new HttpBundle();
|
428 |
bundle.setCurlRequest(put); |
429 |
|
430 |
try {
|
431 |
resp = httpclient.execute(put); |
432 |
bundle.setHttpResponse(resp); |
433 |
} catch (ClientProtocolException e) {
|
434 |
CloudServersException cse = new CloudServersException();
|
435 |
cse.setMessage(e.getLocalizedMessage()); |
436 |
throw cse;
|
437 |
} catch (IOException e) { |
438 |
CloudServersException cse = new CloudServersException();
|
439 |
cse.setMessage(e.getLocalizedMessage()); |
440 |
throw cse;
|
441 |
} catch (FactoryConfigurationError e) { |
442 |
CloudServersException cse = new CloudServersException();
|
443 |
cse.setMessage(e.getLocalizedMessage()); |
444 |
throw cse;
|
445 |
} |
446 |
return bundle;
|
447 |
} |
448 |
|
449 |
public HttpBundle rebuild(Server server, int imageId, Context context) throws CloudServersException { |
450 |
HttpResponse resp = null;
|
451 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
452 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
453 |
|
454 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
455 |
post.addHeader("Content-Type", "application/xml"); |
456 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
457 |
|
458 |
StringEntity tmp = null;
|
459 |
try {
|
460 |
tmp = new StringEntity("<rebuild xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" imageId=\"" + imageId + "\"/>"); |
461 |
} catch (UnsupportedEncodingException e) { |
462 |
CloudServersException cse = new CloudServersException();
|
463 |
cse.setMessage(e.getLocalizedMessage()); |
464 |
throw cse;
|
465 |
} |
466 |
post.setEntity(tmp); |
467 |
|
468 |
HttpBundle bundle = new HttpBundle();
|
469 |
bundle.setCurlRequest(post); |
470 |
|
471 |
try {
|
472 |
resp = httpclient.execute(post); |
473 |
bundle.setHttpResponse(resp); |
474 |
} catch (ClientProtocolException e) {
|
475 |
CloudServersException cse = new CloudServersException();
|
476 |
cse.setMessage(e.getLocalizedMessage()); |
477 |
throw cse;
|
478 |
} catch (IOException e) { |
479 |
CloudServersException cse = new CloudServersException();
|
480 |
cse.setMessage(e.getLocalizedMessage()); |
481 |
throw cse;
|
482 |
} catch (FactoryConfigurationError e) { |
483 |
CloudServersException cse = new CloudServersException();
|
484 |
cse.setMessage(e.getLocalizedMessage()); |
485 |
throw cse;
|
486 |
} |
487 |
return bundle;
|
488 |
} |
489 |
|
490 |
public HttpBundle backup(Server server, String weeklyValue, String dailyValue, boolean enabled, Context context) throws CloudServersException { |
491 |
HttpResponse resp = null;
|
492 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
493 |
HttpPost post = new HttpPost(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + "/backup_schedule.xml"); |
494 |
|
495 |
post.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
496 |
post.addHeader("Content-Type", "application/xml"); |
497 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
498 |
|
499 |
StringEntity tmp = null;
|
500 |
try {
|
501 |
tmp = new StringEntity("<backupSchedule xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" enabled=\"" + enabled + "\" " + |
502 |
"weekly=\"" + weeklyValue + "\" daily=\"" + dailyValue + "\"/>"); |
503 |
|
504 |
} catch (UnsupportedEncodingException e) { |
505 |
CloudServersException cse = new CloudServersException();
|
506 |
cse.setMessage(e.getLocalizedMessage()); |
507 |
throw cse;
|
508 |
} |
509 |
post.setEntity(tmp); |
510 |
|
511 |
HttpBundle bundle = new HttpBundle();
|
512 |
bundle.setCurlRequest(post); |
513 |
|
514 |
try {
|
515 |
resp = httpclient.execute(post); |
516 |
bundle.setHttpResponse(resp); |
517 |
} catch (ClientProtocolException e) {
|
518 |
CloudServersException cse = new CloudServersException();
|
519 |
cse.setMessage(e.getLocalizedMessage()); |
520 |
throw cse;
|
521 |
} catch (IOException e) { |
522 |
CloudServersException cse = new CloudServersException();
|
523 |
cse.setMessage(e.getLocalizedMessage()); |
524 |
throw cse;
|
525 |
} catch (FactoryConfigurationError e) { |
526 |
CloudServersException cse = new CloudServersException();
|
527 |
cse.setMessage(e.getLocalizedMessage()); |
528 |
throw cse;
|
529 |
} |
530 |
return bundle;
|
531 |
} |
532 |
|
533 |
public HttpBundle changePassword(Server server, String password, Context context) throws CloudServersException{ |
534 |
HttpResponse resp = null;
|
535 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
536 |
HttpPut put = new HttpPut(Account.getAccount().getServerUrl() + "/servers/" + server.getId() + ".xml"); |
537 |
|
538 |
put.addHeader("X-Auth-Token", Account.getAccount().getAuthToken());
|
539 |
put.addHeader("Content-Type", "application/xml"); |
540 |
httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); |
541 |
|
542 |
StringEntity tmp = null;
|
543 |
try {
|
544 |
tmp = new StringEntity("<server xmlns=\"http://docs.rackspacecloud.com/servers/api/v1.0\" adminPass=\"" + password + "\"/>"); |
545 |
} catch (UnsupportedEncodingException e) { |
546 |
CloudServersException cse = new CloudServersException();
|
547 |
cse.setMessage(e.getLocalizedMessage()); |
548 |
throw cse;
|
549 |
} |
550 |
put.setEntity(tmp); |
551 |
|
552 |
HttpBundle bundle = new HttpBundle();
|
553 |
bundle.setCurlRequest(put); |
554 |
|
555 |
try {
|
556 |
resp = httpclient.execute(put); |
557 |
bundle.setHttpResponse(resp); |
558 |
} catch (ClientProtocolException e) {
|
559 |
CloudServersException cse = new CloudServersException();
|
560 |
cse.setMessage(e.getLocalizedMessage()); |
561 |
throw cse;
|
562 |
} catch (IOException e) { |
563 |
CloudServersException cse = new CloudServersException();
|
564 |
cse.setMessage(e.getLocalizedMessage()); |
565 |
throw cse;
|
566 |
} catch (FactoryConfigurationError e) { |
567 |
CloudServersException cse = new CloudServersException();
|
568 |
cse.setMessage(e.getLocalizedMessage()); |
569 |
throw cse;
|
570 |
} |
571 |
return bundle;
|
572 |
} |
573 |
|
574 |
|
575 |
} |