def configure_fuel_node(node_id, workdir, env_id, admin_gw):
    
    run("mkdir -p ~/fuelbench")
    
    with cd('~/fuelbench'):
        # node network configuration
        cmdline = "fuel node --node-id {node_id} --network --download".format(node_id=node_id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
        
        buf = StringIO.StringIO(result)
        path_found = False
        
        for line in buf.readlines():
            if path_found:
                remote_path = line.strip()
            
            if re.search(r'^Node attributes for interfaces were written to', line):
                path_found = True
                continue
            
        if not path_found:
            raise RemoteTaskError('Node network configuration file not found')

        filelist = get(remote_path, workdir)        
        if len(filelist) != 1:
            raise RemoteTaskError('Failed to get {0}'.format(remote_path))
        
        local_path = filelist[0]
        network_cfg = utils.modify_yamlfile(local_path, setup_node_network)
        logger.debug('Saving %s: ', local_path)
        logger.debug(network_cfg)
        
        put(local_path, remote_path)
        
        cmdline = "fuel node --node-id {node_id} --network --upload".format(node_id=node_id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
        
        # node provisioning configuration
        cmdline = "fuel --env {env_id} provisioning --default --node {node_id}".format(env_id=env_id,
                                                                                       node_id=node_id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
        
        buf = StringIO.StringIO(result)
        match = None
        
        for line in buf.readlines():
            match = re.search(r'^Default provisioning info .*downloaded to\s+(.+)', line)
            if match:
                remote_dir = match.group(1).strip()
                remote_path = os.path.join(remote_dir, 'node-{0}.yaml'.format(node_id))
                break
            
        if not match:
            raise RemoteTaskError('Node provisioning configuration file not found')

        filelist = get(remote_path, workdir)        
        if len(filelist) != 1:
            raise RemoteTaskError('Failed to get {0}'.format(remote_path))
        
        local_path = filelist[0]
        network_cfg = utils.modify_yamlfile(local_path, setup_node_provisioning, admin_gw)
        logger.debug('Saving %s: ', local_path)
        logger.debug(network_cfg)
        
        put(local_path, remote_path)
        
        cmdline = "fuel --env {env_id} provisioning --upload".format(env_id=env_id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
def configure_fuel_env(id, workdir, public_vip, floating_ranges, public_cidr, public_gateway, public_ranges, upstream_dns):
    
    run("mkdir -p ~/fuelbench")
    
    with cd('~/fuelbench'):        
        # network configuration
        cmdline = "fuel network --env {id} network --download".format(id=id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
        
        buf = StringIO.StringIO(result)
        match = None
        
        for line in buf.readlines():
            match = re.search(r'^Network configuration .* downloaded to\s+(.+)', line)
            if match:
                break
            
        if not match:
            raise RemoteTaskError('Network configuration file not found')
        
        remote_path = match.group(1).strip()
        filelist = get(remote_path, workdir)        
        if len(filelist) != 1:
            raise RemoteTaskError('Unable to get {0}'.format(remote_path))
        
        local_path = filelist[0]
        network_cfg = utils.modify_yamlfile(local_path, setup_site_network, public_vip, floating_ranges, public_cidr, public_gateway, public_ranges)
        logger.debug('Saving %s: ', local_path)
        logger.debug(network_cfg)
        
        put(local_path, remote_path)
        
        cmdline = "fuel --env {id} network --upload".format(id=id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)

        # settings configuration
        cmdline = "fuel --env {id} settings --download".format(id=id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)
        
        buf = StringIO.StringIO(result)
        match = None
        
        for line in buf.readlines():
            match = re.search(r'^Settings configuration .* downloaded to\s+(.+)', line)
            if match:
                break
            
        if not match:
            raise RemoteTaskError('Settings configuration file not found')
        
        remote_path = match.group(1).strip()
        filelist = get(remote_path, workdir)        
        if len(filelist) != 1:
            raise RemoteTaskError('Unable to get {0}'.format(remote_path))
        
        local_path = filelist[0]
        settings_cfg = utils.modify_yamlfile(local_path, setup_site_settings, upstream_dns)
        logger.debug('Saving %s: ', local_path)
        logger.debug(settings_cfg)
        
        put(local_path, remote_path)
        
        cmdline = "fuel --env {id} settings --upload".format(id=id)
        logger.debug('Run: %s', cmdline)    
        result = run(cmdline)
        logger.debug('Result: %s', result)