github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v1/flowlogs/requests.go (about)

     1  package flowlogs
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the
     9  // List request.
    10  type ListOptsBuilder interface {
    11  	ToFlowLogsListQuery() (string, error)
    12  }
    13  
    14  // ListOpts allows the filtering and sorting of paginated collections through
    15  // the API. Filtering is achieved by passing in struct field values that map to
    16  // the subnet attributes you want to see returned.
    17  type ListOpts struct {
    18  	// Specifies the VPC flow log UUID.
    19  	ID string `q:"id"`
    20  
    21  	// Specifies the VPC flow log name.
    22  	Name string `q:"name"`
    23  
    24  	// Specifies the type of resource on which to create the VPC flow log..
    25  	ResourceType string `q:"resource_type"`
    26  
    27  	// Specifies the unique resource ID.
    28  	ResourceID string `q:"resource_id"`
    29  
    30  	// Specifies the type of traffic to log.
    31  	TrafficType string `q:"traffic_type"`
    32  
    33  	// Specifies the log group ID..
    34  	LogGroupID string `q:"log_group_id"`
    35  
    36  	// Specifies the log topic ID.
    37  	LogTopicID string `q:"log_topic_id"`
    38  
    39  	// Specifies the VPC flow log status, the value can be ACTIVE, DOWN or ERROR.
    40  	Status string `q:"status"`
    41  
    42  	// Specifies the number of records returned on each page.
    43  	// The value ranges from 0 to intmax.
    44  	Limit int `q:"limit"`
    45  
    46  	// Specifies the resource ID of pagination query.
    47  	// If the parameter is left blank, only resources on the first page are queried.
    48  	Marker string `q:"marker"`
    49  }
    50  
    51  // ToFlowLogsListQuery formats a ListOpts into a query string.
    52  func (opts ListOpts) ToFlowLogsListQuery() (string, error) {
    53  	q, err := golangsdk.BuildQueryString(opts)
    54  	if err != nil {
    55  		return "", err
    56  	}
    57  	return q.String(), err
    58  }
    59  
    60  // List returns a Pager which allows you to iterate over a collection of
    61  // VPC flow logs. It accepts a ListOpts struct, which allows you to filter
    62  //  and sort the returned collection for greater efficiency.
    63  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    64  	url := listURL(client)
    65  	if opts != nil {
    66  		query, err := opts.ToFlowLogsListQuery()
    67  		if err != nil {
    68  			return pagination.Pager{Err: err}
    69  		}
    70  		url += query
    71  	}
    72  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    73  		return FlowLogPage{pagination.LinkedPageBase{PageResult: r}}
    74  	})
    75  }
    76  
    77  type CreateOpts struct {
    78  	// Specifies the VPC flow log name. The value is a string of no more than 64
    79  	// characters that can contain letters, digits, underscores (_), hyphens (-) and periods (.).
    80  	Name string `json:"name,omitempty"`
    81  
    82  	// Provides supplementary information about the VPC flow log.
    83  	// The value is a string of no more than 255 characters and cannot contain angle brackets (< or >).
    84  	Description string `json:"description,omitempty"`
    85  
    86  	// Specifies the type of resource on which to create the VPC flow log.
    87  	// The value can be Port, VPC, and Network.
    88  	ResourceType string `json:"resource_type" required:"true"`
    89  
    90  	// Specifies the unique resource ID.
    91  	ResourceID string `json:"resource_id" required:"true"`
    92  
    93  	// Specifies the type of traffic to log. The value can be all, accept and reject.
    94  	TrafficType string `json:"traffic_type" required:"true"`
    95  
    96  	// Specifies the log group ID.
    97  	LogGroupID string `json:"log_group_id" required:"true"`
    98  
    99  	// Specifies the log topic ID.
   100  	LogTopicID string `json:"log_topic_id" required:"true"`
   101  }
   102  
   103  type CreateOptsBuilder interface {
   104  	ToCreateMap() (map[string]interface{}, error)
   105  }
   106  
   107  func (opts CreateOpts) ToCreateMap() (map[string]interface{}, error) {
   108  	b, err := golangsdk.BuildRequestBody(opts, "flow_log")
   109  	if err != nil {
   110  		return nil, err
   111  	}
   112  	return b, nil
   113  }
   114  
   115  func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
   116  	b, err := opts.ToCreateMap()
   117  	if err != nil {
   118  		r.Err = err
   119  		return
   120  	}
   121  
   122  	_, r.Err = client.Post(CreateURL(client), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}})
   123  	return
   124  }
   125  
   126  func Delete(client *golangsdk.ServiceClient, flId string) (r DeleteResult) {
   127  	url := DeleteURL(client, flId)
   128  	_, r.Err = client.Delete(url, nil)
   129  	return
   130  }
   131  
   132  func Get(client *golangsdk.ServiceClient, flId string) (r GetResult) {
   133  	url := GetURL(client, flId)
   134  	_, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{})
   135  	return
   136  }
   137  
   138  type UpdateOpts struct {
   139  	// Specifies the VPC flow log name. The value is a string of no more than 64
   140  	// characters that can contain letters, digits, underscores (_), hyphens (-) and periods (.).
   141  	Name string `json:"name,omitempty"`
   142  
   143  	// Provides supplementary information about the VPC flow log.
   144  	// The value is a string of no more than 255 characters and cannot contain angle brackets (< or >).
   145  	Description string `json:"description,omitempty"`
   146  
   147  	// Specifies whether to enable the VPC flow log function.
   148  	AdminState bool `json:"admin_state"`
   149  }
   150  
   151  type UpdateOptsBuilder interface {
   152  	ToUpdateMap() (map[string]interface{}, error)
   153  }
   154  
   155  func (opts UpdateOpts) ToUpdateMap() (map[string]interface{}, error) {
   156  	b, err := golangsdk.BuildRequestBody(opts, "flow_log")
   157  	if err != nil {
   158  		return nil, err
   159  	}
   160  	return b, nil
   161  }
   162  
   163  func Update(client *golangsdk.ServiceClient, flId string, opts UpdateOptsBuilder) (r UpdateResult) {
   164  	b, err := opts.ToUpdateMap()
   165  	if err != nil {
   166  		r.Err = err
   167  		return
   168  	}
   169  
   170  	_, r.Err = client.Put(UpdateURL(client, flId), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}})
   171  	return
   172  }