Changeset 463
- Timestamp:
- 05/16/08 11:14:07
(8 months ago)
- Author:
- jmowery
- Message:
incremental check-in for new storage
added some node functionality
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r461 |
r463 |
|
| 228 | 228 | def add_node(self, id): |
|---|
| 229 | 229 | '''Add a node with the given id to the store if not already present. Create entries for each known file with an applied time of 0 for that node.''' |
|---|
| | 230 | |
|---|
| 230 | 231 | raise NotImplementedError |
|---|
| 231 | 232 | |
|---|
| … | … | |
| 677 | 678 | def add_node(self, id): |
|---|
| 678 | 679 | '''Add a new node to this Layer; all controlled files have the default time of 0 until sent to the node.''' |
|---|
| 679 | | raise NotImplementedError |
|---|
| | 680 | if not id: |
|---|
| | 681 | raise ValueError, 'Must specify a valid node id.' |
|---|
| | 682 | if id in self.list_nodes(): |
|---|
| | 683 | return # already there |
|---|
| | 684 | if not self.storage: |
|---|
| | 685 | raise RuntimeError, 'Cannot add node \'' + id + '\' to uncontrolled layer \'' + self.name + '\'.' |
|---|
| | 686 | #XXX FIXME |
|---|
| | 687 | self.storage.add_node(id) |
|---|
| 680 | 688 | |
|---|
| 681 | 689 | #TODO should there be a remove node? |
|---|
| … | … | |
| 730 | 738 | class NodeLayerData: |
|---|
| 731 | 739 | '''Represents the data stored on disk about the status of files sent to this node relative to a single Layer.''' |
|---|
| 732 | | layer_name = '' # Name of the layer represented |
|---|
| | 740 | layer_path = '' # Path of the layer represented |
|---|
| 733 | 741 | group_name = '' # Group name for the layer |
|---|
| 734 | 742 | config_path = '' # path to the file containing the on disk record of the state of the Node's files for this layer |
|---|
| 735 | 743 | config = ConfigParser.ConfigParser() # parser object for the file config_path |
|---|
| 736 | 744 | |
|---|
| | 745 | def __init__(self, id, layer_path): |
|---|
| | 746 | assert is_controlled(layer_path) |
|---|
| | 747 | self.layer_path = layer_path |
|---|
| | 748 | l = Layer(layer_path) |
|---|
| | 749 | self.group_name = l.name |
|---|
| | 750 | self.config_path = os.path.join(l.storage.nodes_dir, id) |
|---|
| | 751 | self.config.add_section('entries') |
|---|
| | 752 | if l.storage.path == l.root: |
|---|
| | 753 | self.config.add_section('general') |
|---|
| | 754 | self.config.add_section('bools') |
|---|
| | 755 | self.config.read(self.config_path) |
|---|
| | 756 | |
|---|
| | 757 | def write(self): |
|---|
| | 758 | node_data_file = open(self.config_path, 'w') |
|---|
| | 759 | self.config.write(node_data_file) |
|---|
| | 760 | node_date_file.close() |
|---|
| | 761 | |
|---|
| 737 | 762 | class Node: |
|---|
| 738 | 763 | '''The node object holds all storage relevant data about a single node connected to the store.''' |
|---|
| 739 | | modified = False |
|---|
| 740 | | id = '' |
|---|
| 741 | | classification = '' |
|---|
| 742 | | description = '' |
|---|
| 743 | | bools = {} |
|---|
| 744 | | entries = {} |
|---|
| 745 | | enforcing = 'Unknown' |
|---|
| 746 | | layers = {} |
|---|
| 747 | | |
|---|
| 748 | | def __init__(self, id, layer=''): |
|---|
| 749 | | raise NotImplementedError |
|---|
| | 764 | modified = False # Set whenever the status data has been modified since last sync to disk |
|---|
| | 765 | id = '' # Id of the node (currently its IP address) |
|---|
| | 766 | classification = '' # Group name of the most specific layer containing the node |
|---|
| | 767 | description = '' # User defined string providing description of the node (possibly a name) |
|---|
| | 768 | bools = {} # Status of each boolean on the node system keyed by bool name value is bool not string |
|---|
| | 769 | entries = {} # Entry per module to be sent to the node applied time is last sent version |
|---|
| | 770 | enforcing = 'Unknown' # Enforcing status of the node |
|---|
| | 771 | layers = {} # NodeLayerData per layer path for each layer in classification |
|---|
| | 772 | root = '' # Root of store contianing data for this node |
|---|
| | 773 | |
|---|
| | 774 | def __init__(self, id, root): |
|---|
| | 775 | if not id: |
|---|
| | 776 | raise ValueError, 'Node must have a valid id.' |
|---|
| | 777 | self.root = find_control_root(root) #make sure root really is the root |
|---|
| | 778 | self.classify() |
|---|
| | 779 | self.update() |
|---|
| 750 | 780 | |
|---|
| 751 | 781 | def __del__(self): |
|---|
| … | … | |
| 763 | 793 | def write(self): |
|---|
| 764 | 794 | '''Write the data back to disk.''' |
|---|
| 765 | | raise NotImplementedError |
|---|
| | 795 | for layer_data in self.layers.values(): |
|---|
| | 796 | layer_data.write() |
|---|
| | 797 | self.modified = False |
|---|
| 766 | 798 | |
|---|
| 767 | 799 | def set_file_status(self, name, layer, version, local=True) |
|---|
| … | … | |
| 770 | 802 | def update(self): |
|---|
| 771 | 803 | '''Update all fields and write the node to disk if modified. This function should be called regularly and whenever the Node will go out of scope.''' |
|---|
| 772 | | raise NotImplementedError |
|---|
| | 804 | if not self.modified: |
|---|
| | 805 | return |
|---|
| | 806 | self.layers[self.root].config.set('general', 'description', self.description) |
|---|
| | 807 | self.layers[self.root].config.set('general', 'classification', self.classification) |
|---|
| | 808 | self.layers[self.root].config.set('general', 'enforcing', self.enforcing) |
|---|
| | 809 | self.layers[self.root].config.set('general', 'root', self.root) |
|---|
| | 810 | for b in self.bools.keys(): |
|---|
| | 811 | self.layers[self.root].config.set('bools', b, str(bools[b])) |
|---|
| | 812 | for e in self.entries.keys(): |
|---|
| | 813 | self.layers[os.path.join(os.path.dirname(self.root), self.entries[e].group)].config.set('entries', e, pickle.dumps(self.entries[e])) |
|---|
| | 814 | self.write() |
|---|
| 773 | 815 | |
|---|
| 774 | 816 | def classify(self, classification=''): |
|---|
| 775 | 817 | '''Place this node in the group specified by classification; if empty, attempt to determine from the store how the node is classified.''' |
|---|
| | 818 | if not classification: |
|---|
| | 819 | l = Layer(self.root) |
|---|
| | 820 | if self.id not in l.list_nodes(): #only possible on initial addition of a node |
|---|
| | 821 | self.layers[self.root] = NodeLayerData(self.id, self.root) |
|---|
| | 822 | self.layers[self.root].write() #create empty config to be filled in by layer.add_node() |
|---|
| | 823 | return |
|---|
| 776 | 824 | raise NotImplementedError |
|---|
| 777 | 825 | |
|---|
Download in other formats:
* Generating other formats may take time.