Revision f1331453
src/oca/java/src/org/opennebula/client/image/Image.java | ||
---|---|---|
32 | 32 |
private static final String INFO = METHOD_PREFIX + "info"; |
33 | 33 |
private static final String DELETE = METHOD_PREFIX + "delete"; |
34 | 34 |
private static final String UPDATE = METHOD_PREFIX + "update"; |
35 |
private static final String RMATTR = METHOD_PREFIX + "rmattr"; |
|
36 | 35 |
private static final String ENABLE = METHOD_PREFIX + "enable"; |
37 | 36 |
private static final String PUBLISH = METHOD_PREFIX + "publish"; |
38 | 37 |
private static final String CHOWN = METHOD_PREFIX + "chown"; |
... | ... | |
111 | 110 |
} |
112 | 111 |
|
113 | 112 |
/** |
114 |
* Modifies an image attribute.
|
|
113 |
* Replaces the template contents.
|
|
115 | 114 |
* |
116 | 115 |
* @param client XML-RPC Client. |
117 | 116 |
* @param id The image id of the target image we want to modify. |
118 |
* @param att_name The name of the attribute to update. |
|
119 |
* @param att_val The new value for the attribute. |
|
117 |
* @param new_template New template contents |
|
120 | 118 |
* @return If successful the message contains the image id. |
121 | 119 |
*/ |
122 |
public static OneResponse update(Client client, int id, |
|
123 |
String att_name, String att_val) |
|
120 |
public static OneResponse update(Client client, int id, String new_template) |
|
124 | 121 |
{ |
125 |
return client.call(UPDATE, id, att_name, att_val); |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Removes an image attribute. |
|
130 |
* |
|
131 |
* @param client XML-RPC Client. |
|
132 |
* @param id The image id of the target image we want to modify. |
|
133 |
* @param att_name The name of the attribute to remove. |
|
134 |
* @return If successful the message contains the image id. |
|
135 |
*/ |
|
136 |
public static OneResponse rmattr(Client client, int id, String att_name) |
|
137 |
{ |
|
138 |
return client.call(RMATTR, id, att_name); |
|
122 |
return client.call(UPDATE, id, new_template); |
|
139 | 123 |
} |
140 | 124 |
|
141 | 125 |
/** |
... | ... | |
206 | 190 |
} |
207 | 191 |
|
208 | 192 |
/** |
209 |
* Modifies an image attribute. |
|
210 |
* |
|
211 |
* @param att_name The name of the attribute to update. |
|
212 |
* @param att_val The new value for the attribute. |
|
213 |
* @return If successful the message contains the image id. |
|
214 |
*/ |
|
215 |
public OneResponse update(String att_name, String att_val) |
|
216 |
{ |
|
217 |
return update(client, id, att_name, att_val); |
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* Removes an image attribute. |
|
193 |
* Replaces the template contents. |
|
222 | 194 |
* |
223 |
* @param att_name The name of the attribute to remove.
|
|
195 |
* @param new_template New template contents
|
|
224 | 196 |
* @return If successful the message contains the image id. |
225 | 197 |
*/ |
226 |
public OneResponse rmattr(String att_name)
|
|
198 |
public OneResponse update(String new_template)
|
|
227 | 199 |
{ |
228 |
return rmattr(client, id, att_name);
|
|
200 |
return update(client, id, new_template);
|
|
229 | 201 |
} |
230 | 202 |
|
231 | 203 |
/** |
src/oca/java/src/org/opennebula/client/template/Template.java | ||
---|---|---|
32 | 32 |
private static final String INFO = METHOD_PREFIX + "info"; |
33 | 33 |
private static final String DELETE = METHOD_PREFIX + "delete"; |
34 | 34 |
private static final String UPDATE = METHOD_PREFIX + "update"; |
35 |
private static final String RMATTR = METHOD_PREFIX + "rmattr"; |
|
36 | 35 |
private static final String PUBLISH = METHOD_PREFIX + "publish"; |
37 | 36 |
private static final String CHOWN = METHOD_PREFIX + "chown"; |
37 |
private static final String INSTANTIATE = METHOD_PREFIX + "instantiate"; |
|
38 | 38 |
|
39 | 39 |
/** |
40 | 40 |
* Creates a new Template representation. |
... | ... | |
98 | 98 |
} |
99 | 99 |
|
100 | 100 |
/** |
101 |
* Modifies a template attribute.
|
|
101 |
* Replaces the template contents.
|
|
102 | 102 |
* |
103 | 103 |
* @param client XML-RPC Client. |
104 | 104 |
* @param id The template id of the target template we want to modify. |
105 |
* @param att_name The name of the attribute to update. |
|
106 |
* @param att_val The new value for the attribute. |
|
105 |
* @param new_template New template contents. |
|
107 | 106 |
* @return If successful the message contains the template id. |
108 | 107 |
*/ |
109 |
public static OneResponse update(Client client, int id, |
|
110 |
String att_name, String att_val) |
|
108 |
public static OneResponse update(Client client, int id, String new_template) |
|
111 | 109 |
{ |
112 |
return client.call(UPDATE, id, att_name, att_val); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Removes a template attribute. |
|
117 |
* |
|
118 |
* @param client XML-RPC Client. |
|
119 |
* @param id The template id of the target template we want to modify. |
|
120 |
* @param att_name The name of the attribute to remove. |
|
121 |
* @return If successful the message contains the template id. |
|
122 |
*/ |
|
123 |
public static OneResponse rmattr(Client client, int id, String att_name) |
|
124 |
{ |
|
125 |
return client.call(RMATTR, id, att_name); |
|
110 |
return client.call(UPDATE, id, new_template); |
|
126 | 111 |
} |
127 | 112 |
|
128 | 113 |
/** |
... | ... | |
152 | 137 |
return client.call(CHOWN, id, uid, gid); |
153 | 138 |
} |
154 | 139 |
|
140 |
/** |
|
141 |
* Creates a VM instance from a Template |
|
142 |
* |
|
143 |
* @param client XML-RPC Client. |
|
144 |
* @param id The template id of the target template. |
|
145 |
* @param name A string containing the name of the VM instance, can be empty. |
|
146 |
* @return If successful the message contains the VM Instance ID. |
|
147 |
*/ |
|
148 |
public static OneResponse instantiate(Client client, int id, String name) |
|
149 |
{ |
|
150 |
return client.call(INSTANTIATE, id, name); |
|
151 |
} |
|
152 |
|
|
155 | 153 |
// ================================= |
156 | 154 |
// Instanced object XML-RPC methods |
157 | 155 |
// ================================= |
... | ... | |
180 | 178 |
} |
181 | 179 |
|
182 | 180 |
/** |
183 |
* Modifies a template attribute.
|
|
181 |
* Replaces the template contents.
|
|
184 | 182 |
* |
185 |
* @param att_name The name of the attribute to update. |
|
186 |
* @param att_val The new value for the attribute. |
|
183 |
* @param new_template New template contents. |
|
187 | 184 |
* @return If successful the message contains the template id. |
188 | 185 |
*/ |
189 |
public OneResponse update(String att_name, String att_val)
|
|
186 |
public OneResponse update(String new_template)
|
|
190 | 187 |
{ |
191 |
return update(client, id, att_name, att_val); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Removes a template attribute. |
|
196 |
* |
|
197 |
* @param att_name The name of the attribute to remove. |
|
198 |
* @return If successful the message contains the template id. |
|
199 |
*/ |
|
200 |
public OneResponse rmattr(String att_name) |
|
201 |
{ |
|
202 |
return rmattr(client, id, att_name); |
|
188 |
return update(client, id, new_template); |
|
203 | 189 |
} |
204 | 190 |
|
205 | 191 |
/** |
... | ... | |
267 | 253 |
return chown(-1, gid); |
268 | 254 |
} |
269 | 255 |
|
256 |
/** |
|
257 |
* Creates a VM instance from a Template |
|
258 |
* |
|
259 |
* @param name A string containing the name of the VM instance, can be empty. |
|
260 |
* @return If successful the message contains the VM Instance ID. |
|
261 |
*/ |
|
262 |
public OneResponse instantiate(String name) |
|
263 |
{ |
|
264 |
return instantiate(client, id, name); |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Creates a VM instance from a Template |
|
269 |
* |
|
270 |
* @return If successful the message contains the VM Instance ID. |
|
271 |
*/ |
|
272 |
public OneResponse instantiate() |
|
273 |
{ |
|
274 |
return instantiate(client, id, ""); |
|
275 |
} |
|
276 |
|
|
270 | 277 |
// ================================= |
271 | 278 |
// Helpers |
272 | 279 |
// ================================= |
src/oca/java/test/ImageTest.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
return "NAME = \"test_img_" + cont + "\"\n" + |
45 | 45 |
"PATH = /etc/hosts\n" + |
46 |
"ATT1 = \"val1\""; |
|
46 |
"ATT1 = \"VAL1\"\n" + |
|
47 |
"ATT2 = \"VAL2\""; |
|
47 | 48 |
} |
48 | 49 |
|
49 | 50 |
/** |
... | ... | |
122 | 123 |
@Test |
123 | 124 |
public void update() |
124 | 125 |
{ |
125 |
// Update an existing att. |
|
126 |
res = image.update("ATT1", "new_val_1"); |
|
127 |
assertTrue( !res.isError() ); |
|
128 |
|
|
129 | 126 |
res = image.info(); |
130 | 127 |
assertTrue( !res.isError() ); |
131 |
assertTrue( image.xpath("TEMPLATE/ATT1").equals("new_val_1") ); |
|
132 | 128 |
|
133 |
// Create a new att. |
|
134 |
res = image.update("ATT2", "new_val_2"); |
|
135 |
assertTrue( !res.isError() ); |
|
129 |
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "VAL1" ) ); |
|
130 |
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "VAL2" ) ); |
|
136 | 131 |
|
137 |
res = image.info(); |
|
138 |
assertTrue( !res.isError() ); |
|
139 |
assertTrue( image.xpath("TEMPLATE/ATT2").equals("new_val_2") ); |
|
140 |
} |
|
132 |
String new_template = "ATT2 = NEW_VAL\n" + |
|
133 |
"ATT3 = VAL3"; |
|
141 | 134 |
|
142 |
@Test |
|
143 |
public void rmattr() |
|
144 |
{ |
|
145 |
res = image.rmattr("ATT1"); |
|
135 |
res = image.update(new_template); |
|
146 | 136 |
assertTrue( !res.isError() ); |
147 | 137 |
|
138 |
|
|
148 | 139 |
res = image.info(); |
149 | 140 |
assertTrue( !res.isError() ); |
150 |
|
|
151 |
assertTrue( image.xpath("ATT1").equals("") ); |
|
141 |
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "" ) ); |
|
142 |
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) ); |
|
143 |
assertTrue( image.xpath("TEMPLATE/ATT3").equals( "VAL3" ) ); |
|
152 | 144 |
} |
153 | 145 |
|
146 |
|
|
154 | 147 |
// TODO |
155 | 148 |
// @Test |
156 | 149 |
public void enable() |
src/oca/java/test/TemplateTest.java | ||
---|---|---|
43 | 43 |
|
44 | 44 |
private static String template_str = |
45 | 45 |
"NAME = \"" + name + "\"\n" + |
46 |
"ATT1 = \"val1\""; |
|
46 |
"ATT1 = \"VAL1\"\n" + |
|
47 |
"ATT2 = \"VAL2\""; |
|
47 | 48 |
|
48 | 49 |
/** |
49 | 50 |
* @throws java.lang.Exception |
... | ... | |
121 | 122 |
@Test |
122 | 123 |
public void update() |
123 | 124 |
{ |
124 |
// Update an existing att. |
|
125 |
res = template.update("ATT1", "new_val_1"); |
|
126 |
assertTrue( !res.isError() ); |
|
127 |
|
|
128 | 125 |
res = template.info(); |
129 | 126 |
assertTrue( !res.isError() ); |
130 |
assertTrue( template.xpath("TEMPLATE/ATT1").equals("new_val_1") ); |
|
131 | 127 |
|
132 |
// Create a new att. |
|
133 |
res = template.update("ATT2", "new_val_2"); |
|
134 |
assertTrue( !res.isError() ); |
|
128 |
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "VAL1" ) ); |
|
129 |
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "VAL2" ) ); |
|
135 | 130 |
|
136 |
res = template.info(); |
|
137 |
assertTrue( !res.isError() ); |
|
138 |
assertTrue( template.xpath("TEMPLATE/ATT2").equals("new_val_2") ); |
|
139 |
} |
|
131 |
String new_template = "ATT2 = NEW_VAL\n" + |
|
132 |
"ATT3 = VAL3"; |
|
140 | 133 |
|
141 |
@Test |
|
142 |
public void rmattr() |
|
143 |
{ |
|
144 |
res = template.rmattr("ATT1"); |
|
134 |
res = template.update(new_template); |
|
145 | 135 |
assertTrue( !res.isError() ); |
146 | 136 |
|
137 |
|
|
147 | 138 |
res = template.info(); |
148 | 139 |
assertTrue( !res.isError() ); |
149 |
|
|
150 |
assertTrue( template.xpath("ATT1").equals("") ); |
|
140 |
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "" ) ); |
|
141 |
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) ); |
|
142 |
assertTrue( template.xpath("TEMPLATE/ATT3").equals( "VAL3" ) ); |
|
151 | 143 |
} |
152 | 144 |
|
153 | 145 |
@Test |
... | ... | |
237 | 229 |
assertTrue( template.uid() == uid ); |
238 | 230 |
assertTrue( template.gid() == 0 ); |
239 | 231 |
} |
232 |
|
|
233 |
@Test |
|
234 |
public void instantiate() |
|
235 |
{ |
|
236 |
res = template.instantiate("new_vm_name"); |
|
237 |
assertTrue( !res.isError() ); |
|
238 |
|
|
239 |
int vm_id = Integer.parseInt(res.getMessage()); |
|
240 |
VirtualMachine vm = new VirtualMachine(vm_id, client); |
|
241 |
|
|
242 |
res = vm.info(); |
|
243 |
assertTrue( !res.isError() ); |
|
244 |
|
|
245 |
assertTrue( vm.getName().equals( "new_vm_name" ) ); |
|
246 |
} |
|
240 | 247 |
} |
Also available in: Unified diff