def __init__(self, config, scopegroup_id, address_id, scope_id=None, options=None): """ Create a new high level Scope object :param ns1.config.Config config: config object :param int scopegroup_id: id of the scope group :param int address_id: id of the address the scope is associated with :param int scope_id: id of the scope :param DHCPOptions options: DHCPOptions object that contains the settings for the scope """ self._rest = Scopes(config) self.config = config self.scopegroup_id = scopegroup_id self.address_id = address_id self.id = scope_id if options is None: options = DHCPOptions("dhcpv4", {}) self.options = options.option_list["options"] self.data = None
def scopes(self, callback=None, errback=None): if not self.data: raise ScopegroupException("Scope Group not loaded") scopes_config = Scopes(self.config) return scopes_config.list(self.id, callback=callback, errback=errback)
class Scope(object): def __init__(self, config, scopegroup_id, address_id, scope_id=None, options=None): """ Create a new high level Scope object :param ns1.config.Config config: config object :param int scopegroup_id: id of the scope group :param int address_id: id of the address the scope is associated with :param int scope_id: id of the scope :param DHCPOptions options: DHCPOptions object that contains the settings for the scope """ self._rest = Scopes(config) self.config = config self.scopegroup_id = scopegroup_id self.address_id = address_id self.id = scope_id if options is None: options = DHCPOptions("dhcpv4", {}) self.options = options.option_list["options"] self.data = None def __repr__(self): return "<Scope scopegroup=%s, address=%s>" % ( self.scopegroup_id, self.address_id, ) def __getitem__(self, item): if item == "scopegroup_id": return self.scopegroup_id if item == "address_id": return self.address_id return self.data.get(item, None) def reload(self, callback=None, errback=None): """ Reload Scope data from the API. """ return self.load(reload=True, callback=callback, errback=errback) def load(self, callback=None, errback=None, reload=False): """ Load Reservation data from the API. """ if not reload and self.data: raise ScopeException("Scope already loaded") def success(result, *args): self.data = result self.address_id = result["address_id"] self.options = result["options"] if callback: return callback(self) else: return self if self.id is None: raise ScopeException("Must specify a scope_id") return self._rest.retrieve(self.id, callback=success, errback=errback) def delete(self, callback=None, errback=None): """ Delete the Scope """ return self._rest.delete(self.id, callback=callback, errback=errback) def create(self, callback=None, errback=None, **kwargs): """ Create a new Scope. Pass a list of keywords and their values to configure. For the list of keywords available for address configuration, see :attr:`ns1.rest.ipam.Scope.INT_FIELDS` and :attr:`ns1.rest.ipam.Reservations.PASSTHRU_FIELDS` """ if self.data: raise ScopeException("Scope already loaded") def success(result, *args): self.data = result self.id = result["id"] self.address_id = result["address_id"] self.options = result["options"] if callback: return callback(self) else: return self return self._rest.create( self.scopegroup_id, self.address_id, self.options, callback=success, errback=errback, ) def update(self, address_id, options, callback=None, errback=None, **kwargs): """ Update Scope configuration. Pass a list of keywords and their values to update. For the list of keywords available for address configuration, see :attr:`ns1.rest.ipam.Scopes.INT_FIELDS` and :attr:`ns1.rest.ipam.Scopes.PASSTHRU_FIELDS` """ if not self.data: raise ScopeException("Scope not loaded") def success(result, *args): self.data = result self.id = result["id"] self.address_id = result["address_id"] self.options = result["options"] if callback: return callback(self) else: return self return self._rest.update(self.id, address_id, options, callback=success, errback=errback, **kwargs)