UNPKG

ibm-vpc

Version:
1,941 lines (1,488 loc) 292 kB
/** * @jest-environment node */ /** * (C) Copyright IBM Corp. 2023, 2024, 2025. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; const VpcV1 = require('../dist/vpc/v1'); const { readExternalSources } = require('ibm-cloud-sdk-core'); const authHelper = require('../test/resources/auth-helper.js'); const { displayPartsToString } = require('typescript'); // // This file provides an example of how to use the vpc service. // // The following configuration properties are assumed to be defined: // VPC_URL=<service base url> // VPC_AUTH_TYPE=iam // VPC_APIKEY=<IAM apikey> // VPC_AUTH_URL=<IAM token service base URL - omit this if using the production environment> // // These configuration properties can be exported as environment variables, or stored // in a configuration file and then: // export IBM_CREDENTIALS_FILE=<name of configuration file> // const configFile = 'vpc_v1.env'; const describe = authHelper.prepareTests(configFile); const data = {}; data.zone = "us-east-1" data.region = "us-east" const timeout = 60000; // Save original console.log and console.warn const originalLog = console.log; const originalWarn = console.warn; // Mocks for console.log and console.warn const consoleLogMock = jest.spyOn(console, 'log'); const consoleWarnMock = jest.spyOn(console, 'warn'); jest.setTimeout(timeout); describe('VpcV1', () => { // begin-common const vpcService = VpcV1.newInstance(); // end-common const config = readExternalSources(VpcV1.DEFAULT_SERVICE_NAME); test('listVpcs request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_vpcs const params = { limit: 10, }; const allResults = []; try { const pager = new VpcV1.VpcsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_vpcs console.log(JSON.stringify(allResults, null, 2)); }); test('createVpc request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc const params = { name: 'my-vpc', addressPrefixManagement: 'manual', classicAccess: true, }; var response = await vpcService.createVpc(params); // end-create_vpc data.vpcId = response.result.id; expect(response.result).not.toBeNull(); }); test('createHubVpcExample request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc const zoneIdentityModel = { name: data.zone, }; const dnsServerPrototype = { address: '192.168.3.4', zone_affinity: zoneIdentityModel, }; const vpcDNSResolverPrototype = { manual_servers: [dnsServerPrototype], type: 'manual', }; const vpcDnsPrototype = { enable_hub: false, resolver: vpcDNSResolverPrototype, }; const params = { name: 'my-vpc-hub', addressPrefixManagement: 'manual', classicAccess: true, dns: vpcDnsPrototype, }; var response = await vpcService.createVpc(params); // end-create_vpc expect(response.result).not.toBeNull(); data.vpcHubID = response.result.id; }); test('getVpc request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc const params = { id: data.vpcId, }; const response = await vpcService.getVpc(params); // end-get_vpc expect(response.result).not.toBeNull(); }); test('updateVpc request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_vpc const params = { id: data.vpcId, name: 'my-vpc-updated', }; const response = await vpcService.updateVpc(params); // end-update_vpc expect(response.result).not.toBeNull(); }); test('getVpcDefaultNetworkAcl request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_default_network_acl const params = { id: data.vpcId, }; const response = await vpcService.getVpcDefaultNetworkAcl(params); // end-get_vpc_default_network_acl expect(response.result).not.toBeNull(); }); test('getVpcDefaultRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_default_routing_table const params = { id: data.vpcId, }; const response = await vpcService.getVpcDefaultRoutingTable(params); // end-get_vpc_default_routing_table expect(response.result).not.toBeNull(); }); test('getVpcDefaultSecurityGroup request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_default_security_group const params = { id: data.vpcId, }; const response = await vpcService.getVpcDefaultSecurityGroup(params); // end-get_vpc_default_security_group expect(response.result).not.toBeNull(); }); test('listVpcAddressPrefixes request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_vpc_address_prefixes const params = { vpcId: data.vpcId, limit: 10, }; const allResults = []; try { const pager = new VpcV1.VpcAddressPrefixesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_vpc_address_prefixes console.log(JSON.stringify(allResults, null, 2)); }); test('createVpcAddressPrefix request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc_address_prefix const params = { vpcId: data.vpcId, cidr: '10.0.0.0/24', zone: { name: data.zone }, name: 'my-address-prefix', }; const response = await vpcService.createVpcAddressPrefix(params); // end-create_vpc_address_prefix data.vpcAddressPrefixId = response.result.id; expect(response.result).not.toBeNull(); }); test('getVpcAddressPrefix request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_address_prefix const params = { vpcId: data.vpcId, id: data.vpcAddressPrefixId, }; const response = await vpcService.getVpcAddressPrefix(params); // end-get_vpc_address_prefix expect(response.result).not.toBeNull(); }); test('updateVpcAddressPrefix request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_vpc_address_prefix const params = { vpcId: data.vpcId, id: data.vpcAddressPrefixId, name: 'my-address-prefix-updated', }; const response = await vpcService.updateVpcAddressPrefix(params); // end-update_vpc_address_prefix expect(response.result).not.toBeNull(); }); test('createVpcDnsResolutionBinding request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc_dns_resolution_binding const vpcIdentityModel = { id: data.vpcHubID, }; const params = { vpcId: data.vpcId, name: 'my-vpc-dns-resolution-binding', vpc: vpcIdentityModel, }; const response = await vpcService.createVpcDnsResolutionBinding(params); // end-create_vpc_dns_resolution_binding data.vpcDnsResolutionId = response.result.id; expect(response.result).not.toBeNull(); }); test('listVpcDnsResolutionBinding request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_vpc_dns_resolution_binding const params = { vpcId: data.vpcId, limit: 10, }; const allResults = []; try { const pager = new VpcV1.VpcDnsResolutionBindingsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_vpc_dns_resolution_binding console.log(JSON.stringify(allResults, null, 2)); }); test('getVpcDnsResolutionBinding request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get__vpc_dns_resolution_binding const params = { vpcId: data.vpcId, id: data.vpcDnsResolutionId, }; const response = await vpcService.getVpcDnsResolutionBinding(params); // end-get_vpc_dns_resolution_binding expect(response.result).not.toBeNull(); }); test('updateVpcDnsResolutionBinding request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_vpc_dns_resolution_binding const params = { vpcId: data.vpcId, id: data.vpcDnsResolutionId, name: 'my-vpc-dns-resolution-binding-updated', }; const response = await vpcService.updateVpcDnsResolutionBinding(params); // end-update_vpc_dns_resolution_binding expect(response.result).not.toBeNull(); }); test('listVpcRoutingTables request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_vpc_routing_tables const params = { vpcId: data.vpcId, limit: 10, }; const allResults = []; try { const pager = new VpcV1.VpcRoutingTablesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_vpc_routing_tables console.log(JSON.stringify(allResults, null, 2)); }); test('createVpcRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc_routing_table const routeNextHopPrototypeModel = { address: '192.168.3.4', }; const zoneIdentityModel = { name: data.zone, }; const routePrototypeModel = { action: 'delegate', next_hop: routeNextHopPrototypeModel, name: 'my-route', destination: '192.168.3.0/24', zone: zoneIdentityModel, }; const params = { vpcId: data.vpcId, name: 'my-routing-table', routes: [routePrototypeModel], }; const response = await vpcService.createVpcRoutingTable(params); // end-create_vpc_routing_table data.vpcRoutingTableId = response.result.id; expect(response.result).not.toBeNull(); }); test('getVpcRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_routing_table const params = { vpcId: data.vpcId, id: data.vpcRoutingTableId, }; const response = await vpcService.getVpcRoutingTable(params); // end-get_vpc_routing_table expect(response.result).not.toBeNull(); }); test('updateVpcRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_vpc_routing_table const params = { vpcId: data.vpcId, id: data.vpcRoutingTableId, name: 'my-routing-table-updated', }; const response = await vpcService.updateVpcRoutingTable(params); // end-update_vpc_routing_table expect(response.result).not.toBeNull(); }); test('listVpcRoutingTableRoutes request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_vpc_routing_table_routes const params = { vpcId: data.vpcId, routingTableId: data.vpcRoutingTableId, limit: 10, }; const allResults = []; try { const pager = new VpcV1.VpcRoutingTableRoutesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_vpc_routing_table_routes console.log(JSON.stringify(allResults, null, 2)); }); test('createVpcRoutingTableRoute request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_vpc_routing_table_route const routeNextHopPrototypeModel = { address: '192.168.3.7', }; const params = { vpcId: data.vpcId, routingTableId: data.vpcRoutingTableId, destination: '192.168.77.0/24', zone: { name: data.zone, }, action: 'delegate', nextHop: routeNextHopPrototypeModel, name: 'my-routing-table-route', priority:1, }; const response = await vpcService.createVpcRoutingTableRoute(params); // end-create_vpc_routing_table_route data.vpcRoutingTableRouteId = response.result.id; expect(response.result).not.toBeNull(); }); test('getVpcRoutingTableRoute request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_vpc_routing_table_route const params = { vpcId: data.vpcId, routingTableId: data.vpcRoutingTableId, id: data.vpcRoutingTableRouteId, }; const response = await vpcService.getVpcRoutingTableRoute(params); // end-get_vpc_routing_table_route expect(response.result).not.toBeNull(); }); test('updateVpcRoutingTableRoute request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_vpc_routing_table_route const params = { vpcId: data.vpcId, routingTableId: data.vpcRoutingTableId, id: data.vpcRoutingTableRouteId, name: 'my-routing-table-route-updated', }; const response = await vpcService.updateVpcRoutingTableRoute(params); // end-update_vpc_routing_table_route expect(response.result).not.toBeNull(); }); test('listSubnets request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_subnets const params = { limit: 10, } const allResults = []; try { const pager = new VpcV1.SubnetsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_subnets console.log(JSON.stringify(allResults, null, 2)); }); test('createSubnet request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_subnet const vpcIdentityModel = { id: data.vpcId, }; const zoneIdentityModel = { name: data.zone, }; const subnetPrototypeModel = { name: 'my-subnet', vpc: vpcIdentityModel, ipv4_cidr_block: '10.0.1.0/24', zone: zoneIdentityModel, }; const params = { subnetPrototype: subnetPrototypeModel, }; const response = await vpcService.createSubnet(params); // end-create_subnet expect(response.result).not.toBeNull(); data.subnetId = response.result.id; }); test('getSubnet request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_subnet const params = { id: data.subnetId, }; const response = await vpcService.getSubnet(params); // end-get_subnet expect(response.result).not.toBeNull(); }); test('updateSubnet request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_subnet const params = { id: data.subnetId, name: 'my-subnet-updated', } const response = await vpcService.updateSubnet(params); // end-update_subnet expect(response.result).not.toBeNull(); }); test('getSubnetNetworkAcl request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_subnet_network_acl const params = { id: data.subnetId, }; const response = await vpcService.getSubnetNetworkAcl(params); // end-get_subnet_network_acl expect(response.result).not.toBeNull(); }); test('replaceSubnetNetworkAcl request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-replace_subnet_network_acl const networkAclPrototypeModel = { name: 'my-subnet-network-acl', vpc: { id: data.vpcId, }, }; const networkAclPrototypeParams = { networkAclPrototype: networkAclPrototypeModel, }; const networkAclResponse = await vpcService.createNetworkAcl(networkAclPrototypeParams); expect(networkAclResponse.result).not.toBeNull(); const params = { id: data.subnetId, networkAclIdentity: { id: networkAclResponse.result.id, }, }; const response = await vpcService.replaceSubnetNetworkAcl(params); // end-replace_subnet_network_acl expect(response.result).not.toBeNull(); }); test('setSubnetPublicGateway request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-set_subnet_public_gateway const publicGatewayParams = { vpc: { id: data.vpcId }, zone: { name: data.zone }, }; const publicGatewayResponse = await vpcService.createPublicGateway(publicGatewayParams); const params = { id: data.subnetId, publicGatewayIdentity: { id: publicGatewayResponse.result.id, }, }; const response = await vpcService.setSubnetPublicGateway(params); // end-set_subnet_public_gateway expect(response.result).not.toBeNull(); }); test('getSubnetPublicGateway request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_subnet_public_gateway const params = { id: data.subnetId, }; const response = await vpcService.getSubnetPublicGateway(params); // end-get_subnet_public_gateway expect(response.result).not.toBeNull(); }); test('unsetSubnetPublicGateway request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-unset_subnet_public_gateway const params = { id: data.subnetId, }; const response = await vpcService.unsetSubnetPublicGateway(params); // end-unset_subnet_public_gateway expect(response.result).not.toBeNull(); }); test('getSubnetRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_subnet_routing_table const params = { id: data.subnetId, }; const response = await vpcService.getSubnetRoutingTable(params); // end-get_subnet_routing_table expect(response.result).not.toBeNull(); }); test('replaceSubnetRoutingTable request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-replace_subnet_routing_table const routingTableIdentityModel = { id: data.vpcRoutingTableId, }; const params = { id: data.subnetId, routingTableIdentity: routingTableIdentityModel, }; const response = await vpcService.replaceSubnetRoutingTable(params); // end-replace_subnet_routing_table expect(response.result).not.toBeNull(); }); test('listSubnetReservedIps request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_subnet_reserved_ips const params = { subnetId: data.subnetId, limit: 10, }; const allResults = []; try { const pager = new VpcV1.SubnetReservedIpsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_subnet_reserved_ips console.log(JSON.stringify(allResults, null, 2)); }); test('createSubnetReservedIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_subnet_reserved_ip const params = { subnetId: data.subnetId, name: 'my-subnet-reserved-ip', }; const response = await vpcService.createSubnetReservedIp(params); // end-create_subnet_reserved_ip expect(response.result).not.toBeNull(); data.subnetReservedIp = response.result.id; }); test('getSubnetReservedIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_subnet_reserved_ip const params = { subnetId: data.subnetId, id: data.subnetReservedIp, }; const response = await vpcService.getSubnetReservedIp(params); // end-get_subnet_reserved_ip expect(response.result).not.toBeNull(); }); test('updateSubnetReservedIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_subnet_reserved_ip const params = { subnetId: data.subnetId, id: data.subnetReservedIp, name: 'my-reserved-ip-updated', }; const response = await vpcService.updateSubnetReservedIp(params); // end-update_subnet_reserved_ip expect(response.result).not.toBeNull(); }); test('deleteSubnetReservedIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); const responseNew = await vpcService.createSubnetReservedIp({ subnetId: data.subnetId, name: 'my-subnet-reserved-ip-rip' }); data.subnetReservedIpId = responseNew.result.id; // begin-delete_subnet_reserved_ip const params = { subnetId: data.subnetId, id: data.subnetReservedIp, }; const response = await vpcService.deleteSubnetReservedIp(params); // end-delete_subnet_reserved_ip expect(response.result).not.toBeNull(); }); test('listImages request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_images const params = { userDataFormat: 'cloud_init', visibility: 'private', limit: 10, } const allResults = []; try { const pager = new VpcV1.ImagesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_images console.log(JSON.stringify(allResults, null, 2)); }); test('createImage request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_image const imageFilePrototypeModel = { href: "cos://us-south/my-bucket/my-image.qcow2", }; const operatingSystemIdentityModel = { name: 'debian-9-amd64', }; const imagePrototypeModel = { name: 'my-image', file: imageFilePrototypeModel, operating_system: operatingSystemIdentityModel, }; const params = { imagePrototype: imagePrototypeModel, }; const response = await vpcService.createImage(params); // end-create_image expect(response.result).not.toBeNull(); data.imageId = response.result.id; }); test('getImage request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_image const params = { id: data.imageId, }; const response = await vpcService.getImage(params); // end-get_image expect(response.result).not.toBeNull(); }); test('updateImage request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_image const params = { id: data.imageId, name: 'my-image-updated', }; const response = await vpcService.updateImage(params); // end-update_image expect(response.result).not.toBeNull(); }); test('listImageExportJobs request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_image_export_jobs const params = { imageId: data.imageId, }; const response = await vpcService.listImageExportJobs(params); // end-list_image_export_jobs expect(response.result).not.toBeNull(); }); test('createImageExportJob request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_image_export_job const storageBucket = { name: 'bucket-27200-lwx4cfvcue', }; const params1 = { storageBucket: storageBucket, imageId: data.imageId, name:'my-image-export-job', }; const response1 = await vpcService.createImageExportJob(params1); data.imageExportJobId = response1.result.id; // end-create_image_export_job expect(response1.result).not.toBeNull(); }); test('getImageExportJob request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_image_export_job const params = { imageId: data.imageId, id: data.imageExportJobId, }; const response = await vpcService.getImageExportJob(params); // end-get_image_export_job expect(response.result).not.toBeNull(); }); test('updateImageExportJob request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_image_export_job const params = { imageId: data.imageId, id: data.imageExportJobId, name:'my-image-export-job-updated', }; const response = await vpcService.updateImageExportJob(params); // end-update_image_export_job expect(response.result).not.toBeNull(); }); test('deleteImageExportJob request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-delete_image_export_job const params = { imageId: data.imageId, id: data.imageExportJobId, }; const response = await vpcService.deleteImageExportJob(params); // end-delete_image_export_job expect(response.result).not.toBeNull(); }); test('listOperatingSystems request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_operating_systems const params = { limit: 10, }; const allResults = []; try { const pager = new VpcV1.OperatingSystemsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_operating_systems expect(allResults.result).not.toBeNull(); data.operatingSystemName = allResults[0].name; console.log(JSON.stringify(allResults, null, 2)); }); test('getOperatingSystem request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_operating_system const params = { name: data.operatingSystemName, }; const response = await vpcService.getOperatingSystem(params); // end-get_operating_system expect(response.result).not.toBeNull(); }); test('listKeys request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_keys const params = { limit: 10, }; const allResults = []; try { const pager = new VpcV1.KeysPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_keys console.log(JSON.stringify(allResults, null, 2)); }); test('createKey request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_key const params = { publicKey: 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDDGe50Bxa5T5NDddrrtbx2Y4/VGbiCgXqnBsYToIUKoFSHTQl5IX3PasGnneKanhcLwWz5M5MoCRvhxTp66NKzIfAz7r+FX9rxgR+ZgcM253YAqOVeIpOU408simDZKriTlN8kYsXL7P34tsWuAJf4MgZtJAQxous/2byetpdCv8ddnT4X3ltOg9w+LqSCPYfNivqH00Eh7S1Ldz7I8aw5WOp5a+sQFP/RbwfpwHp+ny7DfeIOokcuI42tJkoBn7UsLTVpCSmXr2EDRlSWe/1M/iHNRBzaT3CK0+SwZWd2AEjePxSnWKNGIEUJDlUYp7hKhiQcgT5ZAnWU121oc5En', name: 'my-ssh-key', }; const response = await vpcService.createKey(params); // end-create_key expect(response.result).not.toBeNull(); data.keyId = response.result.id; }); test('getKey request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_key const params = { id: data.keyId, }; const response = await vpcService.getKey(params); // end-get_key expect(response.result).not.toBeNull(); }); test('updateKey request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_key const params = { id: data.keyId, name: 'my-ssh-key-updated', }; const response = await vpcService.updateKey(params); // end-update_key expect(response.result).not.toBeNull(); }); test('listFloatingIps request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_floating_ips const params = { limit: 10, }; const allResults = []; try { const pager = new VpcV1.FloatingIpsPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_floating_ips console.log(JSON.stringify(allResults, null, 2)); }); test('createFloatingIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-create_floating_ip const params = { floatingIpPrototype: { name: 'my-floating-ip', zone: { name: data.zone, }, }, }; const response = await vpcService.createFloatingIp(params); // end-create_floating_ip expect(response.result).not.toBeNull(); data.floatingIpId = response.result.id; }); test('getFloatingIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_floating_ip const params = { id: data.floatingIpId, }; const response = await vpcService.getFloatingIp(params); // end-get_floating_ip data.floatingIpId = response.result.id; }); test('updateFloatingIp request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_floating_ip const params = { id: data.floatingIpId, name: 'my-floating-ip-updated', }; const response = await vpcService.updateFloatingIp(params); // end-update_floating_ip data.floatingIpId = response.result.id; }); test('listVolumeProfiles request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_volume_profiles const params = { limit: 10, }; const allResults = []; try { const pager = new VpcV1.VolumeProfilesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_volume_profiles console.log(JSON.stringify(allResults, null, 2)); }); test('getVolumeProfile request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_volume_profile const params = { name: '10iops-tier', }; const response = await vpcService.getVolumeProfile(params); // end-get_volume_profile expect(response.result).not.toBeNull(); }); test('listVolumes request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-list_volumes const params = { limit: 10, attachmentState:'attached', encryption:'provider_managed', operatingSystemFamily:'Ubuntu Server', operatingSystemArchitecture:'amd64', } const allResults = []; try { const pager = new VpcV1.VolumesPager(vpcService, params); while (pager.hasNext()) { const nextPage = await pager.getNext(); expect(nextPage).not.toBeNull(); allResults.push(...nextPage); } } catch (err) { console.warn(err); } // end-list_volumes console.log(JSON.stringify(allResults, null, 2)); }); test('createVolume request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); const volumePrototypeModel1 = { name: 'my-volume-1', profile: { name: 'general-purpose' }, zone: { name: data.zone }, capacity: 100, }; const params1 = { volumePrototype: volumePrototypeModel1, }; const response1 = await vpcService.createVolume(params1); data.sourceVolumeId = response1.result.id; // begin-create_volume const volumePrototypeModel = { name: 'my-volume', profile: { name: 'general-purpose' }, zone: { name: data.zone }, capacity: 100, }; const params = { volumePrototype: volumePrototypeModel, }; const response = await vpcService.createVolume(params); // end-create_volume expect(response.result).not.toBeNull(); data.volumeId = response.result.id; }); test('getVolume request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-get_volume const params = { id: data.volumeId, }; const response = await vpcService.getVolume(params); // end-get_volume expect(response.result).not.toBeNull(); }); test('updateVolume request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and then fail the test originalWarn(output); expect(true).toBeFalsy(); }); // begin-update_volume const params = { id: data.volumeId, name: 'my-volume-updated', }; const response = await vpcService.updateVolume(params); // end-update_volume expect(response.result).not.toBeNull(); }); test('listInstanceProfiles request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); }); consoleWarnMock.mockImplementation((output) => { // if an error occurs, display the message and