def nextBillingTime(self): """ Returns the next billing time (in seconds). @return: the next billing time (in seconds). """ return self.billingPolicy.nextBillingTime(self.startTimeSecs, currentTimeSecs())
def __init__(self, readableName, address, pemFile, vmType, monitoringScript, billingPolicy, password = None, userName="******", htm=None, startTimeSecs=None): """ Constr. @param readableName: see superclass. @param address: see superclass. @param pemFile: see superclass. @param vmType: The type of the VM. Must not be None. Must be an instance of VMType. @param monitoringScript: the location of the monitoring script. Must not be None. Must be valid. @param billingPolicy: the billing policy. Must not be null. @param userName: see superclass. @param htm: The HTM to use, or None if a new HTM should be created. @param startTimeSecs: the time, when the VM was started in milliseconds. If None - the VM is considered starting now. """ super(AppServer, self).__init__(readableName = readableName, address = address, pemFile = pemFile, userName = userName, password = password) assert htm is None or isinstance(htm, HTMWrapper), "Invalid HTM type %s" % type(htm) assert monitoringScript is not None and os.path.isfile(monitoringScript), "Invalid monitoring script %s" % (monitoringScript) assert isinstance(vmType, VMType), "Invalid VM type %s" % (vmType) assert startTimeSecs is None or startTimeSecs > 0, "Invalid start time %s" % (startTimeSecs) assert billingPolicy is not None, "Billing policty is None" self.monitoringScript = monitoringScript self.vmType = vmType self.htm = htm if htm is not None else HTMWrapper() self.lastMeasurement = None self.startTimeSecs = startTimeSecs if startTimeSecs is not None else currentTimeSecs() self.billingPolicy = billingPolicy # Start the monitoring remotePath = os.path.join("/home", self.userName, os.path.os.path.basename(self.monitoringScript)) log.info("Copying Monitoring File: %s to %s:%s", self.monitoringScript, self.readableName, remotePath) sftp = self.getSSHClient().open_sftp() sftp.put(self.monitoringScript, remotePath) sftp.close() log.info("Starting the monitoring script on: %s" % (self.readableName)) self.execRemoteCommand(command="bash {0} &> /dev/null".format(remotePath), asynch=True) self.statFile=os.path.expanduser("~/%s-%s.txt" % (readableName, formatCurrTime("%d-%measurement-%Y-%H:%M:%S")) ) log.info("Record measurements in: %s" %(self.statFile)) self._header() self._numMeas = 0
def __init__(self, readableName, address, pemFile, vmType, monitoringScript, billingPolicy, password=None, userName="******", htm=None, startTimeSecs=None): """ Constr. @param readableName: see superclass. @param address: see superclass. @param pemFile: see superclass. @param vmType: The type of the VM. Must not be None. Must be an instance of VMType. @param monitoringScript: the location of the monitoring script. Must not be None. Must be valid. @param billingPolicy: the billing policy. Must not be null. @param userName: see superclass. @param htm: The HTM to use, or None if a new HTM should be created. @param startTimeSecs: the time, when the VM was started in milliseconds. If None - the VM is considered starting now. """ super(AppServer, self).__init__(readableName=readableName, address=address, pemFile=pemFile, userName=userName, password=password) assert htm is None or isinstance( htm, HTMWrapper), "Invalid HTM type %s" % type(htm) assert monitoringScript is not None and os.path.isfile( monitoringScript), "Invalid monitoring script %s" % ( monitoringScript) assert isinstance(vmType, VMType), "Invalid VM type %s" % (vmType) assert startTimeSecs is None or startTimeSecs > 0, "Invalid start time %s" % ( startTimeSecs) assert billingPolicy is not None, "Billing policty is None" self.monitoringScript = monitoringScript self.vmType = vmType self.htm = htm if htm is not None else HTMWrapper() self.lastMeasurement = None self.startTimeSecs = startTimeSecs if startTimeSecs is not None else currentTimeSecs( ) self.billingPolicy = billingPolicy # Start the monitoring remotePath = os.path.join( "/home", self.userName, os.path.os.path.basename(self.monitoringScript)) log.info("Copying Monitoring File: %s to %s:%s", self.monitoringScript, self.readableName, remotePath) sftp = self.getSSHClient().open_sftp() sftp.put(self.monitoringScript, remotePath) sftp.close() log.info("Starting the monitoring script on: %s" % (self.readableName)) self.execRemoteCommand( command="bash {0} &> /dev/null".format(remotePath), asynch=True) self.statFile = os.path.expanduser( "~/%s-%s.txt" % (readableName, formatCurrTime("%d-%measurement-%Y-%H:%M:%S"))) log.info("Record measurements in: %s" % (self.statFile)) self._header() self._numMeas = 0