Skip to content

Commit

Permalink
Feature: instance bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksibm committed Nov 9, 2021
1 parent 20b8865 commit 761edc4
Show file tree
Hide file tree
Showing 21 changed files with 492 additions and 10 deletions.
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 @@ -561,6 +579,18 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
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
97 changes: 93 additions & 4 deletions ibm/data_source_ibm_is_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
"gpu_count": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU count of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -148,7 +148,7 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
"gpu_manufacturer": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU manufacturer of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand All @@ -170,7 +170,7 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
"gpu_memory": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU memory of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -217,7 +217,7 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
"gpu_model": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU model of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand All @@ -236,6 +236,53 @@ func dataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"total_volume_bandwidth": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance storage volumes. An increase in this value will result in a corresponding decrease to total_network_bandwidth.",
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 @@ -573,6 +620,12 @@ 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 @@ -983,3 +1036,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
}
59 changes: 55 additions & 4 deletions ibm/data_source_ibm_is_instance_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
"gpu_count": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU count of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -151,7 +151,7 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
"gpu_manufacturer": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU manufacturer of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand All @@ -173,7 +173,7 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
"gpu_memory": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU memory of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand Down Expand Up @@ -220,7 +220,7 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
"gpu_model": {
Type: schema.TypeList,
Computed: true,
Description: "Collection of the instance profile's disks.",
Description: "GPU model of this profile",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Expand All @@ -239,6 +239,53 @@ func dataSourceIBMISInstanceProfiles() *schema.Resource {
},
},
},
"total_volume_bandwidth": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The amount of bandwidth (in megabits per second) allocated exclusively to instance storage volumes. An increase in this value will result in a corresponding decrease to total_network_bandwidth.",
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 @@ -570,6 +617,10 @@ func instanceProfilesList(d *schema.ResourceData, meta interface{}) error {
l["gpu_model"] = dataSourceInstanceProfileFlattenGPUModel(*profile.GpuModel)
}

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
13 changes: 13 additions & 0 deletions ibm/data_source_ibm_is_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func dataSourceIBMISInstanceTemplate() *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 @@ -307,6 +312,10 @@ func dataSourceIBMISInstanceTemplateRead(context context.Context, d *schema.Reso
d.Set("placement_target", placementTargetList)
}

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

if instance.PrimaryNetworkInterface != nil {
interfaceList := make([]map[string]interface{}, 0)
currentPrimNic := map[string]interface{}{}
Expand Down Expand Up @@ -528,6 +537,10 @@ func dataSourceIBMISInstanceTemplateRead(context context.Context, d *schema.Reso
d.Set(isInstanceTemplateNetworkInterfaces, interfacesList)
}

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

if instance.Image != nil {
imageInf := instance.Image
imageIdentity := imageInf.(*vpcv1.ImageIdentity)
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 @@ -642,6 +659,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
Loading

0 comments on commit 761edc4

Please sign in to comment.