github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/ports/doc.go (about)

     1  /*
     2  Package ports contains functionality for working with Neutron port resources.
     3  
     4  A port represents a virtual switch port on a logical network switch. Virtual
     5  instances attach their interfaces into ports. The logical port also defines
     6  the MAC address and the IP address(es) to be assigned to the interfaces
     7  plugged into them. When IP addresses are associated to a port, this also
     8  implies the port is associated with a subnet, as the IP address was taken
     9  from the allocation pool for a specific subnet.
    10  
    11  Example to List Ports
    12  
    13  	listOpts := ports.ListOpts{
    14  		DeviceID: "b0b89efe-82f8-461d-958b-adbf80f50c7d",
    15  	}
    16  
    17  	allPages, err := ports.List(networkClient, listOpts).AllPages()
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  
    22  	allPorts, err := ports.ExtractPorts(allPages)
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  
    27  	for _, port := range allPorts {
    28  		fmt.Printf("%+v\n", port)
    29  	}
    30  
    31  Example to Create a Port
    32  
    33  	createOtps := ports.CreateOpts{
    34  		Name:         "private-port",
    35  		AdminStateUp: &asu,
    36  		NetworkID:    "a87cc70a-3e15-4acf-8205-9b711a3531b7",
    37  		FixedIPs: []ports.IP{
    38  			{SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.2"},
    39  		},
    40  		SecurityGroups: &[]string{"foo"},
    41  		AllowedAddressPairs: []ports.AddressPair{
    42  			{IPAddress: "10.0.0.4", MACAddress: "fa:16:3e:c9:cb:f0"},
    43  		},
    44  	}
    45  
    46  	port, err := ports.Create(networkClient, createOpts).Extract()
    47  	if err != nil {
    48  		panic(err)
    49  	}
    50  
    51  Example to Update a Port
    52  
    53  	portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8"
    54  
    55  	updateOpts := ports.UpdateOpts{
    56  		Name:           "new_name",
    57  		SecurityGroups: &[]string{},
    58  	}
    59  
    60  	port, err := ports.Update(networkClient, portID, updateOpts).Extract()
    61  	if err != nil {
    62  		panic(err)
    63  	}
    64  
    65  Example to Delete a Port
    66  
    67  	portID := "c34bae2b-7641-49b6-bf6d-d8e473620ed8"
    68  	err := ports.Delete(networkClient, portID).ExtractErr()
    69  	if err != nil {
    70  		panic(err)
    71  	}
    72  */
    73  package ports