From e773ac30b86861fa0b91c691defc73620925a6d9 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 10 Dec 2012 19:30:13 -0500 Subject: [PATCH] initial checkin --- PLC/SiteAddresses.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 PLC/SiteAddresses.py diff --git a/PLC/SiteAddresses.py b/PLC/SiteAddresses.py new file mode 100644 index 00000000..79c6ccfe --- /dev/null +++ b/PLC/SiteAddresses.py @@ -0,0 +1,60 @@ +from types import StringTypes +import time +import re +import datetime + +from PLC.Faults import * +from PLC.Parameter import Parameter, Mixed +from PLC.Debug import profile +from PLC.Timestamp import Timestamp +from PLC.Storage.AlchemyObject import AlchemyObj + +class SiteAddress(AlchemyObj): + """ + Representation of a row in the site_address table. To use, optionally + instantiate with a dict of values. Update as you would a + dict. Commit to the database with sync().To use, instantiate + with a dict of values. + """ + + tablename = 'site_address' + + fields = { + 'site_id': Parameter(int, "Slice identifier", primary_key=True), + 'address_id': Parameter(int, "Address identifier", indexed=True), + } + tags = {} + + def sync(self, commit = True, validate=True): + """ + Add the record + """ + AlchemyObj.sync(self, commit, validate) + AlchemyObj.insert(self, dict(self)) + + def delete(self, commit = True): + """ + Delete existing slice. + """ + AlchemyObj.delete(self, dict(self)) + + +class SiteAddresses(list): + """ + Representation of row(s) from the site address table in the + database. + """ + + def __init__(self, api, filter = None, columns = None): + + # the view that we're selecting upon: start with view_slices + if not filter: + site_addresses = SiteAddress().select() + elif isinstance(filter, dict): + site_addresses = SiteAddress().select(filter=filter) + else: + raise PLCInvalidArgument, "Wrong site_address filter %r"%filter + + for site_address in site_address: + site_address = SiteAddress(self.api, object=site_address) + self.append(site_address) -- 2.47.0