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 8, 2021
1 parent 2af91d0 commit 6c5bbf6
Show file tree
Hide file tree
Showing 22 changed files with 486 additions and 3 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
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
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
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
2 changes: 1 addition & 1 deletion ibm/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func init() {
isImage = os.Getenv("IS_IMAGE")
if isImage == "" {
//isImage = "fc538f61-7dd6-4408-978c-c6b85b69fe76" // for classic infrastructure
isImage = "r006-13938c0a-89e4-4370-b59b-55cd1402562d" // for next gen infrastructure
isImage = "r134-63363662-a4ee-4ba4-a6c4-92e6c78c6b58" // for next gen infrastructure
fmt.Println("[INFO] Set the environment variable IS_IMAGE for testing ibm_is_instance, ibm_is_floating_ip else it is set to default value 'r006-ed3f775f-ad7e-4e37-ae62-7199b4988b00'")
}

Expand Down
Loading

0 comments on commit 6c5bbf6

Please sign in to comment.