n8n-nodes-ionos
Version:
n8n nodes for IONOS DNS, Domain, SSL/Certificate management, Cloud AI, Cloud Infrastructure, Container Registry, Database as a Service, CDN, VPN Gateway, Activity Log, Billing, Logging, Monitoring, Object Storage Management, Network File Storage, Identity
1,179 lines (1,178 loc) • 61.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IonosCloudLoadBalancing = void 0;
const baseUrl = 'https://api.ionos.com/cloudapi/v6';
class IonosCloudLoadBalancing {
description = {
displayName: 'IONOS Cloud Load Balancing',
name: 'ionosCloudLoadBalancing',
icon: 'file:ionos.svg',
group: ['transform'],
version: 1,
subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}',
description: 'Manage IONOS Cloud Load Balancers (Classic, Network, Application, Target Groups). Developped with Love by Ascenzia (ascenzia.fr)',
defaults: {
name: 'IONOS Cloud Load Balancing',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'ionosCloud',
required: true,
},
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'Load Balancer',
value: 'loadBalancer',
description: 'Manage classic Load Balancers',
},
{
name: 'Network Load Balancer',
value: 'networkLoadBalancer',
description: 'Manage Network Load Balancers (Layer 4)',
},
{
name: 'Application Load Balancer',
value: 'applicationLoadBalancer',
description: 'Manage Application Load Balancers (Layer 7)',
},
{
name: 'Target Group',
value: 'targetGroup',
description: 'Manage Target Groups for load balancers',
},
{
name: 'Forwarding Rule',
value: 'forwardingRule',
description: 'Manage forwarding rules for load balancers',
},
],
default: 'loadBalancer',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['loadBalancer'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a load balancer',
action: 'Create a load balancer',
},
{
name: 'Get',
value: 'get',
description: 'Get a load balancer',
action: 'Get a load balancer',
},
{
name: 'Get Many',
value: 'getMany',
description: 'Get many load balancers',
action: 'Get many load balancers',
},
{
name: 'Update',
value: 'update',
description: 'Update a load balancer',
action: 'Update a load balancer',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a load balancer',
action: 'Delete a load balancer',
},
{
name: 'Attach NIC',
value: 'attachNic',
description: 'Attach a NIC to the load balancer',
action: 'Attach a NIC',
},
{
name: 'Detach NIC',
value: 'detachNic',
description: 'Detach a NIC from the load balancer',
action: 'Detach a NIC',
},
{
name: 'List NICs',
value: 'listNics',
description: 'List NICs attached to the load balancer',
action: 'List NICs',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['networkLoadBalancer'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a network load balancer',
action: 'Create a network load balancer',
},
{
name: 'Get',
value: 'get',
description: 'Get a network load balancer',
action: 'Get a network load balancer',
},
{
name: 'Get Many',
value: 'getMany',
description: 'Get many network load balancers',
action: 'Get many network load balancers',
},
{
name: 'Update',
value: 'update',
description: 'Update a network load balancer',
action: 'Update a network load balancer',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a network load balancer',
action: 'Delete a network load balancer',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create an application load balancer',
action: 'Create an application load balancer',
},
{
name: 'Get',
value: 'get',
description: 'Get an application load balancer',
action: 'Get an application load balancer',
},
{
name: 'Get Many',
value: 'getMany',
description: 'Get many application load balancers',
action: 'Get many application load balancers',
},
{
name: 'Update',
value: 'update',
description: 'Update an application load balancer',
action: 'Update an application load balancer',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete an application load balancer',
action: 'Delete an application load balancer',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['targetGroup'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a target group',
action: 'Create a target group',
},
{
name: 'Get',
value: 'get',
description: 'Get a target group',
action: 'Get a target group',
},
{
name: 'Get Many',
value: 'getMany',
description: 'Get many target groups',
action: 'Get many target groups',
},
{
name: 'Update',
value: 'update',
description: 'Update a target group',
action: 'Update a target group',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a target group',
action: 'Delete a target group',
},
],
default: 'create',
},
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a forwarding rule',
action: 'Create a forwarding rule',
},
{
name: 'Get',
value: 'get',
description: 'Get a forwarding rule',
action: 'Get a forwarding rule',
},
{
name: 'Get Many',
value: 'getMany',
description: 'Get many forwarding rules',
action: 'Get many forwarding rules',
},
{
name: 'Update',
value: 'update',
description: 'Update a forwarding rule',
action: 'Update a forwarding rule',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a forwarding rule',
action: 'Delete a forwarding rule',
},
],
default: 'create',
},
{
displayName: 'Datacenter ID',
name: 'datacenterId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['loadBalancer', 'networkLoadBalancer', 'applicationLoadBalancer', 'forwardingRule'],
},
},
default: '',
description: 'The unique ID of the datacenter',
},
{
displayName: 'Load Balancer Type',
name: 'loadBalancerType',
type: 'options',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
},
},
options: [
{
name: 'Network Load Balancer',
value: 'network',
},
{
name: 'Application Load Balancer',
value: 'application',
},
],
default: 'network',
description: 'The type of load balancer for the forwarding rule',
},
{
displayName: 'Load Balancer ID',
name: 'loadBalancerId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['loadBalancer'],
operation: ['get', 'update', 'delete', 'attachNic', 'detachNic', 'listNics'],
},
},
default: '',
description: 'The unique ID of the load balancer',
},
{
displayName: 'Network Load Balancer ID',
name: 'networkLoadBalancerId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['networkLoadBalancer', 'forwardingRule'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The unique ID of the network load balancer',
},
{
displayName: 'Network Load Balancer ID',
name: 'networkLoadBalancerId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
loadBalancerType: ['network'],
operation: ['create', 'getMany'],
},
},
default: '',
description: 'The unique ID of the network load balancer',
},
{
displayName: 'Application Load Balancer ID',
name: 'applicationLoadBalancerId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The unique ID of the application load balancer',
},
{
displayName: 'Application Load Balancer ID',
name: 'applicationLoadBalancerId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
loadBalancerType: ['application'],
operation: ['create', 'getMany'],
},
},
default: '',
description: 'The unique ID of the application load balancer',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['loadBalancer', 'networkLoadBalancer', 'applicationLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'The name of the load balancer',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['loadBalancer'],
operation: ['create', 'update'],
},
},
options: [
{
displayName: 'DHCP',
name: 'dhcp',
type: 'boolean',
default: true,
description: 'Whether the load balancer uses DHCP',
},
{
displayName: 'IP',
name: 'ip',
type: 'string',
default: '',
description: 'The IP address of the load balancer',
},
],
},
{
displayName: 'Listener LAN',
name: 'listenerLan',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['networkLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'The LAN ID for the listener',
},
{
displayName: 'Target LAN',
name: 'targetLan',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['networkLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'The LAN ID for the targets',
},
{
displayName: 'IPs',
name: 'ips',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['networkLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'Comma-separated list of IPs for the load balancer',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['networkLoadBalancer'],
operation: ['create', 'update'],
},
},
options: [
{
displayName: 'LB Private IPs',
name: 'lbPrivateIps',
type: 'string',
default: '',
description: 'Comma-separated list of private IPs',
},
],
},
{
displayName: 'Listener LAN',
name: 'listenerLan',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'The LAN ID for the listener',
},
{
displayName: 'Target LAN',
name: 'targetLan',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'The LAN ID for the targets',
},
{
displayName: 'IPs',
name: 'ips',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
operation: ['create'],
},
},
default: '',
description: 'Comma-separated list of IPs for the load balancer',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['applicationLoadBalancer'],
operation: ['create', 'update'],
},
},
options: [
{
displayName: 'LB Private IPs',
name: 'lbPrivateIps',
type: 'string',
default: '',
description: 'Comma-separated list of private IPs',
},
],
},
{
displayName: 'NIC ID',
name: 'nicId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['loadBalancer'],
operation: ['attachNic', 'detachNic'],
},
},
default: '',
description: 'The ID of the NIC to attach/detach',
},
{
displayName: 'Target Group ID',
name: 'targetGroupId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The unique ID of the target group',
},
{
displayName: 'Name',
name: 'targetGroupName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['create'],
},
},
default: '',
description: 'The name of the target group',
},
{
displayName: 'Algorithm',
name: 'algorithm',
type: 'options',
required: true,
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['create'],
},
},
options: [
{
name: 'Round Robin',
value: 'ROUND_ROBIN',
},
{
name: 'Least Connection',
value: 'LEAST_CONNECTION',
},
{
name: 'Random',
value: 'RANDOM',
},
{
name: 'Source IP',
value: 'SOURCE_IP',
},
],
default: 'ROUND_ROBIN',
description: 'The load balancing algorithm',
},
{
displayName: 'Protocol',
name: 'protocol',
type: 'options',
required: true,
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['create'],
},
},
options: [
{
name: 'HTTP',
value: 'HTTP',
},
{
name: 'HTTPS',
value: 'HTTPS',
},
],
default: 'HTTP',
description: 'The protocol for the target group',
},
{
displayName: 'Targets',
name: 'targets',
type: 'json',
required: true,
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['create'],
},
},
default: '[{"ip":"10.0.0.1","port":80,"weight":100,"healthCheckEnabled":true,"maintenanceEnabled":false}]',
description: 'Array of targets with ip, port, weight, healthCheckEnabled, and maintenanceEnabled properties',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['targetGroup'],
operation: ['create', 'update'],
},
},
options: [
{
displayName: 'Health Check',
name: 'healthCheck',
type: 'json',
default: '{"checkTimeout":2000,"checkInterval":10000,"retries":3}',
description: 'Health check configuration with checkTimeout, checkInterval, and retries',
},
{
displayName: 'HTTP Health Check',
name: 'httpHealthCheck',
type: 'json',
default: '{"path":"/","method":"GET","matchType":"STATUS_CODE","response":"200"}',
description: 'HTTP health check configuration',
},
],
},
{
displayName: 'Forwarding Rule ID',
name: 'forwardingRuleId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['get', 'update', 'delete'],
},
},
default: '',
description: 'The unique ID of the forwarding rule',
},
{
displayName: 'Name',
name: 'forwardingRuleName',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['create'],
},
},
default: '',
description: 'The name of the forwarding rule',
},
{
displayName: 'Protocol',
name: 'protocol',
type: 'options',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['create'],
},
},
options: [
{
name: 'TCP',
value: 'TCP',
},
{
name: 'UDP',
value: 'UDP',
},
{
name: 'HTTP',
value: 'HTTP',
},
{
name: 'HTTPS',
value: 'HTTPS',
},
],
default: 'TCP',
description: 'The protocol for the forwarding rule',
},
{
displayName: 'Listener IP',
name: 'listenerIp',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['create'],
},
},
default: '',
description: 'The IP address on which the load balancer listens',
},
{
displayName: 'Listener Port',
name: 'listenerPort',
type: 'number',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['create'],
},
},
default: 80,
description: 'The port on which the load balancer listens',
},
{
displayName: 'Targets',
name: 'targets',
type: 'json',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
loadBalancerType: ['network'],
operation: ['create'],
},
},
default: '[{"ip":"10.0.0.1","port":8080,"weight":100,"healthCheckEnabled":true}]',
description: 'Array of targets with ip, port, weight, and healthCheckEnabled properties',
},
{
displayName: 'Target Group ID',
name: 'targetGroupId',
type: 'string',
required: true,
displayOptions: {
show: {
resource: ['forwardingRule'],
loadBalancerType: ['application'],
operation: ['create'],
},
},
default: '',
description: 'The ID of the target group',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['forwardingRule'],
operation: ['create', 'update'],
},
},
options: [
{
displayName: 'Health Check',
name: 'healthCheck',
type: 'json',
default: '{"clientTimeout":50000,"connectTimeout":5000,"targetTimeout":50000,"retries":3}',
description: 'Health check configuration (for Network LB)',
},
{
displayName: 'Server Certificates',
name: 'serverCertificates',
type: 'string',
default: '',
description: 'Comma-separated list of certificate IDs (for Application LB HTTPS)',
},
{
displayName: 'HTTP Rules',
name: 'httpRules',
type: 'json',
default: '[]',
description: 'Array of HTTP routing rules (for Application LB)',
},
],
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: ['getMany', 'listNics'],
},
},
default: false,
description: 'Whether to return all results or only up to a given limit',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: ['getMany', 'listNics'],
returnAll: [false],
},
},
typeOptions: {
minValue: 1,
maxValue: 1000,
},
default: 50,
description: 'Max number of results to return',
},
],
};
async execute() {
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
for (let i = 0; i < items.length; i++) {
try {
let responseData = {};
if (resource === 'loadBalancer') {
const datacenterId = this.getNodeParameter('datacenterId', i);
if (operation === 'create') {
const name = this.getNodeParameter('name', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const body = {
properties: {
name,
...(additionalFields.dhcp !== undefined && { dhcp: additionalFields.dhcp }),
...(additionalFields.ip && { ip: additionalFields.ip }),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'POST',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'get') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}`,
});
}
else if (operation === 'getMany') {
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const qs = {
depth: 1,
};
if (!returnAll) {
qs.limit = limit;
}
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers`,
qs,
});
responseData = responseData.items;
}
else if (operation === 'update') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const body = {
properties: {
...(additionalFields.dhcp !== undefined && { dhcp: additionalFields.dhcp }),
...(additionalFields.ip && { ip: additionalFields.ip }),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'PATCH',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}`,
body,
headers: { 'Content-Type': 'application/vnd.profitbricks.partial-properties+json' },
});
}
else if (operation === 'delete') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'DELETE',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}`,
});
responseData = { success: true };
}
else if (operation === 'attachNic') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
const nicId = this.getNodeParameter('nicId', i);
const body = {
id: nicId,
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'POST',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}/balancednics`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'detachNic') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
const nicId = this.getNodeParameter('nicId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'DELETE',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}/balancednics/${nicId}`,
});
responseData = { success: true };
}
else if (operation === 'listNics') {
const loadBalancerId = this.getNodeParameter('loadBalancerId', i);
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const qs = {
depth: 1,
};
if (!returnAll) {
qs.limit = limit;
}
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/loadbalancers/${loadBalancerId}/balancednics`,
qs,
});
responseData = responseData.items;
}
}
else if (resource === 'networkLoadBalancer') {
const datacenterId = this.getNodeParameter('datacenterId', i);
if (operation === 'create') {
const name = this.getNodeParameter('name', i);
const listenerLan = this.getNodeParameter('listenerLan', i);
const targetLan = this.getNodeParameter('targetLan', i);
const ipsString = this.getNodeParameter('ips', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const ips = ipsString.split(',').map((ip) => ip.trim());
const body = {
properties: {
name,
listenerLan: parseInt(listenerLan, 10),
targetLan: parseInt(targetLan, 10),
ips,
...(additionalFields.lbPrivateIps && {
lbPrivateIps: additionalFields.lbPrivateIps.split(',').map((ip) => ip.trim()),
}),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'POST',
url: `${baseUrl}/datacenters/${datacenterId}/networkloadbalancers`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'get') {
const networkLoadBalancerId = this.getNodeParameter('networkLoadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/networkloadbalancers/${networkLoadBalancerId}`,
});
}
else if (operation === 'getMany') {
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const qs = {
depth: 1,
};
if (!returnAll) {
qs.limit = limit;
}
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/networkloadbalancers`,
qs,
});
responseData = responseData.items;
}
else if (operation === 'update') {
const networkLoadBalancerId = this.getNodeParameter('networkLoadBalancerId', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const body = {
properties: {
...(additionalFields.lbPrivateIps && {
lbPrivateIps: additionalFields.lbPrivateIps.split(',').map((ip) => ip.trim()),
}),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'PATCH',
url: `${baseUrl}/datacenters/${datacenterId}/networkloadbalancers/${networkLoadBalancerId}`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'delete') {
const networkLoadBalancerId = this.getNodeParameter('networkLoadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'DELETE',
url: `${baseUrl}/datacenters/${datacenterId}/networkloadbalancers/${networkLoadBalancerId}`,
});
responseData = { success: true };
}
}
else if (resource === 'applicationLoadBalancer') {
const datacenterId = this.getNodeParameter('datacenterId', i);
if (operation === 'create') {
const name = this.getNodeParameter('name', i);
const listenerLan = this.getNodeParameter('listenerLan', i);
const targetLan = this.getNodeParameter('targetLan', i);
const ipsString = this.getNodeParameter('ips', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const ips = ipsString.split(',').map((ip) => ip.trim());
const body = {
properties: {
name,
listenerLan: parseInt(listenerLan, 10),
targetLan: parseInt(targetLan, 10),
ips,
...(additionalFields.lbPrivateIps && {
lbPrivateIps: additionalFields.lbPrivateIps.split(',').map((ip) => ip.trim()),
}),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'POST',
url: `${baseUrl}/datacenters/${datacenterId}/applicationloadbalancers`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'get') {
const applicationLoadBalancerId = this.getNodeParameter('applicationLoadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/applicationloadbalancers/${applicationLoadBalancerId}`,
});
}
else if (operation === 'getMany') {
const returnAll = this.getNodeParameter('returnAll', i);
const limit = this.getNodeParameter('limit', i, 50);
const qs = {
depth: 1,
};
if (!returnAll) {
qs.limit = limit;
}
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'GET',
url: `${baseUrl}/datacenters/${datacenterId}/applicationloadbalancers`,
qs,
});
responseData = responseData.items;
}
else if (operation === 'update') {
const applicationLoadBalancerId = this.getNodeParameter('applicationLoadBalancerId', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const body = {
properties: {
...(additionalFields.lbPrivateIps && {
lbPrivateIps: additionalFields.lbPrivateIps.split(',').map((ip) => ip.trim()),
}),
},
};
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'PATCH',
url: `${baseUrl}/datacenters/${datacenterId}/applicationloadbalancers/${applicationLoadBalancerId}`,
body,
headers: { 'Content-Type': 'application/json' },
});
}
else if (operation === 'delete') {
const applicationLoadBalancerId = this.getNodeParameter('applicationLoadBalancerId', i);
responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'ionosCloud', {
method: 'DELETE',
url: `${baseUrl}/datacenters/${datacenterId}/applicationloadbalancers/${applicationLoadBalancerId}`,
});
responseData = { success: true };
}
}
else if (resource === 'targetGroup') {
if (operation === 'create') {
const name = this.getNodeParameter('targetGroupName', i);
const algorithm = this.getNodeParameter('algorithm', i);
const protocol = this.getNodeParameter('protocol', i);
const targetsJson = this.getNodeParameter('targets', i);
const additionalFields = this.getNodeParameter('additionalFields', i);
const targets = JSON.parse(targetsJson);
const body = {
properties: {