Пример #1
0
    def _node_logic(self, dev_name, sw_info, port_info_list, conf_list):
        ports = []
        cplane_ports = []
        client = OfpmClient(ncs_cfg.ofpm_url)
        cable_links = client.get_connected_port(dev_name)
        cable_links = cable_links.result

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

        subnet = ''
        for port in port_info_list:
            conf = conf_map.get(port['traffic_type'], None)
            if not conf:
                continue

            ip_range = IpAddress(conf['ipRange'])
            new_ip = IpAddress(sw_info['ip_address'], port['netmask'])
            new_ip.configure_network_address(ip_range.compute_network_address())
            port['ip_address'] = new_ip.compute_ip_string()
            ports.append(port)
            subnet = port['netmask']

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

        cfg = Config(ports=ports, subnet=subnet)
        return cfg, cplane_ports
Пример #2
0
    def configure(self, config):
        print 'CALLED UbuntuDriver'
        print 'config = %s' % config
        plane_m = self._search_port_type(config.ports, PlaneType.M.value)
        plane_c = self._search_port_type(config.ports, PlaneType.C.value)
        plane_d = self._search_port_type(config.ports, PlaneType.D.value)
        plane_s = self._search_port_type(config.ports, PlaneType.S.value)

        config_map = {}

        if plane_m:
            m = IpAddress(plane_m['ip_address'], plane_m['netmask'])
            config_map['#M '] = ''
            config_map[':M '] = ''
            config_map['ethM'] = plane_m['nic_name']
            config_map['M.ip'] = m.compute_ip_string()
            config_map['M.network'] = m.to_network_address_string()
            config_map['M.subnet'] = m.compute_subnet_string()
            config_map['M.broadcast'] = m.to_broadcast_address_string()
            if 'gateway' in plane_m:
                m.configure_local_address(plane_m['gateway'])
                config_map['M.gateway'] = m.compute_ip_string()
            if 'dns' in plane_m:
                m.configure_local_address(plane_m['dns'])
                config_map['M.dns'] = m.compute_ip_string()

        if plane_c:
            c = IpAddress(plane_c['ip_address'], plane_c['netmask'])
            config_map['#C '] = ''
            config_map[':C '] = ''
            config_map['ethC'] = plane_c['nic_name']
            config_map['C.ip'] = c.compute_ip_string()
            config_map['C.network'] = c.to_network_address_string()
            config_map['C.subnet'] = c.compute_subnet_string()
            config_map['C.broadcast'] = c.to_broadcast_address_string()
            if 'gateway' in plane_c:
                c.configure_local_address(plane_c['gateway'])
                config_map['C.gateway'] = c.compute_ip_string()
            if 'dns' in plane_c:
                c.configure_local_address(plane_c['dns'])
                config_map['C.dns'] = c.compute_ip_string()

        if plane_d:
            d = IpAddress(plane_d['ip_address'], plane_d['netmask'])
            config_map['#D '] = ''
            config_map[':D '] = ''
            config_map['ethD'] = plane_d['nic_name']
            config_map['D.ip'] = d.compute_ip_string()
            config_map['D.network'] = d.to_network_address_string()
            config_map['D.subnet'] = d.compute_subnet_string()
            config_map['D.broadcast'] = d.to_broadcast_address_string()
            if 'gateway' in plane_d:
                d.configure_local_address(plane_d['gateway'])
                config_map['D.gateway'] = d.compute_ip_string()
            if 'dns' in plane_d:
                d.configure_local_address(plane_d['dns'])
                config_map['D.dns'] = d.compute_ip_string()

        if plane_s:
            s = IpAddress(plane_s['ip_address'], plane_s['netmask'])
            config_map['#S '] = ''
            config_map[':S '] = ''
            config_map['ethS'] = plane_s['nic_name']
            config_map['S.ip'] = s.compute_ip_string()
            config_map['S.network'] = s.to_network_address_string()
            config_map['S.subnet'] = s.compute_subnet_string()
            config_map['S.broadcast'] = s.to_broadcast_address_string()
            if 'gateway' in plane_s:
                s.configure_local_address(plane_s['gateway'])
                config_map['S.gateway'] = s.compute_ip_string()
            if 'dns' in plane_s:
                s.configure_local_address(plane_s['dns'])
                config_map['S.dns'] = s.compute_ip_string()

        with open(self.DRIVER_DIR + '/linux/config/ubuntu') as f:
            cfgfile = f.read()
            cfgcmd = utils.replace_each(cfgfile, config_map)
            print cfgcmd
            try:
                client = pxssh.pxssh()
                client.login(self.ipaddress, self.login.user, self.login.password)
                client.send(cfgcmd)
                client.expect('Password.*:|password.*:'.split('|'))
                client.sendline(self.login.password)
                client.prompt()
                client.logout()
            except pxssh.ExceptionPexpect as e:
                print e.message
                return [-1, 'expect error.']
            except pxssh.TIMEOUT as e:
                print e.message
                return [-1, 'timeout.']
        print 'END UbuntuDriver'
        return [0, 'success.']
Пример #3
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