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

     1  /*
     2  Package groups provides information and interaction with Security Groups
     3  for the OpenStack Networking service.
     4  
     5  Example to List Security Groups
     6  
     7  	listOpts := groups.ListOpts{
     8  		TenantID: "966b3c7d36a24facaf20b7e458bf2192",
     9  	}
    10  
    11  	allPages, err := groups.List(networkClient, listOpts).AllPages()
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	allGroups, err := groups.ExtractGroups(allPages)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	for _, group := range allGroups {
    22  		fmt.Printf("%+v\n", group)
    23  	}
    24  
    25  Example to Create a Security Group
    26  
    27  	createOpts := groups.CreateOpts{
    28  		Name:        "group_name",
    29  		Description: "A Security Group",
    30  	}
    31  
    32  	group, err := groups.Create(networkClient, createOpts).Extract()
    33  	if err != nil {
    34  		panic(err)
    35  	}
    36  
    37  Example to Update a Security Group
    38  
    39  	groupID := "37d94f8a-d136-465c-ae46-144f0d8ef141"
    40  
    41  	updateOpts := groups.UpdateOpts{
    42  		Name: "new_name",
    43  	}
    44  
    45  	group, err := groups.Update(networkClient, groupID, updateOpts).Extract()
    46  	if err != nil {
    47  		panic(err)
    48  	}
    49  
    50  Example to Delete a Security Group
    51  
    52  	groupID := "37d94f8a-d136-465c-ae46-144f0d8ef141"
    53  	err := groups.Delete(networkClient, groupID).ExtractErr()
    54  	if err != nil {
    55  		panic(err)
    56  	}
    57  */
    58  package groups