Adding docs
diff --git a/openstack/compute/v2/extensions/secgroups/requests.go b/openstack/compute/v2/extensions/secgroups/requests.go
index a91922d..58ec6a8 100644
--- a/openstack/compute/v2/extensions/secgroups/requests.go
+++ b/openstack/compute/v2/extensions/secgroups/requests.go
@@ -17,14 +17,21 @@
return pagination.NewPager(client, url, createPage)
}
+// List will return a collection of all the security groups for a particular
+// tenant.
func List(client *gophercloud.ServiceClient) pagination.Pager {
return commonList(client, rootURL(client))
}
+// ListByServer will return a collection of all the security groups which are
+// associated with a particular server.
func ListByServer(client *gophercloud.ServiceClient, serverID string) pagination.Pager {
return commonList(client, listByServerURL(client, serverID))
}
+// GroupOpts is the underlying struct responsible for creating or updating
+// security groups. It therefore represents the mutable attributes of a
+// security group.
type GroupOpts struct {
// Optional - the name of your security group. If no value provided, null
// will be set.
@@ -35,8 +42,10 @@
Description string `json:"description,omitempty"`
}
+// CreateOpts is the struct responsible for creating a security group.
type CreateOpts GroupOpts
+// Create will create a new security group.
func Create(client *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
var result CreateResult
@@ -54,8 +63,11 @@
return result
}
+// UpdateOpts is the struct responsible for updating an existing security group.
type UpdateOpts GroupOpts
+// Update will modify the mutable properties of a security group, notably its
+// name and description.
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
var result UpdateResult
@@ -73,6 +85,7 @@
return result
}
+// Get will return details for a particular security group.
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var result GetResult
@@ -85,6 +98,7 @@
return result
}
+// Delete will permanently delete a security group from the project.
func Delete(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
@@ -96,6 +110,8 @@
return result
}
+// AddRuleOpts represents the configuration for adding a new rule to an
+// existing security group.
type AddRuleOpts struct {
// Required - the ID of the group that this rule will be added to.
ParentGroupID string `json:"parent_group_id"`
@@ -121,6 +137,9 @@
FromGroupID string `json:"group_id,omitempty"`
}
+// AddRule will add a new rule to an existing security group (whose ID is
+// specified in AddRuleOpts). You have the option of controlling inbound
+// traffic from both an IP range (CIDR) or from another security group.
func AddRule(client *gophercloud.ServiceClient, opts AddRuleOpts) AddRuleResult {
var result AddRuleResult
@@ -159,6 +178,7 @@
return result
}
+// DeleteRule will permanently delete a rule from a security group.
func DeleteRule(client *gophercloud.ServiceClient, id string) gophercloud.ErrResult {
var result gophercloud.ErrResult
@@ -176,6 +196,8 @@
}
}
+// AddServerToGroup will associate a server and a security group, enforcing the
+// rules of the group on the server.
func AddServerToGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
var result gophercloud.ErrResult
@@ -189,6 +211,7 @@
return result
}
+// RemoveServerFromGroup will disassociate a server from a security group.
func RemoveServerFromGroup(client *gophercloud.ServiceClient, serverID, groupName string) gophercloud.ErrResult {
var result gophercloud.ErrResult
diff --git a/openstack/compute/v2/extensions/secgroups/results.go b/openstack/compute/v2/extensions/secgroups/results.go
index 17adf44..8610bd5 100644
--- a/openstack/compute/v2/extensions/secgroups/results.go
+++ b/openstack/compute/v2/extensions/secgroups/results.go
@@ -7,34 +7,62 @@
"github.com/rackspace/gophercloud/pagination"
)
+// SecurityGroup represents a security group.
type SecurityGroup struct {
- ID string
- Name string
+ // The unique ID of the group.
+ ID string
+
+ // The human-readable name of the group, which needs to be unique.
+ Name string
+
+ // The human-readable description of the group.
Description string
- Rules []Rule
- TenantID string `mapstructure:"tenant_id"`
+
+ // The rules which determine how this security group operates.
+ Rules []Rule
+
+ // The ID of the tenant to which this security group belongs to.
+ TenantID string `mapstructure:"tenant_id"`
}
+// Rule represents a security group rule, a policy which determines how a
+// security group operates and what inbound traffic it allows in.
type Rule struct {
- ID string
- FromPort int `mapstructure:"from_port"`
- ToPort int `mapstructure:"to_port"`
- IPProtocol string `mapstructure:"ip_protocol"`
- IPRange IPRange `mapstructure:"ip_range"`
- ParentGroupID string `mapstructure:"parent_group_id"`
- Group Group
+ // The unique ID
+ ID string
+
+ // The lower bound of the port range which this security group should open up
+ FromPort int `mapstructure:"from_port"`
+
+ // The upper bound of the port range which this security group should open up
+ ToPort int `mapstructure:"to_port"`
+
+ // The IP protocol (e.g. TCP) which the security group accepts
+ IPProtocol string `mapstructure:"ip_protocol"`
+
+ // The CIDR IP range whose traffic can be received
+ IPRange IPRange `mapstructure:"ip_range"`
+
+ // The security group ID which this rule belongs to
+ ParentGroupID string `mapstructure:"parent_group_id"`
+
+ // Not documented.
+ Group Group
}
+// IPRange represents the IP range whose traffic will be accepted by the
+// security group.
type IPRange struct {
CIDR string
}
+// Group represents a group.
type Group struct {
TenantID string `mapstructure:"tenant_id"`
Name string
}
-// RolePage is a single page of a user Role collection.
+// SecurityGroupPage is a single page of a SecurityGroup collection.
type SecurityGroupPage struct {
pagination.SinglePageBase
}
@@ -63,14 +91,17 @@
gophercloud.Result
}
+// CreateResult represents the result of a create operation.
type CreateResult struct {
commonResult
}
+// GetResult represents the result of a get operation.
type GetResult struct {
commonResult
}
+// UpdateResult represents the result of an update operation.
type UpdateResult struct {
commonResult
}
@@ -89,10 +120,12 @@
return &response.SecurityGroup, err
}
+// AddRuleResult represents the result when adding rules to a security group.
type AddRuleResult struct {
gophercloud.Result
}
+// Extract will extract a Rule struct from an AddResultRule.
func (r AddRuleResult) Extract() (*Rule, error) {
if r.Err != nil {
return nil, r.Err