Forum Stats

  • 3,815,708 Users
  • 2,259,070 Discussions
  • 7,893,213 Comments

Discussions

zfs cli scripting - how to change the properties of all LUN's

User_6TWVP
User_6TWVP Member Posts: 2 Blue Ribbon
edited Apr 13, 2018 4:53PM in ZFS Storage Appliance

we want to create a simple cli script for changing the targetgroup of all available LUN's. for now we don't succeed. Can someone tell me how to change this script?

-------------------------

script

function getPools()

    {

            run('cd /');

            run ('status');

            run ('storage');

            pools=list();

            for (i=0; i < pools.length; i++)

            {

                    var pool=pools[i];

                    getPoolStat(pool);

                    getProjects(pool);

            }

            run('done');

    }

function getPoolStat(pool)

    {

            run('cd /');

            run ('status');

            run ('storage');

            run ('select ' + pool);

            printf("%-10s %-10s \n","Poolname: ",pool);

            run('done');

    }

function getProjects(pool)

    {

            run('cd /');

            run('shares');

            run('set pool=' + pool);

            projects=list();

            for (a=0; a < projects.length; a++)

            {

                var project = projects[a];

                getLuns(project);

            }

      //      run('done');

    }

function getLuns(project)

    {

      run('select ' + project);

      printf("%-10s %-10s \n","Projectname: ",project);

      lns=run('list lun');

            for (y=0; y < lns.length; y++)

            {

                   var lun = lns[y];

                   run ('select ' + lun);

                   printf("%-10s %-10s \n","LUN : ",lun);

                   //run ('set targetgroup="PCA"');

                   //run ('commit');

                  run('done');

             }

      run('done');  // exit selected project

     }

getPools();

---------------------------------------------

Answers

  • Nik
    Nik Blocked Member Posts: 2,879 Bronze Crown
    edited Apr 13, 2018 8:02AM

    Hi.

    What problem you have with script ?  It got error or other problem ?

    What mean  available for LUN ? Is it unmapped LUN ? 

    Or you need change targetgroup for ALL Luns ?

    Regards,

      Nik

  • User_6TWVP
    User_6TWVP Member Posts: 2 Blue Ribbon
    edited Apr 13, 2018 8:42AM

    it was supposed to change all LUN's but in the mean while i found the solution! i can now execute the script successful!

  • Nik
    Nik Blocked Member Posts: 2,879 Bronze Crown
    edited Apr 13, 2018 4:53PM

    Hi.

    Example that can work :

    scriptfunction getProjects()    {            run('cd /');            run('shares');            projects=list();            for (a=0; a < projects.length; a++)            {                printf("%-10s %-10s \n","Share: ",projects[a]);                getLuns(projects[a]);            }    }function getLuns(project)    {      run('select ' + project);      lns=list();            for (y=0; y < lns.length; y++)            {                  printf("%-10s %-10s \n","LUN : ",lns[y]);                run('select ' + lns[y]);                       try  { props=get('volsize');                  // printf("%-10s %-10s \n","props : ",props);                  run ('set targetgroup="PCA"');                  run ('commit');                  }                  catch (err) { printf("%-10s \n","not vol ");                  }                                 run('done')            }      run('done');  // exit selected project    }getProjects();.

    Regards,

      Nik