Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

add regex for different volume size format #1416

Merged
merged 1 commit into from
Dec 17, 2018
Merged

Conversation

Madhu-1
Copy link
Member

@Madhu-1 Madhu-1 commented Dec 17, 2018

we should be able to create volume size with
different formats like KB, Kib, Mb, MiB etc

Fixes: #1398

    [root@dhcp43-209 build]# ./glustercli volume create size1 --size=20MB --replica=3 -v
    size1 Volume created successfully
    Volume ID:  b2693574-8489-4d4b-94ab-3564776d1cce
    
    [root@dhcp43-209 build]# ./glustercli volume create size2 --size=20MiB --replica=3 -v
    size2 Volume created successfully
    Volume ID:  b1153478-4912-4481-a047-8d67258ab08c
    
    [root@dhcp43-209 build]# ./glustercli volume create size3 --size=20M --replica=3 -v
    size3 Volume created successfully
    Volume ID:  8ac1c9a5-cc84-45ec-b382-eff17369d024
    
    [root@dhcp43-209 build]# ./glustercli volume create size35 --size=20 --replica=3 -v
    size35 Volume created successfully
    Volume ID:  560da74f-b7cf-466c-994c-0f03ba07bb24
    
    [root@dhcp43-209 build]# ./glustercli volume create size --size=21mb --replica=3 -v
    7size Volume created successfully
    Volume ID:  638d4108-bf2e-48e9-9d1d-982a34882586
    
    [root@dhcp43-209 build]# ./glustercli volume create sizes6 --size=20971520 --replica=3 -v
    sizes6 Volume created successfully
    Volume ID:  c4de7f7e-e4b4-46e6-80d1-92a9e060c4c0
    
    [root@dhcp43-209 build]# ./glustercli volume create size6 --size=20971520sadf --replica=3 -v
    Invalid Volume Size specified
    ```

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>

@Madhu-1
Copy link
Member Author

Madhu-1 commented Dec 17, 2018

@aravindavk PTAL

@@ -12,7 +12,7 @@ import (
)

var (
validSizeFormat = regexp.MustCompile(`^([0-9]+)([GMKT])?$`)
validSizeFormat = regexp.MustCompile(`^([0-9]+)?([kKmMgGtT])?[iI]?[bB]?$`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • first ? will make digit optional.
  • Space in between digit and number can be supported by adding \s* in between
  • sizeParts[2] will not have all suffix chars. Use this regex ^([0-9]+)\s*([kKmMgGtT]?[iI]?[bB]?)$

we should be able to create volume size with
different formats like KB, Kib, Mb, MiB etc

Fixes: gluster#1398

```
[root@dhcp43-209 build]# ./glustercli volume create size1 --size=20MB --replica=3 -v
size1 Volume created successfully
Volume ID:  b2693574-8489-4d4b-94ab-3564776d1cce

[root@dhcp43-209 build]# ./glustercli volume create size2 --size=20MiB --replica=3 -v
size2 Volume created successfully
Volume ID:  b1153478-4912-4481-a047-8d67258ab08c

[root@dhcp43-209 build]# ./glustercli volume create size3 --size=20M --replica=3 -v
size3 Volume created successfully
Volume ID:  8ac1c9a5-cc84-45ec-b382-eff17369d024

[root@dhcp43-209 build]# ./glustercli volume create size35 --size=20 --replica=3 -v
size35 Volume created successfully
Volume ID:  560da74f-b7cf-466c-994c-0f03ba07bb24

[root@dhcp43-209 build]# ./glustercli volume create size --size=21mb --replica=3 -v
7size Volume created successfully
Volume ID:  638d4108-bf2e-48e9-9d1d-982a34882586

[root@dhcp43-209 build]# ./glustercli volume create sizes6 --size=20971520 --replica=3 -v
sizes6 Volume created successfully
Volume ID:  c4de7f7e-e4b4-46e6-80d1-92a9e060c4c0

[root@dhcp43-209 build]# ./glustercli volume create size6 --size=20971520sadf --replica=3 -v
Invalid Volume Size specified
```

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
@Madhu-1
Copy link
Member Author

Madhu-1 commented Dec 17, 2018

@aravindavk PTAL

@@ -12,7 +12,7 @@ import (
)

var (
validSizeFormat = regexp.MustCompile(`^([0-9]+)([GMKT])?$`)
validSizeFormat = regexp.MustCompile(`^([0-9]+)\s*([kKmMgGtT]?[iI]?[bB]?)$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What're iI & bB for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to support units like MB or MiB , kb, kib

@atinmu atinmu merged commit c198e11 into gluster:master Dec 17, 2018
@ghost ghost removed the in progress label Dec 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants