Revision bdff03d5
b/kamaki/cli/commands/network.py | ||
---|---|---|
368 | 368 |
@errors.generic.all |
369 | 369 |
@errors.cyclades.connection |
370 | 370 |
def _run(self, subnet_id): |
371 |
r = self.client.get_subnet_details(subnet_id) |
|
372 |
r = self.client.update_subnet( |
|
373 |
subnet_id, r['network_id'], name=self['new_name']) |
|
371 |
r = self.client.update_subnet(subnet_id, name=self['new_name']) |
|
374 | 372 |
self._print(r, self.print_dict) |
375 | 373 |
|
376 | 374 |
def main(self, subnet_id): |
b/kamaki/clients/network/__init__.py | ||
---|---|---|
186 | 186 |
return r.json |
187 | 187 |
|
188 | 188 |
def update_subnet( |
189 |
self, network_id, cidr,
|
|
190 |
name=None, allocation_pools=None, gateway_ip=None, subnet_id=None,
|
|
191 |
ipv6=None, enable_dhcp=None):
|
|
189 |
self, subnet_id,
|
|
190 |
name=None, allocation_pools=None, gateway_ip=None, ipv6=None,
|
|
191 |
enable_dhcp=None): |
|
192 | 192 |
""" |
193 |
:param network_id: (str) used as filter |
|
194 |
:param cidr: (str) used as filter |
|
193 |
:param subnet_id: (str) |
|
195 | 194 |
|
196 | 195 |
:param name: (str) The subnet name |
197 | 196 |
:param allocation_pools: (list of dicts) start/end addresses of |
198 | 197 |
allocation pools: [{'start': ..., 'end': ...}, ...] |
199 | 198 |
:param gateway_ip: (str) |
200 |
:param subnet_id: (str) |
|
201 | 199 |
:param ipv6: (bool) ip_version == 6 if true, 4 if false, used as filter |
202 | 200 |
:param enable_dhcp: (bool) |
203 | 201 |
""" |
204 |
subnet = dict(network_id=network_id, cidr=cidr)
|
|
202 |
subnet = dict() |
|
205 | 203 |
if name not in (None, ): |
206 | 204 |
subnet['name'] = name |
207 | 205 |
if allocation_pools not in (None, ): |
208 | 206 |
subnet['allocation_pools'] = allocation_pools |
209 | 207 |
if gateway_ip not in (None, ): |
210 | 208 |
subnet['gateway_ip'] = gateway_ip |
211 |
if subnet_id not in (None, ): |
|
212 |
subnet['id'] = subnet_id |
|
213 | 209 |
if ipv6 not in (None, ): |
214 | 210 |
subnet['ip_version'] = 6 if ipv6 else 4 |
215 | 211 |
if enable_dhcp not in (None, ): |
216 | 212 |
subnet['enable_dhcp'] = enable_dhcp |
217 |
r = self.subnets_put(json_data=dict(subnet=subnet), success=201) |
|
213 |
r = self.subnets_put( |
|
214 |
subnet_id, json=dict(subnet=subnet), success=200) |
|
218 | 215 |
return r.json['subnet'] |
219 | 216 |
|
220 | 217 |
def delete_subnet(self, subnet_id): |
b/kamaki/clients/network/test.py | ||
---|---|---|
399 | 399 |
def test_update_subnet(self, subnets_put): |
400 | 400 |
for ( |
401 | 401 |
name, allocation_pools, gateway_ip, |
402 |
subnet_id, ipv6, enable_dhcp) in product(
|
|
402 |
ipv6, enable_dhcp) in product( |
|
403 | 403 |
('name', None), ('all pools', None), ('gip', None), |
404 |
('sid', None), (True, False, None), (True, False, None)):
|
|
404 |
(True, False, None), (True, False, None)): |
|
405 | 405 |
kwargs = dict( |
406 | 406 |
name=name, allocation_pools=allocation_pools, |
407 |
gateway_ip=gateway_ip, subnet_id=subnet_id, |
|
408 |
ipv6=ipv6, enable_dhcp=enable_dhcp) |
|
409 |
FakeObject.json, network_id, cidr = dict(subnet='rv'), 'name', 'cd' |
|
407 |
gateway_ip=gateway_ip, ipv6=ipv6, enable_dhcp=enable_dhcp) |
|
408 |
FakeObject.json, subnet_id = dict(subnet='rv'), 'sid' |
|
410 | 409 |
self.assertEqual( |
411 |
self.client.update_subnet(network_id, cidr, **kwargs), 'rv') |
|
412 |
req = dict(network_id=network_id, cidr=cidr) |
|
413 |
if kwargs.get('ipv6', None) not in (None, ): |
|
414 |
req['ip_version'] = 6 if kwargs.pop('ipv6') else 4 |
|
410 |
self.client.update_subnet(subnet_id, **kwargs), 'rv') |
|
411 |
req = dict() |
|
415 | 412 |
for k, v in kwargs.items(): |
416 | 413 |
if v not in (None, ): |
417 |
req['id' if k == 'subnet_id' else k] = v |
|
418 |
expargs = dict(json_data=dict(subnet=req), success=201) |
|
419 |
self.assertEqual(subnets_put.mock_calls[-1], call(**expargs)) |
|
414 |
if k in ('ipv6', ): |
|
415 |
req['ip_version'] = 6 if v else 4 |
|
416 |
else: |
|
417 |
req[k] = v |
|
418 |
expargs = dict(json=dict(subnet=req), success=200) |
|
419 |
self.assertEqual( |
|
420 |
subnets_put.mock_calls[-1], call(subnet_id, **expargs)) |
|
420 | 421 |
|
421 | 422 |
@patch( |
422 | 423 |
'kamaki.clients.network.NetworkClient.subnets_delete', |
b/kamaki/clients/test.py | ||
---|---|---|
411 | 411 |
continue |
412 | 412 |
self.client.request(method, path, **kwargs) |
413 | 413 |
self.assertEqual( |
414 |
RespInit.mock_calls[-1], call(FR, connection_retry_limit=0)) |
|
414 |
RespInit.mock_calls[-1], |
|
415 |
call(FR, connection_retry_limit=0, poolsize=None)) |
|
415 | 416 |
|
416 | 417 |
@patch('kamaki.clients.Client.request', return_value='lala') |
417 | 418 |
def _test_foo(self, foo, request): |
Also available in: Unified diff