forked from banzaicloud/cloudinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CCM-5210]: support for instance family endpoint
- Loading branch information
Utsav Krishnan
committed
Nov 14, 2021
1 parent
7049b45
commit a3c12ea
Showing
18 changed files
with
401 additions
and
7 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
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
33 changes: 33 additions & 0 deletions
33
internal/cloudinfo/providers/amazon/instancefamily_mapper.go
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,33 @@ | ||
// Copyright © 2021 Banzai Cloud | ||
// | ||
// 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 amazon | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// mapSeries get instance series associated with the instanceType | ||
func (e *Ec2Infoer) mapSeries(instanceType string) string { | ||
series := strings.Split(instanceType, ".") | ||
|
||
if len(series) != 2 { | ||
e.log.Warn("error parsing instance series from instanceType", map[string]interface{}{"instanceType": instanceType}) | ||
|
||
// return instanceType itself when there is a parsing error, to speedup debugging | ||
return instanceType | ||
} | ||
|
||
return series[0] | ||
} |
40 changes: 40 additions & 0 deletions
40
internal/cloudinfo/providers/amazon/instancefamily_mapper_test.go
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,40 @@ | ||
// Copyright © 2021 Banzai Cloud | ||
// | ||
// 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 amazon | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"logur.dev/logur" | ||
|
||
"github.com/banzaicloud/cloudinfo/internal/cloudinfo/cloudinfoadapter" | ||
) | ||
|
||
func TestAmazonInfoer_mapSeries(t *testing.T) { | ||
familySeriesMap := map[string]string{ | ||
"r5.large": "r5", | ||
"r5.metal": "r5", | ||
"r5d.24xlarge": "r5d", | ||
} | ||
|
||
ec2Infoer := Ec2Infoer{log: cloudinfoadapter.NewLogger(&logur.TestLogger{})} | ||
|
||
for family, series := range familySeriesMap { | ||
t.Run("test parsing "+family, func(t *testing.T) { | ||
assert.Equal(t, ec2Infoer.mapSeries(family), series, "unexpected series") | ||
}) | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
internal/cloudinfo/providers/azure/instancefamily_mapper_test.go
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,38 @@ | ||
// Copyright © 2021 Banzai Cloud | ||
// | ||
// 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 azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"logur.dev/logur" | ||
|
||
"github.com/banzaicloud/cloudinfo/internal/cloudinfo/cloudinfoadapter" | ||
) | ||
|
||
func TestAzureInfoer_mapSeries(t *testing.T) { | ||
familySeriesMap := map[string]string{ | ||
"standardDADSv5Family": "DADSv5", | ||
} | ||
|
||
azureInfoer := AzureInfoer{log: cloudinfoadapter.NewLogger(&logur.TestLogger{})} | ||
|
||
for family, series := range familySeriesMap { | ||
t.Run("test parsing "+family, func(t *testing.T) { | ||
assert.Equal(t, azureInfoer.mapSeries(family), series, "unexpected series") | ||
}) | ||
} | ||
} |
Oops, something went wrong.