Skip to content

Commit 85d107e

Browse files
authored
Merge pull request #60 from ns1/feature/ddi-tagging-PLAT-803
PLAT-803/ Feature/ddi tagging
2 parents fa795b8 + 5434016 commit 85d107e

3 files changed

Lines changed: 105 additions & 20 deletions

File tree

ns1/__init__.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,14 @@ def loadScopeGroup(self, id, callback=None, errback=None):
449449
return scope_group.load(callback=callback, errback=errback)
450450

451451
def createScopeGroup(
452-
self, name, service_def_id, dhcp4, dhcp6, callback=None, errback=None
452+
self,
453+
name,
454+
service_def_id,
455+
dhcp4,
456+
dhcp6,
457+
callback=None,
458+
errback=None,
459+
**kwargs
453460
):
454461
"""
455462
Create a new Scope Group
@@ -467,7 +474,11 @@ def createScopeGroup(
467474
)
468475

469476
return scope_group.create(
470-
dhcp4=dhcp4, dhcp6=dhcp6, callback=callback, errback=errback
477+
dhcp4=dhcp4,
478+
dhcp6=dhcp6,
479+
callback=callback,
480+
errback=errback,
481+
**kwargs
471482
)
472483

473484
def createReservation(
@@ -478,14 +489,24 @@ def createReservation(
478489
dhcp_options=None,
479490
callback=None,
480491
errback=None,
492+
**kwargs
481493
):
494+
"""
495+
Create a new Reservation
496+
For the list of keywords available, see :attr:`ns1.rest.ipam.Reservation.INT_FIELDS` and :attr:`ns1.rest.ipam.Reservation.PASSTHRU_FIELDS`
497+
498+
:param int scopegroup_id: id of the scope group
499+
:param int address_id: id of the address the reservation is associated with
500+
:param str mac: mac address of the reservation
501+
:param list options: dhcp options of the reservation
502+
"""
482503
import ns1.ipam
483504

484505
reservation = ns1.ipam.Reservation(
485506
self.config, scopegroup_id, address_id, dhcp_options, mac
486507
)
487508

488-
return reservation.create(callback=callback, errback=errback)
509+
return reservation.create(callback=callback, errback=errback, **kwargs)
489510

490511
def loadReservation(
491512
self, scopegroup_id, address_id, callback=None, errback=None
@@ -505,14 +526,23 @@ def createScope(
505526
dhcp_options=None,
506527
callback=None,
507528
errback=None,
529+
**kwargs
508530
):
531+
"""
532+
Create a new Scope
533+
For the list of keywords available, see :attr:`ns1.rest.ipam.Scope.INT_FIELDS` and :attr:`ns1.rest.ipam.Scope.PASSTHRU_FIELDS`
534+
535+
:param int scopegroup_id: id of the scope group
536+
:param int address_id: id of the address the scope is associated with
537+
:param DHCPOptions options: DHCPOptions object that contains the settings for the scope
538+
"""
509539
import ns1.ipam
510540

511541
scope = ns1.ipam.Scope(
512542
self.config, scopegroup_id, address_id, dhcp_options
513543
)
514544

515-
return scope.create(callback=callback, errback=errback)
545+
return scope.create(callback=callback, errback=errback, **kwargs)
516546

517547
def loadScope(
518548
self, scopegroup_id, address_id, callback=None, errback=None

ns1/ipam.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,21 @@ class OptiondefException(Exception):
4646

4747

4848
class Network(object):
49-
def __init__(self, config, name=None, id=None):
49+
def __init__(self, config, name=None, id=None, tags=None):
5050
"""
5151
Create a new high level Network object
5252
5353
:param ns1.config.Config config: config object
5454
:param str name: network name
5555
:param int id: id of an existing Network
56+
:param dict tags: tags of the network
5657
"""
5758
self._rest = Networks(config)
5859
self.config = config
5960
self.name = name
6061
self.id = id
6162
self.report = {}
63+
self.tags = tags
6264
self.data = None
6365

6466
def __repr__(self):
@@ -88,6 +90,9 @@ def success(result, *args):
8890
self.name = result["name"]
8991
self.report = self._rest.report(self.id)
9092

93+
if "tags" in result:
94+
self.tags = result["tags"]
95+
9196
if callback:
9297
return callback(self)
9398
else:
@@ -186,6 +191,7 @@ def __init__(
186191
network=None,
187192
scope_group=None,
188193
id=None,
194+
tags=None,
189195
):
190196
"""
191197
Create a new high level Address object
@@ -195,6 +201,7 @@ def __init__(
195201
:param str status: planned, assigned
196202
:param Network network: Network Object the address will be part of
197203
:param Scopegroup scope_group: Scopegroup Object that will be associated with the address
204+
:param dict tags: tags of the address
198205
"""
199206
self._rest = Addresses(config)
200207
self.config = config
@@ -206,6 +213,7 @@ def __init__(
206213
self.children = []
207214
self.report = {}
208215
self.data = None
216+
self.tags = tags
209217

210218
def __repr__(self):
211219
return "<Address address=%s>" % self.prefix
@@ -237,6 +245,10 @@ def success(result, *args):
237245
# self.scope_group = Scopegroup(config=self.config, id=result['scope_group_id']) NYI
238246
self.report = self._rest.report(self.id)
239247
children = self._rest.retrieve_children(self.id)
248+
249+
if "tags" in result:
250+
self.tags = result["tags"]
251+
240252
self.children = [
241253
Address(self.config, id=child["id"])
242254
for child in children
@@ -390,14 +402,17 @@ def success(result, *args):
390402

391403

392404
class Scopegroup(object):
393-
def __init__(self, config, name=None, service_def_id=None, id=None):
405+
def __init__(
406+
self, config, name=None, service_def_id=None, id=None, tags=None
407+
):
394408
"""
395409
Create a new high level Scopegroup object
396410
397411
:param ns1.config.Config config: config object
398412
:param str name: Name of the scope group
399413
:param int service_group_id: id of the service group the scope group is associated with
400414
:param int id: id of the scope group
415+
:param dict tags: tags of the scopegroup
401416
"""
402417
self._rest = Scopegroups(config)
403418
self.config = config
@@ -407,6 +422,7 @@ def __init__(self, config, name=None, service_def_id=None, id=None):
407422
self.name = name
408423
self.dhcp_service_id = service_def_id
409424
self.data = None
425+
self.tags = tags
410426

411427
def __repr__(self):
412428
return "<Scopegroup scope_group=%s>" % self.name
@@ -436,6 +452,9 @@ def success(result, *args):
436452
self.dhcp6 = result["dhcpv6"]
437453
self.dhcp_service_id = result.get("dhcp_service_id")
438454

455+
if "tags" in result:
456+
self.tags = result["tags"]
457+
439458
if callback:
440459
return callback(self)
441460
else:
@@ -480,7 +499,7 @@ def success(result, *args):
480499
self.id, callback=success, errback=errback, **kwargs
481500
)
482501

483-
def create(self, dhcp4, dhcp6, callback=None, errback=None):
502+
def create(self, dhcp4, dhcp6, callback=None, errback=None, **kwargs):
484503
"""
485504
:param DHCPOptions dhcp4: DHCPOptions object that contains the settings for dhcp4
486505
:param DHCPOptions dhcp6: DHCPOptions object that contains the settings for dhcp6
@@ -518,6 +537,7 @@ def success(result, *args):
518537
dhcp_service_id=self.dhcp_service_id,
519538
callback=success,
520539
errback=errback,
540+
**kwargs
521541
)
522542

523543
def reserve(
@@ -582,6 +602,7 @@ def __init__(
582602
reservation_id=None,
583603
options=None,
584604
mac=None,
605+
tags=None,
585606
):
586607
"""
587608
Create a new high level Reservation object
@@ -592,6 +613,7 @@ def __init__(
592613
:param int reservation_id: id of the reservation
593614
:param list options: dhcp options of the reservation
594615
:param str mac: mac address of the reservation
616+
:param dict tags: tags of the reservation
595617
"""
596618
self._rest = Reservations(config)
597619
self.config = config
@@ -600,6 +622,7 @@ def __init__(
600622
self.address_id = address_id
601623
self.mac = mac
602624
self.data = None
625+
self.tags = tags
603626

604627
if options is None:
605628
options = DHCPOptions("dhcpv4", {})
@@ -642,6 +665,9 @@ def success(result, *args):
642665
self.mac = result["mac"]
643666
self.options = result["options"]
644667

668+
if "tags" in result:
669+
self.tags = result["tags"]
670+
645671
if callback:
646672
return callback(self)
647673
else:
@@ -818,7 +844,13 @@ def success(result, *args):
818844

819845
class Scope(object):
820846
def __init__(
821-
self, config, scopegroup_id, address_id, scope_id=None, options=None
847+
self,
848+
config,
849+
scopegroup_id,
850+
address_id,
851+
scope_id=None,
852+
options=None,
853+
tags=None,
822854
):
823855
"""
824856
Create a new high level Scope object
@@ -828,12 +860,14 @@ def __init__(
828860
:param int address_id: id of the address the scope is associated with
829861
:param int scope_id: id of the scope
830862
:param DHCPOptions options: DHCPOptions object that contains the settings for the scope
863+
:param dict tags: tags of the scope
831864
"""
832865
self._rest = Scopes(config)
833866
self.config = config
834867
self.scopegroup_id = scopegroup_id
835868
self.address_id = address_id
836869
self.id = scope_id
870+
self.tags = tags
837871

838872
if options is None:
839873
options = DHCPOptions("dhcpv4", {})
@@ -876,6 +910,9 @@ def success(result, *args):
876910
self.address_id = result["address_id"]
877911
self.options = result["options"]
878912

913+
if "tags" in result:
914+
self.tags = result["tags"]
915+
879916
if callback:
880917
return callback(self)
881918
else:
@@ -919,6 +956,7 @@ def success(result, *args):
919956
self.options,
920957
callback=success,
921958
errback=errback,
959+
**kwargs
922960
)
923961

924962
def update(

ns1/rest/ipam.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Addresses(resource.BaseResource):
1616
" merged_address_id",
1717
"scope_group_id",
1818
]
19-
PASSTHRU_FIELDS = ["prefix", "status", "desc", "kvps", "tags", "reserve"]
19+
PASSTHRU_FIELDS = ["prefix", "status", "desc", "tags", "reserve"]
2020
BOOL_FIELDS = ["parent"]
2121

2222
def _buildBody(self, **kwargs):
@@ -149,7 +149,7 @@ def search(self, network_id, prefix, callback=None, errback=None):
149149
class Networks(resource.BaseResource):
150150
ROOT = "ipam/network"
151151
INT_FIELDS = ["network_id"]
152-
PASSTHRU_FIELDS = ["rt", "name", "desc", "kvps", "tags"]
152+
PASSTHRU_FIELDS = ["rt", "name", "desc", "tags"]
153153
BOOL_FIELDS = []
154154

155155
def _buildBody(self, **kwargs):
@@ -218,7 +218,7 @@ def report(self, network_id, callback=None, errback=None):
218218
class Scopegroups(resource.BaseResource):
219219
ROOT = "dhcp/scopegroup"
220220
INT_FIELDS = ["id", "dhcp_service_id", "valid_lifetime_secs"]
221-
PASSTHRU_FIELDS = ["dhcpv4", "dhcpv6", "name"]
221+
PASSTHRU_FIELDS = ["dhcpv4", "dhcpv6", "name", "tags"]
222222
BOOL_FIELDS = ["enabled", "echo_client_id"]
223223

224224
def _buildBody(self, **kwargs):
@@ -272,6 +272,13 @@ def retrieve(self, scope_group_id, callback=None, errback=None):
272272

273273
class Scopes(resource.BaseResource):
274274
ROOT = "dhcp/scope"
275+
INT_FIELDS = ["scope_group_id", "address_id", "valid_lifetime_secs"]
276+
PASSTHRU_FIELDS = ["options", "tags"]
277+
278+
def _buildBody(self, **kwargs):
279+
body = {}
280+
self._buildStdBody(body, kwargs)
281+
return body
275282

276283
@classmethod
277284
def select_from_list(cls, result, scope_id):
@@ -281,13 +288,18 @@ def select_from_list(cls, result, scope_id):
281288
return None
282289

283290
def create(
284-
self, scopegroup_id, address_id, options, callback=None, errback=None
291+
self,
292+
scopegroup_id,
293+
address_id,
294+
options,
295+
callback=None,
296+
errback=None,
297+
**kwargs
285298
):
286-
body = {
287-
"address_id": address_id,
288-
"scope_group_id": scopegroup_id,
289-
"options": options,
290-
}
299+
kwargs["address_id"] = address_id
300+
kwargs["scope_group_id"] = scopegroup_id
301+
kwargs["options"] = options
302+
body = self._buildBody(**kwargs)
291303

292304
return self._make_request(
293305
"PUT",
@@ -305,10 +317,15 @@ def update(
305317
scopegroup_id=None,
306318
callback=None,
307319
errback=None,
320+
**kwargs
308321
):
309-
body = {"address_id": address_id, "options": options}
322+
kwargs["address_id"] = address_id
323+
kwargs["options"] = options
324+
310325
if scopegroup_id is not None:
311-
body["scope_group_id"] = (scopegroup_id,)
326+
kwargs["scope_group_id"] = scopegroup_id
327+
328+
body = self._buildBody(**kwargs)
312329

313330
return self._make_request(
314331
"POST",
@@ -426,7 +443,7 @@ def retrieve(self, space, key, callback=None, errback=None):
426443
class Reservations(resource.BaseResource):
427444
ROOT = "dhcp/reservation"
428445
INT_FIELDS = ["scope_group_id", "address_id"]
429-
PASSTHRU_FIELDS = ["mac", "options"]
446+
PASSTHRU_FIELDS = ["mac", "options", "tags"]
430447
BOOL_FIELDS = ["dhcpv6"]
431448

432449
def _buildBody(self, **kwargs):

0 commit comments

Comments
 (0)