Changeset 436
- Timestamp:
- 05/06/08 13:47:47 (8 months ago)
- Files:
-
- branches/trunk-pmd-intproto/agent/agent_storage.py (modified) (2 diffs)
- branches/trunk-pmd-intproto/common/file_util.py (added)
- branches/trunk-pmd-intproto/mgmt/manager.py (modified) (3 diffs)
- branches/trunk-pmd-intproto/server/master.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/trunk-pmd-intproto/agent/agent_storage.py
r431 r436 2 2 import ConfigParser 3 3 import subprocess 4 sys.path.append("../common") 5 import file_util 4 6 5 7 class AgentSystemData: … … 98 100 if int(self.ModuleData[module]) != int(version): 99 101 return False 100 proc = subprocess.Popen(['md5sum', os.path.join(self.PolicyDir, module)], stdout=subprocess.PIPE) 101 proc.wait() 102 sum = proc.stdout.read().split()[0] 102 sum = file_util.checksum(os.path.join(self.PolicyDir, module)) 103 103 return sum == md5sum 104 104 branches/trunk-pmd-intproto/mgmt/manager.py
r435 r436 2 2 import sys 3 3 sys.path.append("../network") 4 sys.path.append("../common") 4 5 import server 5 6 import client 6 7 import protocol 8 import file_util 7 9 import struct 8 10 import time … … 84 86 msg.type = 'query' 85 87 msg.body = 'all' 88 return msg 89 90 def add_message(self, group=''): 91 msg = protocol.Message() 92 msg.msg = 'add' 93 msg.type = 'query' 94 msg.body = (group, []) 95 return msg 96 97 def remove_message(self, group=''): 98 msg = protocol.Message() 99 msg.msg = 'remove' 100 msg.type = 'query' 101 msg.body = (group, []) 86 102 return msg 87 103 … … 113 129 if arg1 == '' or arg2 == '': 114 130 print 'usage:' 115 print ' add FILE GROUP' 116 sys.exit(1) 117 if not os.path.exists(arg1): 118 print 'File \'' + arg1 + '\' does not exist' 119 print 'moduole addition not yet implemented' 131 print ' add GROUP FILE...' 132 sys.exit(1) 133 resp = m.query_server(m.list_groups()) 134 if arg1 not in resp.body: 135 print 'Group \'' + arg1 + '\' does not exist' 136 sys.exit(1) 137 files = [] 138 for arg in sys.argv[3:]: 139 if not os.path.exists(arg): 140 print 'File \'' + arg + '\' does not exist' 141 else: 142 files.append((os.path.realpath(os.path.expanduser(arg))), file_util.checksum(arg)) 143 if len(files) != len(sys.argv[3:]): 144 sys.exit(1) 145 msg = m.add_message(arg1) 146 msg.body[1] += files 120 147 elif cmd == 'remove': 121 148 if arg1 == '' or arg2 == '': 122 149 print 'usage:' 123 print ' remove FILE GROUP' 124 sys.exit(1) 125 print 'module removal not yet implemented' 150 print ' remove GROUP FILE...' 151 sys.exit(1) 152 resp = m.query_server(m.list_groups()) 153 if arg1 not in resp.body: 154 print 'Group \'' + arg1 + '\' does not exist' 155 sys.exit(1) 156 files = [os.path.basename(x) for x in sys.argv[3:]] 157 msg = m.remove_message(arg1) 158 msg.body[1] += files 126 159 elif cmd == 'update': 127 160 if arg1 == 'client': branches/trunk-pmd-intproto/server/master.py
r435 r436 1 1 import sys 2 2 sys.path.append("../network") 3 sys.path.append('../common') 3 4 import server 4 5 import client 5 6 import protocol 6 7 import storage 8 import file_util 7 9 import struct 8 10 import time … … 11 13 import os 12 14 import subprocess 15 import shutil 16 import tempfile 13 17 14 18 def send_files(host, file_list, dest_path): … … 91 95 else: 92 96 val.body = [] 97 res = val 98 elif val.msg == 'add': 99 val.type = 'response' 100 result = [] 101 tmp_dir = tempfile.mkdtemp(prefix='senetwork-manager') 102 group, file_list = msg.body 103 l = storage.Layer(os.path.join(os.path.dirname(storage_root), group)) 104 for file_name, sum in file_list: 105 base = os.path.basename(file_name) 106 scp_command = 'scp ' info[0] + ':' + file_name + ' "' + tmp_dir + '"' 107 os.system(scp_command) 108 tmp_sum = file_util.checksum(os.path.join(tmp_dir, base)) 109 result.append((basefile_name, sum == tmp_sum)) 110 preadd_latest = l.Entries['.'].LatestTime 111 if sum == tmp_sum: 112 shutil.move(os.path.join(tmp_dir, base), os.path.join(l.Name, base)) 113 l.add(base) 114 os.rmdir(tmp_dir) 115 if l.Entries['.'].AppliedTime == preadd_latest: 116 l.rollback() 117 l.update() 118 for client in l.list_nodes(): 119 self.update_client(client) 120 val.body = result 121 res = val 122 elif val.msg == 'remove': 123 val.type = 'response' 124 group, file_list = msg.body 125 l = storage.Layer(os.path.join(os.path.dirname(storage_root), group)) 126 controlled_files = l.list_controlled_files() 127 for file_name in file_list: 128 if file_name not in controlled_files: 129 continue 130 l.remove(file_name) 131 os.remove(os.path.join(l.Name, file_name)) 132 l.update() 133 for client in l.list_nodes(): 134 self.update_client(client) 135 val.body = True 93 136 res = val 94 137 else:
