Exemplo n.º 1
0
    def run(self, user, password, token, data):
        print 'SwitchConfigDecoder run!'
#        dev_name = data['deviceName']
        dev_name = data['dev']['device_name']

        client = DmdbClient()
        client.set_auth(token)
        sw_info = client.get_switch(dev_name)
        sw_info = sw_info.result[0]

        port_info_list = client.get_port(dev_name)
        port_info_list = port_info_list.result

        cplane_ports = []
        if sw_info['traffic_type'] == DeviceTrafficType.PLANE:
            config = self._plane_logic(port_info_list, data['conf'])
        else:
            config, cplane_ports = self._node_logic(dev_name, sw_info, port_info_list, data['conf'])

        self._driver.devicename = dev_name
        self._driver.ipaddress = sw_info['ip_address']
        self._driver.login = Login(user, password, None)
        error, message = self._driver.configure(config)
        if error:
            return message

#        for port in port_buf:
#            client.update_port()

        #en queue cplane

        return message
Exemplo n.º 2
0
    def run(self, user, password, token, data):
        print 'NodeConfigDecoder run!'
#        dev_name = data['deviceName']
        print data
        dev_name = data['dev']['device_name']

        client = DmdbClient()
        client.set_auth(token)
        node_info = client.get_node(dev_name)
        node_info = node_info.result[0]

        nic_info_list = client.get_nic(dev_name)
        nic_info_list = nic_info_list.result


        client = OfpmClient(ncs_cfg.ofpm_url)
        cable_links = client.get_connected_port(dev_name)
        cable_links = cable_links.result

        conf_map = {}
        for conf in data['conf']:
            plane_id = conf['planeId']
            conf_map[plane_id] = conf

        nic_m_addr = None
        config = []
        cplane_ports = []
        for nic in nic_info_list:
            if nic['traffic_type'] == PlaneType.M.value:
                nic_m_addr = nic['ip_address']

            conf = conf_map.get(nic['traffic_type'], None)
            if not conf:
                continue

            ip_range = IpAddress(conf['ipRange'])
            new_ip = IpAddress(nic['ip_address'], nic['netmask'])
            new_ip.configure_network_address(ip_range.compute_network_address())
            nic['ip_address'] = new_ip.compute_ip_string()
            config.append(nic)

            if nic['traffic_type'] == PlaneType.C.value:
                neighbor_port = self._search_neighbor_port(dev_name, nic['nic_name'], cable_links)
                cplane_ports.append({'port': neighbor_port, 'conf': conf})

        self._driver.devicename = dev_name
        self._driver.ipaddress = nic_m_addr
        self._driver.login = Login(user, password, None)
        driver_cfg = Config(ports=nic_info_list)
        try:
            error, message = self._driver.configure(driver_cfg)
        except Exception as e:
            print e
        if error:
            return message

#        for port in port_buf:
#            client.update_port()

        #en queue cplane

        return message