def setFirstActiveAccount(self): """Find the first enabled account and define it as active""" aAccounts = self.getAllEnabledAccounts() if 0 == len(aAccounts): raise DRingCtrlAccountError("No active account !") self.account = aAccounts[0]
def Call(self, dest, account=None): """Start a call and return a CallID Use the current account previously set using setAccount(). If no account specified, first registered one in account list is used. return callID Newly generated callidentifier for this call """ if dest is None or dest == "": raise DRingCtrlError("Invalid call destination") # Set the account to be used for this call if not self.account: self.setFirstRegisteredAccount() if self.account is not "IP2IP" and not self.isAccountRegistered(): raise DRingCtrlAccountError( "Can't place a call without a registered account") # Send the request to the CallManager callid = self.callmanager.placeCall(self.account, dest) if callid: # Add the call to the list of active calls and set status to SENT self.activeCalls[callid] = { 'Account': self.account, 'To': dest, 'State': 'SENT' } return callid
def removeAccount(self, accountID=None): """Remove an account from internal list""" if accountID is None: raise DRingCtrlAccountError("Account ID must be specified") self.configurationmanager.removeAccount(accountID)
def setFirstRegisteredAccount(self): """Find the first enabled account and define it as active""" rAccounts = self.getAllRegisteredAccounts() if 0 == len(rAccounts): raise DRingCtrlAccountError("No registered account !") self.account = rAccounts[0]
def getAccountByAlias(self, alias): """Get account name having its alias""" for account in self.getAllAccounts(): details = self.getAccountDetails(account) if details['Account.alias'] == alias: return account raise DRingCtrlAccountError("No account matched with alias")
def setAccountByAlias(self, alias): """Define as active the first account who match with the alias""" for testedaccount in self.getAllAccounts(): details = self.getAccountDetails(testedaccount) if (details['Account.enable'] == 'true' and details['Account.alias'] == alias): self.account = testedaccount return raise DRingCtrlAccountError("No enabled account matched with alias")
def setAccount(self, account): """Define the active account The active account will be used when sending a new call """ if account in self.getAllAccounts(): self.account = account else: print(account) raise DRingCtrlAccountError("Not a valid account")
def Accept(self, callid): """Accept an incoming call identified by a CallID""" print("Accept call " + callid) if not self.account: self.setFirstRegisteredAccount() if not self.isAccountRegistered(): raise DRingCtrlAccountError("Can't accept a call without a registered account") if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.accept(callid)
def addAccount(self, details=None): """Add a new account account Add a new account to the daemon. Default parameters are \ used for missing account configuration field. Required parameters are type, alias, hostname, username and password input details """ if details is None: raise DRingCtrlAccountError("Must specifies type, alias, hostname, \ username and password in \ order to create a new account") return str(self.configurationmanager.addAccount(details))