def add_dev(): # no res default, and no need to give devid by yourself body = common.rd_prop('cfg/dev_property.xml') header = {'Content-type':'text/xml'} print '\nadd device...' ret = restful.method_post(init.url_addDevice + '/' + WrtGateway.s_mwid,body,header) newdevid = ret.split('>')[2].split('<')[0] if newdevid == 'false': print 'add device failed' sys.exit(-1) print 'devid:' + newdevid + ' newly added' #common.wr_settings(newdevid,'',2) WrtGateway.s_first_time_add_dev = True if WrtGateway.s_first_time_add_dev: #WrtGateway.del_dev('00') pass return newdevid
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 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 add_dev(): # no res default, and no need to give devid by yourself body = common.rd_prop('../cfg/dev_property.xml') header = {'Content-type': 'text/xml'} print '\nadd device...' ret = restful.method_post(init.url_addDevice + '/' + WrtGateway.s_mwid, body, header) newdevid = ret.split('>')[2].split('<')[0] if newdevid == 'false': print 'add device failed' sys.exit(-1) print 'devid:' + newdevid + ' newly added' #common.wr_settings(newdevid,'',2) WrtGateway.s_first_time_add_dev = True if WrtGateway.s_first_time_add_dev: #WrtGateway.del_dev('00') pass return newdevid
def add_res(devid,res_type): body_init = common.rd_prop('cfg/res_property.xml') strinfo=re.compile('type') body=strinfo.sub(res_type,body_init) print 'add_res body:\n',body header = {'Content-type':'text/xml'} print '\nadd resource...' ret = restful.method_post(init.url_addRes + '/' + WrtGateway.s_mwid + '?devid=' + devid,body,header) newresid = ret.split('>')[2].split('<')[0] if newresid == 'false': print 'add resource failed' sys.exit(-1) print 'resid:' + newresid + ' newly added for ' + devid #common.wr_settings(newresid,devid,3) return newresid
def add_res(devid, res_type): body_init = common.rd_prop('../cfg/res_property.xml') strinfo = re.compile('type') body = strinfo.sub(res_type, body_init) print 'add_res body:\n', body header = {'Content-type': 'text/xml'} print '\nadd resource...' ret = restful.method_post( init.url_addRes + '/' + WrtGateway.s_mwid + '?devid=' + devid, body, header) newresid = ret.split('>')[2].split('<')[0] if newresid == 'false': print 'add resource failed' sys.exit(-1) print 'resid:' + newresid + ' newly added for ' + devid #common.wr_settings(newresid,devid,3) return newresid