Skip to content

Commit

Permalink
fix: Get all objects with json data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
amhn committed Sep 5, 2022
1 parent 70f615e commit 58c2a11
Show file tree
Hide file tree
Showing 89 changed files with 2,136 additions and 89 deletions.
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_circuits_circuit_terminations_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONCircuitsCircuitTerminationsListRead(d *schema.ResourceData, m
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Circuits.CircuitsCircuitTerminationsList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONCircuitsCircuitTerminationsList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_circuits_circuit_types_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONCircuitsCircuitTypesListRead(d *schema.ResourceData, m interf
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Circuits.CircuitsCircuitTypesList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONCircuitsCircuitTypesList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_circuits_circuits_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONCircuitsCircuitsListRead(d *schema.ResourceData, m interface{
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Circuits.CircuitsCircuitsList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONCircuitsCircuitsList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_circuits_provider_networks_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONCircuitsProviderNetworksListRead(d *schema.ResourceData, m in
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Circuits.CircuitsProviderNetworksList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONCircuitsProviderNetworksList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_circuits_providers_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONCircuitsProvidersListRead(d *schema.ResourceData, m interface
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Circuits.CircuitsProvidersList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONCircuitsProvidersList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_cables_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimCablesListRead(d *schema.ResourceData, m interface{}) err
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimCablesList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimCablesList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_console_port_templates_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimConsolePortTemplatesListRead(d *schema.ResourceData, m in
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimConsolePortTemplatesList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimConsolePortTemplatesList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_console_ports_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimConsolePortsListRead(d *schema.ResourceData, m interface{
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimConsolePortsList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimConsolePortsList")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimConsoleServerPortTemplatesListRead(d *schema.ResourceData
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimConsoleServerPortTemplatesList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimConsoleServerPortTemplatesList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_console_server_ports_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimConsoleServerPortsListRead(d *schema.ResourceData, m inte
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimConsoleServerPortsList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimConsoleServerPortsList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_device_bay_templates_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimDeviceBayTemplatesListRead(d *schema.ResourceData, m inte
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimDeviceBayTemplatesList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimDeviceBayTemplatesList")
Expand Down
25 changes: 24 additions & 1 deletion netbox/data_netbox_json_dcim_device_bays_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,30 @@ func dataNetboxJSONDcimDeviceBaysListRead(d *schema.ResourceData, m interface{})
return err
}

j, _ := json.Marshal(list.Payload.Results)
tmp := list.Payload.Results
resultLength := int64(len(tmp))
desiredLength := *list.Payload.Count
if limit > 0 && limit < desiredLength {
desiredLength = limit
}
if limit == 0 || resultLength < desiredLength {
limit = resultLength
}
offset := limit
params.Offset = &offset
for int64(len(tmp)) < desiredLength {
offset = int64(len(tmp))
if limit > desiredLength - offset {
limit = desiredLength - offset
}
list, err = client.Dcim.DcimDeviceBaysList(params, nil)
if err != nil {
return err
}
tmp = append(tmp, list.Payload.Results...)
}

j, _ := json.Marshal(tmp)

d.Set("json", string(j))
d.SetId("NetboxJSONDcimDeviceBaysList")
Expand Down
Loading

0 comments on commit 58c2a11

Please sign in to comment.