def launch(management_port = 7001, default_controller_url = "https://localhost:9000", config_filename='/etc/gram/config.json'): config.initialize(config_filename) log.debug("VMOC.launch"); core.registerNew(VMOCController) for port in config.vlan_port_map.keys(): default_controller_port = get_default_controller_port() if int(port) == default_controller_port: continue of_task = of_01.OpenFlow_01_Task(port, '0.0.0.0') # In case we get a string from command line management_port = int(management_port) management_interface = VMOCManagementInterface(management_port, default_controller_url) management_interface.start()
def monitor(parms): try: opts, args = getopt.getopt(parms, "hdv:m:i:", ["vlan=", "mac=", "ip="]) except getopt.GetoptError: print "gram_mon.py: Error parsing args" sys.exit(2) found = False sip = None smac = None svlan = None for opt, arg in opts: # print opt, arg if opt == '-h': usage() sys.exit() elif opt in ("-i", "--ip"): sip = arg print "Searching for Slice Information for ipaddr " + sip elif opt in ("-m", "--mac"): smac = arg print "Searching for Slice Information for mac " + smac elif opt in ("-v", "--vlan"): svlan = arg print "Searching for Slice Information for vlan " + svlan config.initialize("/etc/gram/config.json") organization = gmoc.Organization(ORGNAME) pop = gmoc.POP(POPNAME) aggregate = gmoc.Aggregate('urn:publicid:IDN+bbn-cam-ctrl-1+authority+am', type='gram', version='3', pop=pop, operator=organization) #print config.stitching_info['aggregate_id'] #import pdb; pdb.set_trace() #get vmresources vmresources = config.compute_hosts stitching_handler = stitching.Stitching() resources = {} for k in vmresources: #print k #weird - if you don't use str - component_id comes back as type unicode component_id = str(config.urn_prefix + "node+" + k) #print component_id #import pdb; pdb.set_trace() resources[k] = gmoc.Resource(component_id, type='vmserver', pop=pop, operator=organization) aggregate.resources = resources.values() snapshot_dir = config.gram_snapshot_directory + "/" + getpass.getuser() allF = [] files = os.listdir(snapshot_dir) for f in files: filename = os.path.join(snapshot_dir, f) if (os.path.isfile(filename)): # print filename allF.append(filename) if allF: nfiles = sorted(allF, key=os.path.getctime) oldest = nfiles[0] newest = nfiles[-1] print "Latest snapshot file: " + newest + "\n" myslices = Archiving.read_state(newest, None, stitching_handler) sliver = {} for i, slice in myslices.iteritems(): slice_obj = gmoc.Slice(str(slice.getSliceURN())) #print "Slice: "+ str(slice.getSliceURN()) slivers = slice.getAllSlivers() for k, v in slivers.iteritems(): #print "*********************" #import pdb; pdb.set_trace() #sliver[v.getSliverURN()] = gmoc.Sliver(str(v.getSliverURN()), v.getExpiration(), v.getOperationalState(), aggregate, v.getUserURN()) #sliver[v.getSliverURN()] = gmoc.Sliver(str(v.getSliverURN()), v.getExpiration(), gmoc.SLIVER_STATE_UP, aggregate, gmoc.Contact(str(v.getUserURN()))) sliver[v.getSliverURN()] = gmoc.Sliver( str(v.getSliverURN()), expires=v.getExpiration(), state=gmoc.SLIVER_STATE_UP, aggregate=aggregate, creator=gmoc.Contact(str(v.getUserURN()))) sliver[v.getSliverURN()].slice = slice_obj sliver[v.getSliverURN()].created = v.getCreation() if v.getUUID() is not None: sliver[v.getSliverURN()].uuid = uuid.UUID(v.getUUID()) #print v.getCreation() #print v.getExpiration() #print v.getSliverURN() #print v.getOperationalState() #print v.getUserURN() #print v.getUUID() #print slice.getSliceURN() #import pdb; pdb.set_trace() #print v if isinstance(v, Archiving.VirtualMachine): #print "vm" #print v.getHost() #print v.getExternalIp() #why is ExternalIp not set - have to ask Stephen RRH #if v.getExternalIp() is not None: # print "IP " + v.getExternalIp() # if sip == str(v.getExternalIp()): if sip is not None: match = re.search(sip, str(v)) if match: #print "FOUND IP " + match.group() print "Diagnostic Information for ip = " + sip + ":" printDiagInfo(slice, v) found = True sliver[v.getSliverURN()].extIP = match.group() return #else: # print "No external IP " #print "v.getHost " + v.getHost() #print "v.getSliverURN " + v.getSliverURN() if v.getHost() != None and v.getSliverURN() != None: gmoc.ResourceMapping(str(v.getUUID()), type='vm', resource=resources[v.getHost()], sliver=sliver[v.getSliverURN()]) #print "*********************" elif isinstance(v, Archiving.NetworkLink): #print "Link" if v.getVLANTag() is not None: #print "vlan " + str(v.getVLANTag()) if svlan == str(v.getVLANTag()): print "Diagnostic Information for vlan = " + svlan + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].vlan = str(v.getVLANTag()) #else: # print "No VLAN Tag" #print "*********************" elif isinstance(v, Archiving.NetworkInterface): #print "NIC" #print "mac " + v.getMACAddress() if smac == str(v.getMACAddress()): print "Diagnostic Information for mac = " + smac + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].mac = str(v.getMACAddress()) if v.getVLANTag() is not None: #print "vlan " + str(v.getVLANTag()) if svlan == str(v.getVLANTag()): print "Diagnostic Information for vlan = " + svlan + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].vlan = str(v.getVLANTag()) #else: # print "No VLAN Tag" #print "*********************" else: print "Unknown Sliver Type" print "*********************" # print sliver # Now actually setup and report stuff #client = gmoc.GMOCClient( # serviceURL = 'https://gmoc-db.grnoc.iu.edu/', # username = MONUSERNAME, # password = MONPASSWORD, # ) # import pdb; pdb.set_trace() if found == False: print "\n\n*********************" print "PRINTING ALL CURRENT INFORMATION FOR " + time.strftime("%c") print pop print "*********************"
def installerCommands(self, dir, module_name, module_installer, install): prefix = "install" if not install: prefix = "uninstall" module_install_file = open("%s/%s_%s.sh" % (dir, prefix, module_name), "w") module_installer.clear() if install: module_installer.installCommands() else: module_installer.uninstallCommands() module_install_commands = module_installer.getCommands() for ic in module_install_commands: module_install_file.write(ic) module_install_file.write("\n") module_install_file.close() if __name__ == "__main__": config.initialize("/etc/gram/config.json") openstack = OpenStack() openstack.createCommands(OpenStack._CONTROL_INSTALLERS, \ "/tmp/install", "install_control.sh", \ "uninstall_control.sh") openstack.createCommands(OpenStack._COMPUTE_INSTALLERS, \ "/tmp/install", "install_compute.sh", \ "uninstall_compute.sh")
# # modify_conf_env.py file variable config_variable prefix # # Create a 'sed' command to modify the contents of a given config file line # that starts with # prefix variable=old_value into # prefix variable=new_value # where new value is taken from the config_variable of the gram.am.gram.config package import sys from gram.am.gram import config if __name__ == "__main__": if len(sys.argv) != 5: print "Usage: modify_conf_env file variable config_variable prefix" sys.exit() config.initialize('/etc/gram/config.json') filename = sys.argv[1] variable = sys.argv[2] config_variable = sys.argv[3] prefix = sys.argv[4] if prefix != "": prefix = prefix + " " if config_variable == 'control_host': new_value = "http:\/\/" + config.control_host + ":5000\/v2.0\/" else: new_value = getattr(config, config_variable) print "sed -i 's/^%s%s=.*/%s%s=%s/' %s" % \ (prefix, variable, prefix, variable, new_value, filename)
if not install: prefix = "uninstall" module_install_file = open("%s/%s_%s.sh" % (dir, prefix, module_name), "w") module_installer.clear() if install: module_installer.installCommands() else: module_installer.uninstallCommands() module_install_commands = module_installer.getCommands() for ic in module_install_commands: module_install_file.write(ic) module_install_file.write("\n") module_install_file.close() if __name__ == "__main__": config.initialize("/etc/gram/config.json") openstack = OpenStack() openstack.createCommands(OpenStack._CONTROL_INSTALLERS, \ "/tmp/install", "install_control.sh", \ "uninstall_control.sh") openstack.createCommands(OpenStack._COMPUTE_INSTALLERS, \ "/tmp/install", "install_compute.sh", \ "uninstall_compute.sh")
def monitor(parms): try: opts, args = getopt.getopt(parms,"hdv:m:i:", ["vlan=", "mac=", "ip="]) except getopt.GetoptError: print "gram_mon.py: Error parsing args" sys.exit(2) found = False sip = None smac = None svlan = None for opt, arg in opts: # print opt, arg if opt == '-h': usage() sys.exit() elif opt in ("-i", "--ip"): sip = arg print "Searching for Slice Information for ipaddr " + sip elif opt in ("-m", "--mac"): smac = arg print "Searching for Slice Information for mac " + smac elif opt in ("-v", "--vlan"): svlan = arg print "Searching for Slice Information for vlan " + svlan config.initialize("/etc/gram/config.json") organization = gmoc.Organization( ORGNAME ) pop = gmoc.POP( POPNAME ) aggregate = gmoc.Aggregate('urn:publicid:IDN+bbn-cam-ctrl-1+authority+am', type='gram', version='3', pop = pop, operator=organization) #print config.stitching_info['aggregate_id'] #import pdb; pdb.set_trace() #get vmresources vmresources = config.compute_hosts stitching_handler = stitching.Stitching() resources={} for k in vmresources: #print k #weird - if you don't use str - component_id comes back as type unicode component_id = str(config.urn_prefix + "node+" + k) #print component_id #import pdb; pdb.set_trace() resources[k] = gmoc.Resource(component_id, type = 'vmserver', pop = pop, operator = organization) aggregate.resources = resources.values() snapshot_dir = config.gram_snapshot_directory + "/" + getpass.getuser() allF = [] files = os.listdir(snapshot_dir) for f in files: filename = os.path.join(snapshot_dir, f) if(os.path.isfile(filename)): # print filename allF.append(filename) if allF: nfiles = sorted(allF, key=os.path.getctime) oldest = nfiles[0] newest = nfiles[-1] print "Latest snapshot file: " + newest + "\n" myslices = Archiving.read_state(newest, None, stitching_handler) sliver = {} for i, slice in myslices.iteritems(): slice_obj = gmoc.Slice(str(slice.getSliceURN())) #print "Slice: "+ str(slice.getSliceURN()) slivers = slice.getAllSlivers() for k, v in slivers.iteritems(): #print "*********************" #import pdb; pdb.set_trace() #sliver[v.getSliverURN()] = gmoc.Sliver(str(v.getSliverURN()), v.getExpiration(), v.getOperationalState(), aggregate, v.getUserURN()) #sliver[v.getSliverURN()] = gmoc.Sliver(str(v.getSliverURN()), v.getExpiration(), gmoc.SLIVER_STATE_UP, aggregate, gmoc.Contact(str(v.getUserURN()))) sliver[v.getSliverURN()] = gmoc.Sliver(str(v.getSliverURN()), expires = v.getExpiration(), state = gmoc.SLIVER_STATE_UP, aggregate = aggregate, creator = gmoc.Contact(str(v.getUserURN()))) sliver[v.getSliverURN()].slice = slice_obj sliver[v.getSliverURN()].created = v.getCreation() if v.getUUID() is not None: sliver[v.getSliverURN()].uuid = uuid.UUID(v.getUUID()) #print v.getCreation() #print v.getExpiration() #print v.getSliverURN() #print v.getOperationalState() #print v.getUserURN() #print v.getUUID() #print slice.getSliceURN() #import pdb; pdb.set_trace() #print v if isinstance(v, Archiving.VirtualMachine): #print "vm" #print v.getHost() #print v.getExternalIp() #why is ExternalIp not set - have to ask Stephen RRH #if v.getExternalIp() is not None: # print "IP " + v.getExternalIp() # if sip == str(v.getExternalIp()): if sip is not None: match = re.search(sip, str(v)) if match: #print "FOUND IP " + match.group() print "Diagnostic Information for ip = " + sip + ":" printDiagInfo(slice, v) found = True sliver[v.getSliverURN()].extIP = match.group() return #else: # print "No external IP " #print "v.getHost " + v.getHost() #print "v.getSliverURN " + v.getSliverURN() if v.getHost() != None and v.getSliverURN() != None: gmoc.ResourceMapping(str(v.getUUID()), type = 'vm', resource = resources[v.getHost()], sliver = sliver[v.getSliverURN()]) #print "*********************" elif isinstance(v, Archiving.NetworkLink): #print "Link" if v.getVLANTag() is not None: #print "vlan " + str(v.getVLANTag()) if svlan == str(v.getVLANTag()): print "Diagnostic Information for vlan = " + svlan + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].vlan = str(v.getVLANTag()) #else: # print "No VLAN Tag" #print "*********************" elif isinstance(v, Archiving.NetworkInterface): #print "NIC" #print "mac " + v.getMACAddress() if smac == str(v.getMACAddress()): print "Diagnostic Information for mac = " + smac + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].mac = str(v.getMACAddress()) if v.getVLANTag() is not None: #print "vlan " + str(v.getVLANTag()) if svlan == str(v.getVLANTag()): print "Diagnostic Information for vlan = " + svlan + ":" printDiagInfo(slice, v) found = True return sliver[v.getSliverURN()].vlan = str(v.getVLANTag()) #else: # print "No VLAN Tag" #print "*********************" else: print "Unknown Sliver Type" print "*********************" # print sliver # Now actually setup and report stuff #client = gmoc.GMOCClient( # serviceURL = 'https://gmoc-db.grnoc.iu.edu/', # username = MONUSERNAME, # password = MONPASSWORD, # ) # import pdb; pdb.set_trace() if found == False: print "\n\n*********************" print "PRINTING ALL CURRENT INFORMATION FOR " + time.strftime("%c") print pop print "*********************"