From 2b4c3b6edccf2494c3ab0b4d8f2b8c17ef7744dd Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Tue, 25 Oct 2011 09:56:51 -0400 Subject: [PATCH] removing specdict --- sfa/util/specdict.py | 131 ------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 sfa/util/specdict.py diff --git a/sfa/util/specdict.py b/sfa/util/specdict.py deleted file mode 100644 index 2138e876..00000000 --- a/sfa/util/specdict.py +++ /dev/null @@ -1,131 +0,0 @@ -## -# SpecDict -# -# SpecDict defines a means for converting a dictionary with plc specific keys -# to a dict with rspec specific keys. -# -# SpecDict.fields dict defines all the rspec specific attribute and their -# expected type. -# -# SpecDict.plc_fields defines a one to one mapping of plc attribute to rspec -# attribute - -from types import StringTypes, ListType - -class SpecDict(dict): - """ - Base class of SpecDict objects. - """ - fields = {} - plc_fields = {} - type = None - - def __init__(self, spec_dict): - # convert plc dict and initialize self - sdict = self.plcToSpec(spec_dict) - dict.__init__(self, sdict) - - - def plcToSpec(self, spec_dict): - """ - Defines how to convert a plc dict to rspec dict - """ - spec = {} - for field in self.fields: - value = "" - expected = self.fields[field] - if isinstance(expected, StringTypes): - if self.plc_fields.has_key(field): - plc_field = self.plc_fields[field] - if spec_dict.has_key(plc_field): - value = spec_dict[plc_field] - elif isinstance(expected, ListType): - expected = expected[0] - if self.plc_fields.has_key(field): - plc_field = self.plc_fields[field] - if spec_dict.has_key(plc_field): - value = [expected(value) for value in spec_dict[plc_field]] - spec[field] = value - return {self.type: spec} - -# -# fields = { geni_field: type. Could be class for nested classes, otherwise prob str} -# plc_fields = {geni_field : plc_field} -# - -class IfSpecDict(SpecDict): - type = 'IfSpec' - fields = {'name': '', - 'addr': '', - 'type': '', - 'init_params': '', - 'min_rate': '', - 'max_rate': '', - 'max_kbyte': '', - 'ip_spoof': ''} - plc_fields = {'name': 'is_primary', # XXX needs munging to return name instead of True or False - 'addr': 'ip', - 'type': 'type'} - -class LinkSpecDict(SpecDict): - type = 'LinkSpec' - fields = {'min_alloc': '', - 'max_alloc': '', - 'type': '', - 'start_time': '', - 'bw': '', - 'duration': '', - 'init_params': '', - 'endpoints': [IfSpecDict]} - plc_fields = {'min_alloc': 'min_alloc', - 'max_alloc': 'max_alloc', - 'type': 'type', - 'start_time': 'start_time', - 'bw': 'bw', - 'duration': 'duration', - 'init_params': 'init_params', - 'endpoints': 'endpoints'} - - -class NodeSpecDict(SpecDict): - type = 'NodeSpec' - fields = {'name': '', - 'type': '', - 'init_params': '', - 'cpu_min': '', - 'cpu_share': '', - 'cpu_pct': '', - 'disk_max': '', - 'start_time': '', - 'duration': '', - 'net_if': [IfSpecDict]} - - plc_fields = {'name': 'hostname', - 'net_if': 'interfaces'} - -class NetSpecDict(SpecDict): - type = 'NetSpec' - fields = {'name': '', - 'start_time': '', - 'duration': '', - 'nodes': [NodeSpecDict], - 'links': [LinkSpecDict], - } - plc_fields = {'name': 'name', - 'start_time': 'start_time', - 'duration': 'duration', - 'nodes': 'nodes', - 'links': 'links'} - -class RSpecDict(SpecDict): - type = 'RSpec' - fields = {'start_time': '', - 'duration': '', - 'networks': [NetSpecDict] - } - plc_fields = {'networks': 'networks', - 'start_time': 'start_tim', - 'duration': 'duration' - } - -# vim:ts=4:expandtab -- 2.43.0