Skip to content

Commit

Permalink
Feature: instance bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksibm committed Sep 28, 2021
1 parent cf461bb commit 9857245
Show file tree
Hide file tree
Showing 20 changed files with 361 additions and 3 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/IBM/container-registry-go-sdk v0.0.13
github.com/IBM/eventstreams-go-sdk v1.2.0
github.com/IBM/go-sdk-core/v4 v4.10.0
github.com/IBM/go-sdk-core/v5 v5.6.3
github.com/IBM/go-sdk-core/v5 v5.6.5
github.com/IBM/ibm-cos-sdk-go v1.7.0
github.com/IBM/ibm-cos-sdk-go-config v1.2.0
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20210723145459-a232c3f3ac91
Expand All @@ -24,7 +24,7 @@ require (
github.com/IBM/scc-go-sdk v1.2.0
github.com/IBM/schematics-go-sdk v0.0.2
github.com/IBM/secrets-manager-go-sdk v0.1.19
github.com/IBM/vpc-go-sdk v0.10.0
github.com/IBM/vpc-go-sdk v0.11.0
github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/Shopify/sarama v1.29.1
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ github.com/IBM/go-sdk-core v1.1.0/go.mod h1:2pcx9YWsIsZ3I7kH+1amiAkXvLTZtAq9kbxs
github.com/IBM/go-sdk-core/v3 v3.0.0/go.mod h1:JI5NS2+iCoY/D8Oq3JNEZNA7qO42agu6fnaUmDsRcJA=
github.com/IBM/go-sdk-core/v3 v3.2.4 h1:WKYJYYKlZnw1y/gM+Qbf5EQVAL9xaoD54+ooJZz/iBQ=
github.com/IBM/go-sdk-core/v3 v3.2.4/go.mod h1:lk9eOzNbNltPf3CBpcg1Ewkhw4qC3u2QCCKDRsUA2M0=
github.com/IBM/go-sdk-core/v4 v4.5.1/go.mod h1:lTUXbqIX6/aAbSCkP6q59+dyFsTwZAc0ewRS2vJWVbg=
github.com/IBM/go-sdk-core/v4 v4.8.1/go.mod h1:GECJ/p0r9Hs0XcOnCiGjZrt6M/rQc+gW8YkCsGJ+j5U=
github.com/IBM/go-sdk-core/v4 v4.9.0/go.mod h1:DbQ+3pFoIjxGGTEiA9zQ2V0cemMNmFMkLBBnR729HKg=
github.com/IBM/go-sdk-core/v4 v4.10.0 h1:aLoKusSFVsxMJeKHf8csj9tBWt4Y50kVvfxoKh6scN0=
Expand All @@ -74,6 +75,8 @@ github.com/IBM/go-sdk-core/v5 v5.4.5/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723
github.com/IBM/go-sdk-core/v5 v5.5.1/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723y8GsfLV8e0=
github.com/IBM/go-sdk-core/v5 v5.6.3 h1:xj44tzfBnjGJXKthMeaIn9wcYH+z4dXTuhntsBp+NdQ=
github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/go-sdk-core/v5 v5.6.5 h1:zXlt5x/udqZTD617SKUQzPDON4x5y0+22vNxsdCGYpg=
github.com/IBM/go-sdk-core/v5 v5.6.5/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/ibm-cos-sdk-go v1.3.1/go.mod h1:YLBAYobEA8bD27P7xpMwSQeNQu6W3DNBtBComXrRzRY=
github.com/IBM/ibm-cos-sdk-go v1.7.0 h1:3DZULY/D5WzjlIm+Iaj6h0surEjQs65EZk1YAe8+rj0=
github.com/IBM/ibm-cos-sdk-go v1.7.0/go.mod h1:Oi8AC5WNDhmUJgbo1GL2FtBdo0nRgbzE/1HmCL1SERU=
Expand All @@ -97,6 +100,8 @@ github.com/IBM/secrets-manager-go-sdk v0.1.19 h1:0GPs5EoTaWNsjo4QPj64GNxlWfN8VHJ
github.com/IBM/secrets-manager-go-sdk v0.1.19/go.mod h1:eO3dBhzPrHkkt+yPex/jB2xD6qHZxBko+Aw+0tfqHeA=
github.com/IBM/vpc-go-sdk v0.10.0 h1:QAUN6hziV9+dbtsHrk8KuSr/kIW8qGBNlCsZ/ghgBZ4=
github.com/IBM/vpc-go-sdk v0.10.0/go.mod h1:Y1oXX7o+UJIKzMnTt1t74e2weUzVqb2XZ1/INV/D/fs=
github.com/IBM/vpc-go-sdk v0.11.0 h1:OstkhjsBkSTejo/wxWziOkVVRw8Hm1kCFrcvtTM3nAE=
github.com/IBM/vpc-go-sdk v0.11.0/go.mod h1:B3Pgkwb0tQqTeIojR1MFLp96qW7cKnWyJ74jbAJgdbk=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
Expand Down
30 changes: 30 additions & 0 deletions ibm/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ func dataSourceIBMISInstance() *schema.Resource {
Description: "Profile info",
},

isInstanceTotalVolumeBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance storage volumes",
},

isInstanceBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The total bandwidth (in megabits per second) shared across the instance's network interfaces and storage volumes",
},

isInstanceTotalNetworkBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance network interfaces.",
},

isInstanceTags: {
Type: schema.TypeSet,
Computed: true,
Expand Down Expand Up @@ -558,6 +576,18 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
gpuList := make([]map[string]interface{}, 0)
d.Set(isInstanceGpu, gpuList)

if instance.Bandwidth != nil {
d.Set(isInstanceBandwidth, int(*instance.Bandwidth))
}

if instance.TotalNetworkBandwidth != nil {
d.Set(isInstanceTotalNetworkBandwidth, int(*instance.TotalNetworkBandwidth))
}

if instance.TotalVolumeBandwidth != nil {
d.Set(isInstanceTotalVolumeBandwidth, int(*instance.TotalVolumeBandwidth))
}

if instance.Disks != nil {
d.Set(isInstanceDisks, dataSourceInstanceFlattenDisks(instance.Disks))
}
Expand Down
90 changes: 90 additions & 0 deletions ibm/data_source_ibm_is_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,52 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"total_volume_bandwidth": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The value for this profile field.",
},
"default": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The default value for this profile field.",
},
"max": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The maximum value for this profile field.",
},
"min": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The minimum value for this profile field.",
},
"step": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The increment step value for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The permitted values for this profile field.",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
"disks": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -411,6 +457,14 @@ func instanceProfileGet(d *schema.ResourceData, meta interface{}, name string) e
return err
}
}

if profile.TotalVolumeBandwidth != nil {
err = d.Set("total_volume_bandwidth", dataSourceInstanceProfileFlattenTotalVolumeBandwidth(*profile.TotalVolumeBandwidth.(*vpcv1.InstanceProfileVolumeBandwidth)))
if err != nil {
return err
}
}

if profile.Disks != nil {
err = d.Set("disks", dataSourceInstanceProfileFlattenDisks(profile.Disks))
if err != nil {
Expand Down Expand Up @@ -707,3 +761,39 @@ func dataSourceInstanceProfileDisksSupportedInterfaceTypesToMap(supportedInterfa

return supportedInterfaceTypesMap
}

func dataSourceInstanceProfileFlattenTotalVolumeBandwidth(result vpcv1.InstanceProfileVolumeBandwidth) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceInstanceProfileTotalVolumeBandwidthToMap(result)
finalList = append(finalList, finalMap)

return finalList
}

func dataSourceInstanceProfileTotalVolumeBandwidthToMap(bandwidthItem vpcv1.InstanceProfileVolumeBandwidth) (bandwidthMap map[string]interface{}) {
bandwidthMap = map[string]interface{}{}

if bandwidthItem.Type != nil {
bandwidthMap["type"] = bandwidthItem.Type
}
if bandwidthItem.Value != nil {
bandwidthMap["value"] = bandwidthItem.Value
}
if bandwidthItem.Default != nil {
bandwidthMap["default"] = bandwidthItem.Default
}
if bandwidthItem.Max != nil {
bandwidthMap["max"] = bandwidthItem.Max
}
if bandwidthItem.Min != nil {
bandwidthMap["min"] = bandwidthItem.Min
}
if bandwidthItem.Step != nil {
bandwidthMap["step"] = bandwidthItem.Step
}
if bandwidthItem.Values != nil {
bandwidthMap["values"] = bandwidthItem.Values
}

return bandwidthMap
}
51 changes: 51 additions & 0 deletions ibm/data_source_ibm_is_instance_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,52 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
},
},
},
"total_volume_bandwidth": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The value for this profile field.",
},
"default": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The default value for this profile field.",
},
"max": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The maximum value for this profile field.",
},
"min": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The minimum value for this profile field.",
},
"step": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The increment step value for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The permitted values for this profile field.",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
"disks": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -415,6 +461,11 @@ func instanceProfilesList(d *schema.ResourceData, meta interface{}) error {
bandwidthList = append(bandwidthList, bandwidthMap)
l["bandwidth"] = bandwidthList
}

if profile.TotalVolumeBandwidth != nil {
l["total_volume_bandwidth"] = dataSourceInstanceProfileFlattenTotalVolumeBandwidth(*profile.TotalVolumeBandwidth.(*vpcv1.InstanceProfileVolumeBandwidth))
}

if profile.Disks != nil {
disksList := []map[string]interface{}{}
for _, disksItem := range profile.Disks {
Expand Down
9 changes: 9 additions & 0 deletions ibm/data_source_ibm_is_instance_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func dataSourceIBMISInstanceTemplates() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
isInstanceTotalVolumeBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance storage volumes",
},
isInstanceTemplateVolumeAttachments: {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -344,6 +349,10 @@ func dataSourceIBMISInstanceTemplatesRead(d *schema.ResourceData, meta interface
template["placement_target"] = placementTargetList
}

if instance.TotalVolumeBandwidth != nil {
template[isInstanceTotalVolumeBandwidth] = int(*instance.TotalVolumeBandwidth)
}

if instance.PrimaryNetworkInterface != nil {
interfaceList := make([]map[string]interface{}, 0)
currentPrimNic := map[string]interface{}{}
Expand Down
28 changes: 28 additions & 0 deletions ibm/data_source_ibm_is_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ func dataSourceIBMISInstances() *schema.Resource {
Computed: true,
Description: "Instance Profile",
},
isInstanceTotalVolumeBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance storage volumes",
},

isInstanceBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The total bandwidth (in megabits per second) shared across the instance's network interfaces and storage volumes",
},

isInstanceTotalNetworkBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance network interfaces.",
},
"vcpu": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -611,6 +628,17 @@ func instancesList(d *schema.ResourceData, meta interface{}) error {
placementTargetMap := resourceIbmIsInstanceInstancePlacementToMap(*instance.PlacementTarget.(*vpcv1.InstancePlacementTarget))
l["placement_target"] = []map[string]interface{}{placementTargetMap}
}
if instance.Bandwidth != nil {
l[isInstanceBandwidth] = int(*instance.Bandwidth)
}

if instance.TotalNetworkBandwidth != nil {
l[isInstanceTotalNetworkBandwidth] = int(*instance.TotalNetworkBandwidth)
}

if instance.TotalVolumeBandwidth != nil {
l[isInstanceTotalVolumeBandwidth] = int(*instance.TotalVolumeBandwidth)
}

if instance.BootVolumeAttachment != nil {
bootVolList := make([]map[string]interface{}, 0)
Expand Down
7 changes: 7 additions & 0 deletions ibm/data_source_ibm_is_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func dataSourceIBMISVolume() *schema.Resource {
Description: "Zone name",
},

isVolumeBandwidth: {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum bandwidth (in megabits per second) for the volume",
},

isVolumeResourceGroup: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -201,6 +207,7 @@ func volumeGet(d *schema.ResourceData, meta interface{}, name string) error {
}
for _, vol := range allrecs {
d.SetId(*vol.ID)
d.Set(isVolumeBandwidth, int(*vol.Bandwidth))
d.Set(isVolumeName, *vol.Name)
d.Set(isVolumeProfileName, *vol.Profile.Name)
d.Set(isVolumeZone, *vol.Zone.Name)
Expand Down
Loading

0 comments on commit 9857245

Please sign in to comment.