github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/flowlogs/requests.go (about) 1 package flowlogs 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/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 return q.String(), err 55 } 56 57 // List returns a Pager which allows you to iterate over a collection of 58 // VPC flow logs. It accepts a ListOpts struct, which allows you to filter 59 // and sort the returned collection for greater efficiency. 60 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 61 url := listURL(client) 62 if opts != nil { 63 query, err := opts.ToFlowLogsListQuery() 64 if err != nil { 65 return pagination.Pager{Err: err} 66 } 67 url += query 68 } 69 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 70 return FlowLogPage{pagination.LinkedPageBase{PageResult: r}} 71 }) 72 } 73 74 type CreateOpts struct { 75 // Specifies the VPC flow log name. The value is a string of no more than 64 76 // characters that can contain letters, digits, underscores (_), hyphens (-) and periods (.). 77 Name string `json:"name,omitempty"` 78 79 // Provides supplementary information about the VPC flow log. 80 // The value is a string of no more than 255 characters and cannot contain angle brackets (< or >). 81 Description string `json:"description,omitempty"` 82 83 // Specifies the type of resource on which to create the VPC flow log. 84 // The value can be Port, VPC, and Network. 85 ResourceType string `json:"resource_type" required:"true"` 86 87 // Specifies the unique resource ID. 88 ResourceID string `json:"resource_id" required:"true"` 89 90 //Specifies the type of traffic to log. The value can be all, accept and reject. 91 TrafficType string `json:"traffic_type" required:"true"` 92 93 // Specifies the log group ID. 94 LogGroupID string `json:"log_group_id" required:"true"` 95 96 // Specifies the log topic ID. 97 LogTopicID string `json:"log_topic_id" required:"true"` 98 } 99 100 type CreateOptsBuilder interface { 101 ToCreateMap() (map[string]interface{}, error) 102 } 103 104 func (opts CreateOpts) ToCreateMap() (map[string]interface{}, error) { 105 b, err := golangsdk.BuildRequestBody(opts, "flow_log") 106 if err != nil { 107 return nil, err 108 } 109 return b, nil 110 } 111 112 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 113 b, err := opts.ToCreateMap() 114 if err != nil { 115 r.Err = err 116 return 117 } 118 119 _, r.Err = client.Post(CreateURL(client), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 120 return 121 } 122 123 func Delete(client *golangsdk.ServiceClient, flId string) (r DeleteResult) { 124 url := DeleteURL(client, flId) 125 _, r.Err = client.Delete(url, nil) 126 return 127 } 128 129 func Get(client *golangsdk.ServiceClient, flId string) (r GetResult) { 130 url := GetURL(client, flId) 131 _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{}) 132 return 133 } 134 135 type UpdateOpts struct { 136 // Specifies the VPC flow log name. The value is a string of no more than 64 137 // characters that can contain letters, digits, underscores (_), hyphens (-) and periods (.). 138 Name string `json:"name,omitempty"` 139 140 // Provides supplementary information about the VPC flow log. 141 // The value is a string of no more than 255 characters and cannot contain angle brackets (< or >). 142 Description string `json:"description,omitempty"` 143 144 // Specifies whether to enable the VPC flow log function. 145 AdminState bool `json:"admin_state"` 146 } 147 148 type UpdateOptsBuilder interface { 149 ToUpdateMap() (map[string]interface{}, error) 150 } 151 152 func (opts UpdateOpts) ToUpdateMap() (map[string]interface{}, error) { 153 b, err := golangsdk.BuildRequestBody(opts, "flow_log") 154 if err != nil { 155 return nil, err 156 } 157 return b, nil 158 } 159 160 func Update(client *golangsdk.ServiceClient, flId string, opts UpdateOptsBuilder) (r UpdateResult) { 161 b, err := opts.ToUpdateMap() 162 if err != nil { 163 r.Err = err 164 return 165 } 166 167 _, r.Err = client.Put(UpdateURL(client, flId), b, &r.Body, &golangsdk.RequestOpts{OkCodes: []int{200}}) 168 return 169 }