-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from ystia/feature/google-block-storage
Feature/google block storage
- Loading branch information
Showing
24 changed files
with
915 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sizeutil | ||
|
||
import ( | ||
"github.com/dustin/go-humanize" | ||
"github.com/pkg/errors" | ||
"github.com/ystia/yorc/helper/mathutil" | ||
"strconv" | ||
) | ||
|
||
// ConvertToGB allows to convert a MB size as "42" or a human readable size as "42MB" or "42 KB" into GB | ||
func ConvertToGB(size string) (int, error) { | ||
// Default size unit is MB | ||
mSize, err := strconv.Atoi(size) | ||
// Not an int value, so maybe a human readable size: we try to retrieve bytes | ||
if err != nil { | ||
var bsize uint64 | ||
bsize, err = humanize.ParseBytes(size) | ||
if err != nil { | ||
return 0, errors.Errorf("Can't convert size to bytes value: %v", err) | ||
} | ||
gSize := float64(bsize) / humanize.GByte | ||
gSize = mathutil.Round(gSize, 0, 0) | ||
return int(gSize), nil | ||
} | ||
|
||
gSize := float64(mSize) / 1000 | ||
gSize = mathutil.Round(gSize, 0, 0) | ||
return int(gSize), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2018 Bull S.A.S. Atos Technologies - Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois, France. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sizeutil | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestConvertToGB(t *testing.T) { | ||
var testData = []struct { | ||
test string | ||
inputSize string | ||
expectedSize int | ||
expectedError bool | ||
}{ | ||
{"volume1", "1", 1, false}, | ||
{"volume10000000", "100", 1, false}, | ||
{"volume10000000", "1500 M", 2, false}, | ||
{"volume1GB", "1GB", 1, false}, | ||
{"volume1GBS", "1 GB", 1, false}, | ||
{"olume1GiB", "1 GiB", 2, false}, | ||
{"volume2GIB", "2 GIB", 3, false}, | ||
{"volume1TB", "1 tb", 1000, false}, | ||
{"volume1TiB", "1 TiB", 1100, false}, | ||
{"error", "1 deca", 0, true}, | ||
} | ||
for _, tt := range testData { | ||
s, err := ConvertToGB(tt.inputSize) | ||
if !tt.expectedError { | ||
assert.Nil(t, err) | ||
assert.Equal(t, tt.expectedSize, s) | ||
} else { | ||
assert.Error(t, err, "Expected an error") | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.