Changeset eab6ae1
- Timestamp:
- May 17, 2010 3:31:16 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- f00fb7d
- Parents:
- 5f6c3af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
r5f6c3af reab6ae1 916 916 sys.exit("Bad response. %s" % e.message) 917 917 918 class ns_image(image):919 def __init__(self):920 """921 Null constructor922 """923 924 image.__init__(self)925 926 def generate_topo_dict(self, splitout):927 class topo_parse:928 """929 Parse the topology XML and create the dats structure. This class930 is copied from federation.experiment_control.931 """932 def __init__(self):933 # Typing of the subelements for data conversion934 self.str_subelements = ('vname', 'vnode', 'ips', 'ip', 'member')935 self.int_subelements = ( 'bandwidth',)936 self.float_subelements = ( 'delay',)937 # The final data structure938 self.nodes = [ ]939 self.lans = [ ]940 self.topo = { \941 'node': self.nodes,\942 'lan' : self.lans,\943 }944 self.element = { } # Current element being created945 self.chars = "" # Last text seen946 947 def end_element(self, name):948 # After each sub element the contents is added to the current949 # element or to the appropriate list.950 if name == 'node':951 self.nodes.append(self.element)952 self.element = { }953 elif name == 'lan':954 self.lans.append(self.element)955 self.element = { }956 elif name in self.str_subelements:957 self.element[name] = self.chars958 self.chars = ""959 elif name in self.int_subelements:960 self.element[name] = int(self.chars)961 self.chars = ""962 elif name in self.float_subelements:963 self.element[name] = float(self.chars)964 self.chars = ""965 966 def found_chars(self, data):967 self.chars += data.rstrip()968 969 970 tp = topo_parse();971 parser = xml.parsers.expat.ParserCreate()972 parser.EndElementHandler = tp.end_element973 parser.CharacterDataHandler = tp.found_chars974 975 m = re.search('^#\s+Begin\s+Vtopo\s*$(.*)^#\s+End\s+Vtopo', splitout,976 re.MULTILINE | re.DOTALL)977 if m:978 str = m.group(1)979 else:980 sys.exit("Badly formatted split")981 982 parser.Parse(str)983 984 return tp.topo985 986 def __call__(self):987 """988 The control flow. Compose the request and print the response.989 """990 # Process the options using the customized option parser defined above991 parser = fedd_ns_image_opts()992 993 (opts, args) = parser.parse_args()994 995 if opts.trusted:996 if ( not os.access(opts.trusted, os.R_OK) ) :997 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)998 999 if opts.debug > 0: opts.tracefile=sys.stderr1000 1001 (user, cert) = self.get_user_info()1002 1003 if opts.cert != None: cert = opts.cert1004 1005 if cert == None:1006 sys.exit("No certificate given (--cert) or found")1007 1008 if os.access(cert, os.R_OK):1009 fid = fedid(file=cert)1010 else:1011 sys.exit("Cannot read certificate (%s)" % cert)1012 1013 if opts.file:1014 exp_desc = ""1015 try:1016 f = open(opts.file, 'r')1017 for line in f:1018 exp_desc += line1019 f.close()1020 except IOError:1021 sys.exit("Cannot read description file (%s)" %opts.file)1022 else:1023 sys.exit("Must specify an experiment description (--file)")1024 1025 if not opts.master:1026 opts.master="dummy"1027 1028 1029 req = {1030 'description': { 'ns2description': exp_desc },1031 'master': opts.master,1032 'include_fedkit': opts.fedkit,1033 'include_gatewaykit': opts.gatewaykit,1034 }1035 1036 1037 if opts.format and opts.outfile:1038 fmt = opts.format1039 file = opts.outfile1040 elif not opts.format and opts.outfile:1041 fmt = opts.outfile[-3:]1042 if fmt not in ("png", "jpg", "dot", "svg"):1043 sys.exit("Unexpected file type and no format specified")1044 file = opts.outfile1045 elif opts.format and not opts.outfile:1046 fmt = opts.format1047 file = None1048 else:1049 fmt="dot"1050 file = None1051 1052 try:1053 resp_dict = self.do_rpc(req,1054 opts.url, opts.transport, cert, opts.trusted,1055 serialize_only=opts.serialize_only,1056 tracefile=opts.tracefile,1057 caller=self.caller('Ns2Split'))1058 except self.RPCException, e:1059 exit_with_fault(\1060 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})1061 except RuntimeError, e:1062 sys.exit("Error processing RPC: %s" % e)1063 1064 1065 if resp_dict.has_key('output'):1066 if len(resp_dict['output']) < 1:1067 sys.exit("Bad response: could not split")1068 topo = self.generate_topo_dict(resp_dict['output'])1069 self.gen_image(topo, len(topo.get('node', [])), file, fmt,1070 opts.neato, opts.labels, opts.pixels)1071 elif opts.serialze_only:1072 sys.exit(0)1073 else:1074 sys.exit("Bad response. %s" % e.message)1075 1076 918 class topdl_image(image): 1077 919 def __init__(self): … … 1181 1023 self.gen_image(top, len(top.elements), file, fmt, opts.neato, 1182 1024 opts.labels, opts.pixels) 1025 1026 class ns_image(topdl_image): 1027 def __init__(self): 1028 """ 1029 Null constructor 1030 """ 1031 1032 topdl_image.__init__(self) 1033 1034 def __call__(self): 1035 """ 1036 The control flow. Compose the request and print the response. 1037 """ 1038 # Process the options using the customized option parser defined above 1039 parser = fedd_ns_image_opts() 1040 1041 (opts, args) = parser.parse_args() 1042 1043 if opts.trusted: 1044 if ( not os.access(opts.trusted, os.R_OK) ) : 1045 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted) 1046 1047 if opts.debug > 0: opts.tracefile=sys.stderr 1048 1049 (user, cert) = self.get_user_info() 1050 1051 if opts.cert != None: cert = opts.cert 1052 1053 if cert == None: 1054 sys.exit("No certificate given (--cert) or found") 1055 1056 if os.access(cert, os.R_OK): 1057 fid = fedid(file=cert) 1058 else: 1059 sys.exit("Cannot read certificate (%s)" % cert) 1060 1061 if opts.file: 1062 exp_desc = "" 1063 try: 1064 f = open(opts.file, 'r') 1065 for line in f: 1066 exp_desc += line 1067 f.close() 1068 except IOError: 1069 sys.exit("Cannot read description file (%s)" %opts.file) 1070 else: 1071 sys.exit("Must specify an experiment description (--file)") 1072 1073 if not opts.master: 1074 opts.master="dummy" 1075 1076 req = { 'description': { 'ns2description': exp_desc }, } 1077 1078 if opts.format and opts.outfile: 1079 fmt = opts.format 1080 file = opts.outfile 1081 elif not opts.format and opts.outfile: 1082 fmt = opts.outfile[-3:] 1083 if fmt not in ("png", "jpg", "dot", "svg"): 1084 sys.exit("Unexpected file type and no format specified") 1085 file = opts.outfile 1086 elif opts.format and not opts.outfile: 1087 fmt = opts.format 1088 file = None 1089 else: 1090 fmt="dot" 1091 file = None 1092 1093 try: 1094 resp_dict = self.do_rpc(req, 1095 opts.url, opts.transport, cert, opts.trusted, 1096 serialize_only=opts.serialize_only, 1097 tracefile=opts.tracefile, 1098 caller=self.caller('Ns2Topdl')) 1099 except self.RPCException, e: 1100 exit_with_fault(\ 1101 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code}) 1102 except RuntimeError, e: 1103 sys.exit("Error processing RPC: %s" % e) 1104 1105 1106 if 'experimentdescription' in resp_dict: 1107 if 'topdldescription' in resp_dict['experimentdescription']: 1108 exp = resp_dict['experimentdescription']['topdldescription'] 1109 top = topdl.Topology(**exp) 1110 self.gen_image(top, len(top.elements), file, fmt, opts.neato, 1111 opts.labels, opts.pixels) 1112 else: 1113 sys.exit("Bad response: could not translate") 1114 elif opts.serialze_only: 1115 sys.exit(0) 1116 else: 1117 sys.exit("Bad response. %s" % e.message) 1183 1118 1184 1119 class terminate(fedd_rpc):
Note: See TracChangeset
for help on using the changeset viewer.