Пример #1
0
 def startSimulation(self):
     if cherrypy.session.get(SESSION_AUTH_KEY,
                             None) is "true" and has_privileges():
         simulationID = UserDataInterface().getSimulationid(
             cherrypy.request.login)  #pass in this format
         logging.info('Starting simulation for user: '******' with Simulation id: ' +
                      str(simulationID))
         cloudInterface = CloudInterface()
         logging.info('Fetching assigned VM for simulation id: ' +
                      str(simulationID))
         vm = cloudInterface.assignVM(simulationID)
         if vm is None:
             logging.warning('VM could not assigned for user: '******' with Simulation id: ' + str(simulationID))
             return {'response': 'notavailable'}
         private_ip = vm['private_IP']
         key_name = vm['key_name']
         logging.info('Starting simulation for id: ' + str(simulationID) +
                      ' on VM:' + private_ip)
         trafficsim(private_ip, key_name, simulationID,
                    cherrypy.request.login).start()
         #t_sim.start()
         logging.info('Simulation start command sent..')
         return {'response': str(simulationID)}
     else:
         logging.warning('Unable to authenticate..')
         return {'response': "failure"}
Пример #2
0
class trafficsim(threading.Thread):

	cloudInterface = CloudInterface()
        	
	def __init__(self, vmIP, key_name, simulationID, userID):
		threading.Thread.__init__(self)
		logging.info('Initializing trafficsim from SimID' + str(simulationID));
		self.userInterface = UserDataInterface()
		self.simulationID = simulationID
		self.strSimulationID = str(simulationID)
		self.userID = userID
		self.vmIP = vmIP 
		self.keyName = key_name
		self.sumoport = SUMO_PORT
		datafolder = GENERATED_DATA_FOLDER + self.strSimulationID
		self.trafficdataxml = datafolder + TRAFFIC_DATA_XML
		self.trafficsignaldataxml = datafolder + TRAFFIC_SIGNAL_DATA_XML
		self.running = False
		self.traciinst = None
		print("..initialized")
			
	def disconnectSumo(self):
		print("Disconnecting...")
		self.running = False
		if self.traciinst is not None:
			self.traciinst.close()
		
		#self.sumoprocess.wait()
		
	def run(self):
		try:			
			print("running...")
			logging.info('Performing simulation setup for id: ' + self.strSimulationID);
			self.userInterface.updateSimulationRunningState(self.simulationID, "INITIALIZING", self.vmIP)
			self.remoteSim = RemoteSimulation(self.vmIP, self.keyName, self.simulationID)
			if (self.remoteSim.runRemoteSimulation() is False):
				logging.exception('Unable to start remote simulation: ' + self.strSimulationID)
				return		
			logging.info('Simulation server started for id: ' + self.strSimulationID);
			self.userInterface.ensureSimulationExists(self.simulationID)
			self.userInterface.updateSimulationRunningState(self.simulationID, "CONFIGURED")
    			# wait for simulation to start server
			time.sleep(1)
			logging.info('Instantiating Traci for host: ' + self.vmIP + ' for simulation: ' + self.strSimulationID);
			self.traciinst = Traci(port=self.sumoport, numRetries=10, host=self.vmIP)
			logging.info('Backing up old simulation...' + ' for simulation: ' + self.strSimulationID);
			backup = SimulationBackupInterface(self.simulationID)
			backup.backupSimulation(self.userID, "INACTIVE")
			
			logging.info('Starting simulation with ID: ' + self.strSimulationID);			
			self.mainloop()			
			
		except Exception, err:
			logging.exception(err)
		
		finally:
Пример #3
0
	def startSimulation(self):
		if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true" and has_privileges():
			simulationID = UserDataInterface().getSimulationid(cherrypy.request.login) #pass in this format
			logging.info('Starting simulation for user: '******' with Simulation id: ' + str(simulationID))
			cloudInterface = CloudInterface();
			logging.info('Fetching assigned VM for simulation id: ' + str(simulationID))
			vm = cloudInterface.assignVM(simulationID);
			if vm is None:
				logging.warning('VM could not assigned for user: '******' with Simulation id: ' + str(simulationID))
				return {'response' : 'notavailable'}
			private_ip = vm['private_IP'];
			key_name = vm['key_name'];
			logging.info('Starting simulation for id: ' + str(simulationID) + ' on VM:' + private_ip)
			trafficsim(private_ip, key_name, simulationID, cherrypy.request.login).start()
			#t_sim.start()
			logging.info('Simulation start command sent..');
			return {'response' : str(simulationID)}
		else:
			logging.warning('Unable to authenticate..')
			return {'response' :  "failure"}
Пример #4
0
 def setMode(self, user_mode=None):
     if cherrypy.session.get(SESSION_AUTH_KEY, None) is "true":
         username = cherrypy.request.login
         interface = UserDataInterface()
         simulationID = interface.getSimulationid(username)
         logging.info('simulationID: ' + str(simulationID) +
                      ' , username: '******', usermode: ' +
                      user_mode)
         interface.setUserMode(username, user_mode)
         cloudInterface = CloudInterface()
         simFolderId = interface.getSimulationFolder(simulationID, username)
         interface.ensureSimulationExists(simFolderId)
         return {
             'response': {
                 'status': "success",
                 'sim_folder': str(simFolderId),
                 'sim_id': str(simulationID)
             }
         }
     else:
         return {'response': "failure"}
Пример #5
0
from cloud.NovaCloudAccess import *
from cloud.CloudInterface import *

import sys

vm_name = sys.argv[1]
cloud = CloudInterface();
is_deleted = cloud.deleteVM(vm_name);
print is_deleted;

Пример #6
0
        try:
            while True:
                self.cloud.extend_session()
                time.sleep(self.config['loop_delay_s'])
                alert = self.cloud.check_for_alert()
                self.arduino.send_alert_update(alert=alert)
                if alert:
                    print(alert)
                self.arduino.request_button_status()
        except:
            print(traceback.format_exc())
            self.cloud.disconnect()
            raise


if __name__ == '__main__':
    from arduino import ArduinoInterface
    from cloud import CloudInterface
    import sys

    device = sys.argv[1]
    url = sys.argv[2]

    print('Configured to use device {}'.format(device))
    arduino = ArduinoInterface({'device': device})

    print('Configured to use server {}'.format(url))
    cloud = CloudInterface({'address': url})

    UselessMachine({'loop_delay_s': 1}, arduino, cloud).start()
Пример #7
0
from cloud.NovaCloudAccess import *
from cloud.CloudInterface import *

#client = NovaCloudAccess();
#client.getServerList();
#client.getImageList();
#client.getFlavorList();
#client.createServer("229-snapshot", "m1.medium");

cloud = CloudInterface();
vm_name = cloud.createVM();
print vm_name;

Пример #8
0
from cloud.NovaCloudAccess import *
from cloud.CloudInterface import *

#client = NovaCloudAccess();
#client.getServerList();
#client.getImageList();
#client.getFlavorList();
#client.createServer("229-snapshot", "m1.medium");

cloud = CloudInterface()
vm_name = cloud.createVM()
print vm_name