github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/nodegroups/doc.go (about)

     1  /*
     2  Package nodegroups provides methods for interacting with the Magnum node group API.
     3  
     4  All node group actions must be performed on a specific cluster,
     5  so the cluster UUID/name is required as a parameter in each method.
     6  
     7  Create a client to use:
     8  
     9  	opts, err := openstack.AuthOptionsFromEnv()
    10  	if err != nil {
    11  	    panic(err)
    12  	}
    13  
    14  	provider, err := openstack.AuthenticatedClient(opts)
    15  	if err != nil {
    16  	    panic(err)
    17  	}
    18  
    19  	client, err := openstack.NewContainerInfraV1(provider, gophercloud.EndpointOpts{Region: os.Getenv("OS_REGION_NAME")})
    20  	if err != nil {
    21  	    panic(err)
    22  	}
    23  
    24  	client.Microversion = "1.9"
    25  
    26  Example of Getting a node group:
    27  
    28  	ng, err := nodegroups.Get(client, clusterUUID, nodeGroupUUID).Extract()
    29  	if err != nil {
    30  	    panic(err)
    31  	}
    32  	fmt.Printf("%#v\n", ng)
    33  
    34  Example of Listing node groups:
    35  
    36  	listOpts := nodegroup.ListOpts{
    37  	    Role: "worker",
    38  	}
    39  
    40  	allPages, err := nodegroups.List(client, clusterUUID, listOpts).AllPages()
    41  	if err != nil {
    42  	    panic(err)
    43  	}
    44  
    45  	ngs, err := nodegroups.ExtractNodeGroups(allPages)
    46  	if err != nil {
    47  	    panic(err)
    48  	}
    49  
    50  	for _, ng := range ngs {
    51  	    fmt.Printf("%#v\n", ng)
    52  	}
    53  
    54  Example of Creating a node group:
    55  
    56  	// Labels, node image and node flavor will be inherited from the cluster value if not set.
    57  	// Role will default to "worker" if not set.
    58  
    59  	// To add a label to the new node group, need to know the cluster labels
    60  	cluster, err := clusters.Get(client, clusterUUID).Extract()
    61  	if err != nil {
    62  	    panic(err)
    63  	}
    64  
    65  	// Add the new label
    66  	labels := cluster.Labels
    67  	labels["availability_zone"] = "A"
    68  
    69  	maxNodes := 5
    70  	createOpts := nodegroups.CreateOpts{
    71  	    Name:         "new-nodegroup",
    72  	    MinNodeCount: 2,
    73  	    MaxNodeCount: &maxNodes,
    74  	    Labels: labels,
    75  	}
    76  
    77  	ng, err := nodegroups.Create(client, clusterUUID, createOpts).Extract()
    78  	if err != nil {
    79  	    panic(err)
    80  	}
    81  
    82  	fmt.Printf("%#v\n", ng)
    83  
    84  Example of Updating a node group:
    85  
    86  	// Valid paths are "/min_node_count" and "/max_node_count".
    87  	// Max node count can be unset with the "remove" op to have
    88  	// no enforced maximum node count.
    89  
    90  	updateOpts := []nodegroups.UpdateOptsBuilder{
    91  	    nodegroups.UpdateOpts{
    92  	        Op:    nodegroups.ReplaceOp,
    93  	        Path:  "/max_node_count",
    94  	        Value: 10,
    95  	    },
    96  	}
    97  
    98  	ng, err = nodegroups.Update(client, clusterUUID, nodeGroupUUID, updateOpts).Extract()
    99  	if err != nil {
   100  	    panic(err)
   101  	}
   102  
   103  	fmt.Printf("%#v\n", ng)
   104  
   105  Example of Deleting a node group:
   106  
   107  	err = nodegroups.Delete(client, clusterUUID, nodeGroupUUID).ExtractErr()
   108  	if err != nil {
   109  	    panic(err)
   110  	}
   111  */
   112  package nodegroups