def createPod(self, dbSession): if bottle.request.json is None: raise bottle.HTTPError( 400, exception=InvalidRequest("No json in request object")) else: pod = bottle.request.json.get('pod') if pod is None: raise bottle.HTTPError( 400, exception=InvalidRequest("POST body cannot be empty")) l3ClosMediation = L3ClosMediation(self._conf, self.__daoClass) podDevices = self.getDevDictFromDict(pod) pod = self.getPodFromDict(pod) podName = pod.pop('name') try: createdPod = l3ClosMediation.createPod(podName, pod, podDevices) url = str(bottle.request.url).translate(None, ',') + '/' + createdPod.id pod = self.getPod(dbSession, createdPod.id, url) except Exception as e: logger.debug('StackTrace: %s' % (traceback.format_exc())) raise bottle.HTTPError(400, exception=e) bottle.response.set_header('Location', url) bottle.response.status = 201 return pod
def create_pods(self, pod_definition_file): ret_list = [] pods_yaml_file = os.path.join(propLoader.propertyFileLocation, pod_definition_file) try: pods_file_stream = open(pods_yaml_file, 'r') pods_template = yaml.load(pods_file_stream) pods_definition = {} if (pods_template.has_key("pods")): pods_definition = pods_template["pods"] l3ClosMediation = L3ClosMediation() for pod in pods_definition: l3ClosMediation.createPod(pod, pods_definition[pod]) else: print "Could not find pods definition in " + pods_yaml_file except IOError as e: print "Could not open " + pods_yaml_file print e.strerror except ImportError: print "Could not load " + pods_yaml_file finally: pass
def getDeviceConfig(self): l3ClosMediation = L3ClosMediation(conf=self._conf) config = l3ClosMediation.createLeafConfigFor2Stage(self.device) # l3ClosMediation used seperate db sessions to create device config # expire device from current session for lazy load with committed data self._session.expire(self.device) return config
def createDeviceConfiguration(self, dbSession, podId): try: l3ClosMediation = L3ClosMediation(self._conf, self.__daoClass) if l3ClosMediation.createDeviceConfig(podId) is True: return bottle.HTTPResponse(status=200) except PodNotFound as e: raise bottle.HTTPError(404, exception=e) except Exception as e: raise bottle.HTTPError(500, exception=e)
def handle_show_bgp_summary ( self , *args): #print "Yeah Got it!!" l3ClosMediation = L3ClosMediation () pods = l3ClosMediation.loadClosDefinition() #l3ClosMediation.createSpineIFDs('anotherPod', 'QFX5100-24Q') path = os.getcwd() path = path + '/conf/junosTemplates/policyOptions.txt' # print path f = open(path,'r').read() print f
def handle_update_pods(self, pod_id): l3ClosMediation = L3ClosMediation() ## Get Object for this Pod based on ID ## Get Data from config file report = ResourceAllocationReport() with report._dao.getReadSession() as session: pod_object = report._dao.getObjectById(session, Pod, pod_id) pod_name = pod_object.name pods_from_conf = l3ClosMediation.loadClosDefinition() l3ClosMediation.updatePod(pod_id, pods_from_conf[pod_name]) ## Regenerate devices configuration, cabling plan and ZTP configuration l3ClosMediation.createCablingPlan(pod_id) l3ClosMediation.createDeviceConfig(pod_id) ztpServer = ZtpServer() ztpServer.createPodSpecificDhcpConfFile(session, pod_id)
def reconfigPod(self, dbSession, podId): if bottle.request.json is None: raise bottle.HTTPError( 400, exception=InvalidRequest("No json in request object")) else: inPod = bottle.request.json.get('pod') if inPod is None: raise bottle.HTTPError( 400, exception=InvalidRequest("POST body cannot be empty")) l3ClosMediation = L3ClosMediation(self._conf, self.__daoClass) pod = self.getPodFromDict(inPod) #pod['id'] = podId #pod['uri'] = str(bottle.request.url).translate(None, ',') podDevices = self.getDevDictFromDict(inPod) # Pass the pod and podDevices dictionaries to config/update API, then return try: updatedPod = l3ClosMediation.updatePod(podId, pod, podDevices) url = str(bottle.request.url).translate(None, ',') + '/' + updatedPod.id return self.getPod(dbSession, podId, url) except Exception as e: raise bottle.HTTPError(400, exception=e)
def handle_create_device_config(self, pod_id): l3ClosMediation = L3ClosMediation() l3ClosMediation.createDeviceConfig(pod_id)
def handle_create_cabling_plan(self, pod_id): l3ClosMediation = L3ClosMediation() l3ClosMediation.createCablingPlan(pod_id)
except Exception as exc: logger.error('updateDeviceConfiguration failed for %s, %s' % (self.deviceLogStr, exc)) logger.debug('StackTrace: %s' % (traceback.format_exc())) configurationUnit.rollback() raise DeviceRpcFailed( 'updateDeviceConfiguration failed for %s' % (self.deviceLogStr), exc) finally: configurationUnit.unlock() logger.debug('Unlock config for %s' % (self.deviceLogStr)) if __name__ == "__main__": #TODO: need to add integration test, hard to write unit tests #### TEST CODE, should not be executed #### .219 is the only device we have on which we can test #### please rollback changes from CLI after running this test #configurator = TwoStageConfigurator('192.168.48.219') #configurator.start2StageConfiguration() #### TEST CODE, should not be executed l3ClosMediation = L3ClosMediation() pods = l3ClosMediation.loadClosDefinition() pod = l3ClosMediation.createPod('anotherPod', pods['anotherPod']) raw_input("pause...") leaf1 = l3ClosMediation.__dao.Session.query(Device).filter( Device.name == 'clos-leaf-01').one() c = L2DataCollector(leaf1.id) c.startL2Report()
def handle_create_device_config ( self, pod_name ): l3ClosMediation = L3ClosMediation () pods = l3ClosMediation.loadClosDefinition() l3ClosMediation.processFabric ( pod_name , pods [ pod_name ], reCreateFabric = True)