Skip to main content
Networks provide software-defined networking infrastructure for connecting instances and other cloud resources within a region.

Methods

New

Create a new virtual network.
func (r *NetworkService) New(ctx context.Context, params NetworkNewParams, opts ...option.RequestOption) (*TaskIDList, error)
func (r *NetworkService) NewAndPoll(ctx context.Context, params NetworkNewParams, opts ...option.RequestOption) (*Network, error)
project_id
int64
required
Project ID
region_id
int64
required
Region ID
name
string
required
Network name
create_router
bool
Automatically create a router for the network. Defaults to true
type
string
Network type: vlan or vxlan. Default is vxlan
tags
map[string]string
Key-value tags
id
string
Network UUID
name
string
Network name
type
string
Network type (vlan or vxlan)
external
bool
Whether this is an external network
shared
bool
Whether this network is shared across projects
subnets
[]string
List of subnet IDs in this network

Update

Update network name or tags.
func (r *NetworkService) Update(ctx context.Context, networkID string, params NetworkUpdateParams, opts ...option.RequestOption) (*Network, error)
name
string
New network name
tags
TagUpdateMap
Tags to add, update, or remove

List

List networks with optional filtering.
func (r *NetworkService) List(ctx context.Context, params NetworkListParams, opts ...option.RequestOption) (*pagination.OffsetPage[Network], error)
func (r *NetworkService) ListAutoPaging(ctx context.Context, params NetworkListParams, opts ...option.RequestOption) *pagination.OffsetPageAutoPager[Network]
name
string
Filter by network name
external
bool
Filter by external network status
network_type
string
Filter by network type: vlan or vxlan
owned_by
string
Control which networks to return: project (default) or any (includes shared networks)
order_by
string
Sort order: created_at.asc, created_at.desc, name.asc, name.desc, priority.desc
limit
int64
Maximum results per page
offset
int64
Results to skip

Get

Retrieve network details.
func (r *NetworkService) Get(ctx context.Context, networkID string, query NetworkGetParams, opts ...option.RequestOption) (*Network, error)

Delete

Delete a network.
func (r *NetworkService) Delete(ctx context.Context, networkID string, body NetworkDeleteParams, opts ...option.RequestOption) (*TaskIDList, error)
func (r *NetworkService) DeleteAndPoll(ctx context.Context, networkID string, body NetworkDeleteParams, opts ...option.RequestOption) error

Sub-Services

Subnets

Manage subnets within networks.
client.Cloud.Networks.Subnets.New(ctx, params) // Create subnet
client.Cloud.Networks.Subnets.List(ctx, params) // List subnets
client.Cloud.Networks.Subnets.Get(ctx, subnetID, params)
client.Cloud.Networks.Subnets.Update(ctx, subnetID, params)
client.Cloud.Networks.Subnets.Delete(ctx, subnetID, params)

Routers

Manage routers for network connectivity.
client.Cloud.Networks.Routers.New(ctx, params) // Create router
client.Cloud.Networks.Routers.List(ctx, params) // List routers
client.Cloud.Networks.Routers.Get(ctx, routerID, params)
client.Cloud.Networks.Routers.Update(ctx, routerID, params)
client.Cloud.Networks.Routers.Delete(ctx, routerID, params)

Examples

Create a Network

import (
    "context"
    "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/cloud"
    "github.com/G-Core/gcore-go/option"
)

client := gcore.NewClient(
    option.WithCloudProjectID(projectID),
    option.WithCloudRegionID(regionID),
)

network, err := client.Cloud.Networks.NewAndPoll(context.Background(), 
    cloud.NetworkNewParams{
        Name:         "my-network",
        CreateRouter: gcore.Bool(true),
        Type:         cloud.NetworkNewParamsTypeVxlan,
        Tags:         map[string]string{"environment": "production"},
    },
)
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Created network: %s\n", network.ID)

Create a Subnet

subnet, err := client.Cloud.Networks.Subnets.NewAndPoll(context.Background(), 
    cloud.NetworkSubnetNewParams{
        NetworkID: networkID,
        Name:      "my-subnet",
        Cidr:      "10.0.1.0/24",
        EnableDhcp: gcore.Bool(true),
    },
)

List All Networks

networks, err := client.Cloud.Networks.List(context.Background(), 
    cloud.NetworkListParams{},
)
if err != nil {
    log.Fatal(err)
}

for _, net := range networks.Results {
    fmt.Printf("Network: %s (Type: %s)\n", net.Name, net.Type)
}

List Networks with Shared Networks

networks, err := client.Cloud.Networks.List(context.Background(), 
    cloud.NetworkListParams{
        OwnedBy: cloud.NetworkListParamsOwnedByAny,
    },
)

Update Network

network, err := client.Cloud.Networks.Update(context.Background(), 
    networkID,
    cloud.NetworkUpdateParams{
        Name: param.NewOpt("updated-network-name"),
        Tags: cloud.TagUpdateMap{
            "environment": param.NewOpt("staging"),
        },
    },
)

Get Network Details

network, err := client.Cloud.Networks.Get(context.Background(), 
    networkID,
    cloud.NetworkGetParams{},
)

Delete Network

err := client.Cloud.Networks.DeleteAndPoll(context.Background(), 
    networkID,
    cloud.NetworkDeleteParams{},
)

Common Use Cases

Create Network with Subnet

// Create network
network, err := client.Cloud.Networks.NewAndPoll(context.Background(), 
    cloud.NetworkNewParams{
        Name:         "app-network",
        CreateRouter: gcore.Bool(true),
    },
)
if err != nil {
    log.Fatal(err)
}

// Create subnet
subnet, err := client.Cloud.Networks.Subnets.NewAndPoll(context.Background(), 
    cloud.NetworkSubnetNewParams{
        NetworkID:  network.ID,
        Name:       "app-subnet",
        Cidr:       "192.168.1.0/24",
        EnableDhcp: gcore.Bool(true),
        DnsNameservers: []string{"8.8.8.8", "8.8.4.4"},
    },
)
if err != nil {
    log.Fatal(err)
}

fmt.Printf("Network: %s, Subnet: %s\n", network.ID, subnet.ID)

Multi-tier Network Architecture

// Create network
network, err := client.Cloud.Networks.NewAndPoll(context.Background(), 
    cloud.NetworkNewParams{
        Name: "multi-tier-network",
    },
)

// Web tier subnet
webSubnet, _ := client.Cloud.Networks.Subnets.NewAndPoll(context.Background(), 
    cloud.NetworkSubnetNewParams{
        NetworkID: network.ID,
        Name:      "web-tier",
        Cidr:      "10.0.1.0/24",
    },
)

// App tier subnet
appSubnet, _ := client.Cloud.Networks.Subnets.NewAndPoll(context.Background(), 
    cloud.NetworkSubnetNewParams{
        NetworkID: network.ID,
        Name:      "app-tier",
        Cidr:      "10.0.2.0/24",
    },
)

// Database tier subnet
dbSubnet, _ := client.Cloud.Networks.Subnets.NewAndPoll(context.Background(), 
    cloud.NetworkSubnetNewParams{
        NetworkID: network.ID,
        Name:      "db-tier",
        Cidr:      "10.0.3.0/24",
    },
)

List Subnets in a Network

subnets, err := client.Cloud.Networks.Subnets.List(context.Background(), 
    cloud.NetworkSubnetListParams{
        NetworkID: gcore.String(networkID),
    },
)
if err != nil {
    log.Fatal(err)
}

for _, subnet := range subnets.Results {
    fmt.Printf("Subnet: %s, CIDR: %s\n", subnet.Name, subnet.Cidr)
}

Build docs developers (and LLMs) love