def reg_hwid(self): # choose mac address as HWID for the moment self.hwid = common.get_mac_addr() print 'hwid:', self.hwid WrtGateway.s_hwid = self.hwid # if hwid has been registered, make sure it won't be registered again if common.is_hwid_existed(self.hwid) == True: return body = '<RegisterHWSN><HWSN>' + self.hwid + \ '</HWSN><User>Admin</User>'\ '<Password>admin</Password></RegisterHWSN>' header = {'Content-type': 'text/xml'} print 'registering hwid...' try: ret = restful.method_post(init.url_registerHW, body, header) if ret.split('>')[2].split('<')[0] == 'true': print 'register hwid ok' common.wr_settings(self.hwid, '', 0) common.wr_settings('', '', 1) except: # repeating registering hwid will raise exception print 'hwid already exists or network off' common.wr_settings(self.hwid, '', 0) common.wr_settings('', '', 1)
def reg_hwid(self): # register hardware id #self.hwid = '200000' self.hwid = common.get_mac_addr() print 'hwid:',self.hwid WrtGateway.s_hwid = self.hwid if common.is_hwid_existed(self.hwid) == True: return body = '<RegisterHWSN><HWSN>' + self.hwid + \ '</HWSN><User>Admin</User>'\ '<Password>admin</Password></RegisterHWSN>' header = {'Content-type':'text/xml'} print 'registering hwid...' try: ret = restful.method_post(init.url_registerHW,body,header) if ret.split('>')[2].split('<')[0] == 'true': print 'register hwid ok' common.wr_settings(self.hwid,'',0) common.wr_settings('','',1) except: # repeating registering hwid will raise exception print 'hwid already exists or network off' common.wr_settings(self.hwid,'',0) common.wr_settings('','',1)
def del_mw(self): # just delete mwid and its property not including hwid body = '<Verification xmlns="http://schemas.datacontract.org/2004/07/EntityLib.Entity"> \ <EmailAddress>' + self.mail + '</EmailAddress> \ <HWSN>' + self.hwid + '</HWSN> \ <MWID>' + self.mwid + '</MWID></Verification>' header = {'Content-type': 'text/xml'} print '\ndeleting gateway...' ret = restful.method_post(init.url_deleteGW, body, header) if ret.split('>')[1].split('<')[0] == 'true': print 'delete mw ok' # clear mwid common.wr_settings('', '', 1) # clear updated flag common.wr_settings('0', '', 2)
def del_mw(self): # just delete mwid and its property not including hwid body = '<Verification xmlns="http://schemas.datacontract.org/2004/07/EntityLib.Entity"> \ <EmailAddress>' + self.mail + '</EmailAddress> \ <HWSN>' + self.hwid + '</HWSN> \ <MWID>' + self.mwid + '</MWID></Verification>' header = {'Content-type':'text/xml'} print '\ndeleting gateway...' ret = restful.method_post(init.url_deleteGW,body,header) if ret.split('>')[1].split('<')[0] == 'true': print 'delete mw ok' # clear mwid common.wr_settings('','',1) # clear updated flag common.wr_settings('0','',2)
def reg_mwid(self): mwid = common.is_mwid_existed(self.hwid) if mwid != '': # make sure it won't be registered again self.mwid = mwid print 'mwid:', mwid WrtGateway.s_mwid = self.mwid return body = '<Verification><HWSN>' + self.hwid + '</HWSN><EmailAddress>' + self.mail + \ '</EmailAddress><MWID></MWID></Verification>' header = {'Content-type': 'text/xml'} print 'registering mwid...' ret = restful.method_post(init.url_registerMW, body, header) self.mwid = ret.split('>')[2].split('<')[0] WrtGateway.s_mwid = self.mwid print 'register mwid ok.mwid:', self.mwid common.wr_settings(self.mwid, '', 1) common.wr_settings('0', '', 2)
def update_mw(self,force_update=False): # I haven't add resid in this body, which can be done with other interfaces # but at lease one devid should be included in this body, # or the following call add_dev will fail # force_update means force updating property if not force_update and common.is_updated() == True: return body = common.rd_prop('../cfg/gw_property.xml') header = {'Content-type':'text/xml'} print 'updating gateway property...' ret = restful.method_post(init.url_updateMW + '/' + self.mwid,body,header) if ret.split('>')[2].split('<')[0] == 'true': print 'update gateway property ok' common.wr_settings('1','',2) common.clear_file('../cfg/mac_dev_map.cfg') common.clear_file('../cfg/mac_resID_resPlat_map.cfg')
def reg_mwid(self): mwid = common.is_mwid_existed(self.hwid) if mwid != '': # make sure it won't be registered again self.mwid = mwid print 'mwid:',mwid WrtGateway.s_mwid = self.mwid return body = '<Verification><HWSN>' + self.hwid + '</HWSN><EmailAddress>' + self.mail + \ '</EmailAddress><MWID></MWID></Verification>' header = {'Content-type':'text/xml'} print 'registering mwid...' ret = restful.method_post(init.url_registerMW,body,header) self.mwid = ret.split('>')[2].split('<')[0] WrtGateway.s_mwid = self.mwid print 'register mwid ok.mwid:',self.mwid common.wr_settings(self.mwid,'',1) common.wr_settings('0','',2)
def update_mw(self, force_update=False): # I haven't add resid in this body, which can be done with other interfaces # but at lease one devid should be included in this body, # or the following call add_dev will fail # force_update means force updating property if not force_update and common.is_updated() == True: return body = common.rd_prop('../cfg/gw_property.xml') header = {'Content-type': 'text/xml'} print 'updating gateway property...' ret = restful.method_post(init.url_updateMW + '/' + self.mwid, body, header) if ret.split('>')[2].split('<')[0] == 'true': print 'update gateway property ok' common.wr_settings('1', '', 2) common.clear_file('../cfg/mac_dev_map.cfg') common.clear_file('../cfg/mac_resID_resPlat_map.cfg')