The transition to NetApp MS Azure AD B2C is complete. If you missed the pre-registration, you will be invited to register at next log in.
Please note that access to your NetApp data may take up to 1 hour.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Active IQ Unified Manager Discussions

WFA - Function to get Volume name Prefix

sheelnidhig

Hello All,

I am trying to write a Function to get the volume name Prefix pattern from the Storage controller name.

the Storage controller name could be :

     cgtestx123.iceage.com or

     mfdevx234.sid.iceage.com or

    

The volume Prefix that we are expecting is :

     if the Storage is cgtestx123.abc.com  volume name prefix should be => test123v[3 digit number]

     if the Storage is mfdevx234.abc.com volume name prefix should be => dev234v[3 digit number]

So, if i would have to explain it, i can say that i need to take from 3rd character till character "x" and the numeric's before the domain name ".sid..... or .iceage...."

The function i am trying to write is not helping:

def getVolumeprefix (storagecontroller)

{

          java.util.regex.Pattern RESOLVE_PATTERN =  java.util.regex.Pattern.compile("(^.*?)(\\d+)(.\.*?)");

          java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);

   

          String number = matcher.group(2);

          String site = storagecontroller.substring(2,5);

          String volname = site + number + "v";

          return volname;

}

can someone please help me in fixing this pattern function.

,Sheel

1 ACCEPTED SOLUTION

dhruvd

Hi Sheel,

The java.util.regex.Pattern.compile does not handle dot('\.') well. The dot needs to be given as \p{Punct}

I have modified the function and this works fine in my environment:

def getVolumeprefix (storagecontroller)

{

          java.util.regex.Pattern RESOLVE_PATTERN =  java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");

          java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);

          if (matcher.matches())

          {

          String number = matcher.group(2);

          String site = matcher.group(1);

          String volname = site + number + "v";

          return volname;

          }

          throwException('Input not in correct format')

}

Hope this helps.

-Dhruv

View solution in original post

3 REPLIES 3

dhruvd

Hi Sheel,

The java.util.regex.Pattern.compile does not handle dot('\.') well. The dot needs to be given as \p{Punct}

I have modified the function and this works fine in my environment:

def getVolumeprefix (storagecontroller)

{

          java.util.regex.Pattern RESOLVE_PATTERN =  java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");

          java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);

          if (matcher.matches())

          {

          String number = matcher.group(2);

          String site = matcher.group(1);

          String volname = site + number + "v";

          return volname;

          }

          throwException('Input not in correct format')

}

Hope this helps.

-Dhruv

View solution in original post

sheelnidhig

Thanks Dhruv,

it worked for me, i just added an elese condition as well, if i am selecting a vFiler, which generally does not have a domain name added to it:

def getVolumeprefix (storagecontroller)

{

          java.util.regex.Pattern RESOLVE_PATTERN =  java.util.regex.Pattern.compile("^..(.+)x(\\d+)(\\p{Punct}.+)");

          java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);

          if (matcher.matches())

          {

                    String number = matcher.group(2);

                    String site = matcher.group(1);

                    String volname = site + number + "v";

                    return volname;

          } else {

                    String part = storagecontroller.substring(2,storagecontroller.length());

                    String site = part.substring(0, part.length()-4);

                    String code = part.substring(part.length()-3, part.length());

                    String volname = site + code + "v";

                    return volname;

          }

}

Dont have any knowledge about java. so i have to do copy and paste 🙂

dhruvd

Thats Great.

In case you want the function to work for both storage controllers and vfilers, the following will do. It will even throw an exception if the input format is not as expected.

def getVolumeprefix (storagecontroller)

{

          java.util.regex.Pattern RESOLVE_PATTERN =  java.util.regex.Pattern.compile("^..(.+)x(\\d{3}).*");

          java.util.regex.Matcher matcher = RESOLVE_PATTERN.matcher(storagecontroller);

          if (matcher.matches())

          {

          String number = matcher.group(2);

          String site = matcher.group(1);

          String volname = site + number + "v";

          return volname;

          }

          throwException('Input not in correct format')

}

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public