from PLC.Faults import *
from PLC.Parameter import Parameter
from PLC.Filter import Filter
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
from PLC.Table import Row, Table
class AddressType(AlchemyObj):
def delete(self, commit=True):
+ assert 'address_type_id' in self
AlchemyObj.delete(self, dict(self))
class AddressTypes(list):
from PLC.Faults import *
from PLC.Parameter import Parameter
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
from PLC.AddressTypes import AddressType, AddressTypes
class Address(AlchemyObj):
AlchemyObj.update(self, {'address_id': self['address_id']}, dict(self))
def delete(self, commit=True):
+ assert 'address_id' in self
AlchemyObj.delete(self, dict(self))
class Addresses(list):
def delete(self,commit=True):
### need to cleanup ilinks
+ assert 'interface_id' in self
AlchemyObj.delete(self, dict(self)
with sync().
"""
- table_name = 'keys'
- primary_key = 'key_id'
+ tablename = 'keys'
join_tables = ['person_key', 'peer_key']
fields = {
- 'key_id': Parameter(str, "Key identifier"),
- 'key_type': Parameter(str, "Key type"),
- 'key': Parameter(str, "Key value", max = 4096),
- 'person_id': Parameter(int, "User to which this key belongs", nullok = True),
- 'peer_id': Parameter(int, "Peer to which this key belongs", nullok = True),
- 'peer_key_id': Parameter(int, "Foreign key identifier at peer", nullok = True),
+ 'id': Parameter(str, "Key identifier", primary_key=True),
+ #'key_type': Parameter(str, "Key type"),
+ 'public_key': Parameter(str, "Key string", max = 4096),
+ 'name': Parameter(str, "Key name",)
}
def sync(self, insert = False, validate = True):
NovaObject.sync(self, insert, validate)
- if insert == True or self.key_id not in self:
- self.object = self.api.client_shell.nova.keypairs.create(self.key_id,
+ if insert == True or 'id' not in self:
+ self.object = self.api.client_shell.nova.keypairs.create(self.id,
self.key)
+ else:
+ self.object = self.api.client_shell.nova.keypairs.update(self.id, dict(self))
def delete(self):
- self.api.client_shell.nova.keypairs.delete(self.key_id)
+ assert 'id' in self
+ self.api.client_shell.nova.keypairs.delete(self.id)
- def validate_key_type(self, key_type):
- key_types = [row['key_type'] for row in KeyTypes(self.api)]
- if key_type not in key_types:
- raise PLCInvalidArgument, "Invalid key type"
- return key_type
-
- def validate_key(self, key):
+ def validate_public_key(self, key):
# Key must not be blacklisted
- rows = self.api.db.selectall("SELECT 1 from keys" \
- " WHERE key = %(key)s" \
- " AND is_blacklisted IS True",
- locals())
- if rows:
- raise PLCInvalidArgument, "Key is blacklisted and cannot be used"
-
+ pass
return key
+ def validate_name(self, name)
+ keys = Keys(self.api, name)
+ if keys:
+ raise PLCInvalidArgument, "Key name alredy in use"
+
def validate(self):
# Basic validation
- Row.validate(self)
+ NovaObject.validate(self)
- assert 'key' in self
- key = self['key']
+ assert 'public_key' in self
+ key = self['public_key']
if self['key_type'] == 'ssh':
# Accept only SSH version 2 keys without options. From
AlchemyObj.update(self, {'message_id': self['message_id']}, dict(self))
def delete(self, commit = True):
+ assert 'message_id' in self
AlchemyObj.delete(self, dict(self))
class Messages(list):
AlchemyObj.insert(self, dict(self))
def delete(self, commit=True):
- assert method in self
+ assert 'method' in self
AlchemyObj.delete(self, dict(self))
return name
+ def sync(self, commit=True, validate=True):
+ AlchemyObj.sync(self, commit=commit, validate=validate)
+ AlchemyObj.insert(self, dict(self))
+
+ def delete(self, commit=True):
+ assert 'type' in self
+ AlchemyObj.delete(self, dict(self))
+
class NetworkTypes(list):
"""
Representation of the network_types table in the database.
else:
AlchemyObj.update(self, {'nodegroup_id': self['nodegroup_id']}, dict(self))
+ def delete(self, commit=True):
+ assert 'nodegroup_id' in self
+ AlchemyObj.delete(self, dict(self))
+
class NodeGroups(list):
"""
Representation of row(s) from the nodegroups table in the
#
from PLC.Faults import *
from PLC.Parameter import Parameter
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
from PLC.Nodes import Node, Nodes
from PLC.TagTypes import TagType, TagTypes
AlchemyObj.update(self, {'node_tag_id': self['node_tag_id']}, dict(self))
def delete(self, commit=True):
+ assert 'node_tag_id' in self
AlchemyObj.delete(self, dict(self))
class NodeTags(list):
from PLC.Faults import *
from PLC.Parameter import Parameter
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
class NodeType(AlchemyObj):
"""
AlchemyObj.insert(self, dict(self)
def delete(self, commit=True):
+ assert 'node_type' in self
AlcemyObj.delete(self, dict(self))
class NodeTypes(list):
- def sync(self, insert=False, validate=True):
- AlchemyObj.sync(self, insert, validate)
- if insert == True or 'node_id' not in self:
+ def sync(self, commit=True, validate=True):
+ AlchemyObj.sync(self, commit=commit, validate=validate)
+ if 'node_id' not in self:
AlchemyObj.insert(self, dict(self))
else:
- AlchemyObj.update(self, dict(self))
+ AlchemyObj.update(self, {'node_id': self['node_id']}, dict(self))
def delete(self, commit = True):
"""
from PLC.Faults import *
from PLC.Parameter import Parameter
-from PLC.Table import Row, Table
-from PLC.Filter import Filter
+from PLC.Storage.AlchemyObject import AlchemyObj
-class PCUProtocolType(Row):
+class PCUProtocolType(AlchemyObj):
"""
Representation of a row in the pcu_protocol_type table. To use,
instantiate with a dict of values.
"""
- table_name = 'pcu_protocol_type'
- primary_key = 'pcu_protocol_type_id'
+ tablename = 'pcu_protocol_type'
join_tables = []
fields = {
- 'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier"),
+ 'pcu_protocol_type_id': Parameter(int, "PCU protocol type identifier", primary_key=True),
'pcu_type_id': Parameter(int, "PCU type identifier"),
'port': Parameter(int, "PCU port"),
'protocol': Parameter(str, "Protocol"),
return protocol
-class PCUProtocolTypes(Table):
+ def sync(self, commit=True, validate=True):
+ AlchemyObj.sync(self, commit=commit, validate=validate)
+ if 'pcu_protocol_type_id' not in self:
+ AlchemyObj.insert(self, dict(self))
+ else:
+ filter = {'pcu_protocol_type_id', self['pcu_protocol_type_id']}
+ AlchemyObj.update(self, filter, dict(self))
+
+ def delete(self, commit=True):
+ assert 'pcu_protocol_type_id' in self
+ AlchemyObj.delete(self, dict(self))
+
+class PCUProtocolTypes(list):
"""
Representation of the pcu_protocol_types table in the database.
"""
def __init__(self, api, protocol_type_filter = None, columns = None):
- Table.__init__(self, api, PCUProtocolType, columns)
-
- sql = "SELECT %s FROM pcu_protocol_type WHERE True" % \
- ", ".join(self.columns)
-
- if protocol_type_filter is not None:
- if isinstance(protocol_type_filter, (list, tuple, set, int, long)):
- protocol_type_filter = Filter(PCUProtocolType.fields, {'pcu_protocol_type_id': protocol_type_filter})
- sql += " AND (%s) %s" % protocol_type_filter.sql(api, "OR")
- elif isinstance(protocol_type_filter, dict):
- protocol_type_filter = Filter(PCUProtocolType.fields, protocol_type_filter)
- sql += " AND (%s) %s" % protocol_type_filter.sql(api, "AND")
- else:
- raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter
-
+ if not protocol_type_filter:
+ protocol_types = PCUProtocolType().select()
+ elif isinstance(protocol_type_filter, (list, tuple, set, int, long)):
+ protocol_types = PCUProtocolType.select(filter={'pcu_protocol_type_id': protocol_type_filter})
+ elif isinstance(protocol_type_filter, dict):
+ protocol_types = PCUProtocolType.select(filter= protocol_type_filter)
+ else:
+ raise PLCInvalidArgument, "Wrong pcu_protocol_type filter %r"%protocol_type_filter
- self.selectall(sql)
+ self.extend(protocol_types)
#
from PLC.Faults import *
from PLC.Parameter import Parameter
-from PLC.Filter import Filter
-from PLC.Table import Row, Table
+from PLC.Storage.AlchemyObject import AlchemyObj
from PLC.TagTypes import TagType, TagTypes
from PLC.Persons import Person
-class PersonTag(Row):
+class PersonTag(AlchemyObj):
"""
Representation of a row in the person_tag.
To use, instantiate with a dict of values.
"""
- table_name = 'person_tag'
- primary_key = 'person_tag_id'
+ tablename = 'person_tag'
fields = {
- 'person_tag_id': Parameter(int, "Person setting identifier"),
+ 'person_tag_id': Parameter(int, "Person setting identifier", primary_key=True),
'person_id': Person.fields['id'],
'email': Person.fields['email'],
'tag_type_id': TagType.fields['tag_type_id'],
}
-class PersonTags(Table):
+ def sync(self, commit=True, validate=True):
+ AlchemyObj.sync(self, commit=Ture, validate=True)
+ if 'person_tag_id' not in self:
+ AlchemyObj.insert(self, dict(self))
+ else:
+ AlchemyObj.update(self, {'person_tag_id': self['person_tag_id']}, dict(self))
+
+
+ def delete(self, commit=True):
+ assert 'person_tag_id' in self
+ AlchemyObj.delete(self, dict(self))
+
+class PersonTags(list):
"""
Representation of row(s) from the person_tag table in the
database.
"""
def __init__(self, api, person_tag_filter = None, columns = None):
- Table.__init__(self, api, PersonTag, columns)
-
- sql = "SELECT %s FROM view_person_tags WHERE True" % \
- ", ".join(self.columns)
-
- if person_tag_filter is not None:
- if isinstance(person_tag_filter, (list, tuple, set, int, long)):
- person_tag_filter = Filter(PersonTag.fields, {'person_tag_id': person_tag_filter})
- elif isinstance(person_tag_filter, dict):
- person_tag_filter = Filter(PersonTag.fields, person_tag_filter)
- else:
- raise PLCInvalidArgument, "Wrong person setting filter %r"%person_tag_filter
- sql += " AND (%s) %s" % person_tag_filter.sql(api)
-
-
- self.selectall(sql)
+ if not person_tag_filter:
+ person_tags = PersonTag().select()
+ elif isinstance(person_tag_filter, (list, tuple, set, int, long)):
+ person_tags = PersonTag().select(filter={'person_tag_id': person_tag_filter})
+ elif isinstance(person_tag_filter, dict):
+ person_tags = PersonTag().select(filter=person_tag_filter)
+ else:
+ raise PLCInvalidArgument, "Wrong person setting filter %r"%person_tag_filter
+
+ self.extend(person_tags)
from PLC.Roles import Role, Roles
from PLC.Keys import Key, Keys
from PLC.Messages import Message, Messages
-from PLC.Storage.AlchemyObj import AlchemyObj
+from PLC.Storage.AlchemyObject import AlchemyObj
class Person(AlchemyObj):
"""
dict. Commit to the database with sync().
"""
+ tablename = 'persons'
+
fields = {
- 'person_id': Parameter(int, "User identifier"),
+ 'person_id': Parameter(int, "User identifier", primary_key=True),
'keystone_id': Parameter(int, "Keystone User identifier"),
'first_name': Parameter(str, "Given name", max = 128),
'last_name': Parameter(str, "Surname", max = 128),
def delete(self):
+ assert 'person_id' in self
# delete relationships
SlicePerson().delete.filter({'person_id': self['person_id']})