diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/client.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/client.go new file mode 100644 index 000000000000..ce4e0072c9f4 --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/client.go @@ -0,0 +1,50 @@ +// Package workloadmonitor implements the Azure ARM Workloadmonitor service API version 2020-01-13-preview. +// +// Workload Monitor API +package workloadmonitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Workloadmonitor + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Workloadmonitor. +type BaseClient struct { + autorest.Client + BaseURI string +} + +// New creates an instance of the BaseClient client. +func New() BaseClient { + return NewWithBaseURI(DefaultBaseURI) +} + +// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with +// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewWithBaseURI(baseURI string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + } +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/enums.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/enums.go new file mode 100644 index 000000000000..f7ce455716c0 --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/enums.go @@ -0,0 +1,37 @@ +package workloadmonitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// HealthState enumerates the values for health state. +type HealthState string + +const ( + // Critical ... + Critical HealthState = "Critical" + // Healthy ... + Healthy HealthState = "Healthy" + // Unknown ... + Unknown HealthState = "Unknown" + // Warning ... + Warning HealthState = "Warning" +) + +// PossibleHealthStateValues returns an array of possible values for the HealthState const type. +func PossibleHealthStateValues() []HealthState { + return []HealthState{Critical, Healthy, Unknown, Warning} +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/models.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/models.go new file mode 100644 index 000000000000..b8e463e51779 --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/models.go @@ -0,0 +1,746 @@ +package workloadmonitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor" + +// DefaultError error body contract. +type DefaultError struct { + // Error - Details about the error + Error *DefaultErrorError `json:"error,omitempty"` +} + +// DefaultErrorError details about the error +type DefaultErrorError struct { + // Code - Service-defined error code. This code serves as a sub-status for the HTTP error code specified in the response. + Code *string `json:"code,omitempty"` + // Message - Human-readable representation of the error. + Message *string `json:"message,omitempty"` + // Details - Details of the error. + Details *[]ErrorDetails `json:"details,omitempty"` +} + +// ErrorDetails error details of the error body contract. +type ErrorDetails struct { + // Code - Property level error code. + Code *string `json:"code,omitempty"` + // Message - Human-readable representation of property-level error. + Message *string `json:"message,omitempty"` +} + +// Monitor information about a monitor. +type Monitor struct { + autorest.Response `json:"-"` + *MonitorProperties `json:"properties,omitempty"` + // ID - READ-ONLY; Arm ID of this monitor. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Url-encoded monitor name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Type of ARM resource. + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for Monitor. +func (mVar Monitor) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mVar.MonitorProperties != nil { + objectMap["properties"] = mVar.MonitorProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Monitor struct. +func (mVar *Monitor) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var monitorProperties MonitorProperties + err = json.Unmarshal(*v, &monitorProperties) + if err != nil { + return err + } + mVar.MonitorProperties = &monitorProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + mVar.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + mVar.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + mVar.Type = &typeVar + } + } + } + + return nil +} + +// MonitorList basic information about the current status of a monitor. +type MonitorList struct { + autorest.Response `json:"-"` + // Value - Array of monitors. + Value *[]Monitor `json:"value,omitempty"` + // NextLink - Link to next page if list is too long. + NextLink *string `json:"nextLink,omitempty"` +} + +// MonitorListIterator provides access to a complete listing of Monitor values. +type MonitorListIterator struct { + i int + page MonitorListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *MonitorListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *MonitorListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter MonitorListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter MonitorListIterator) Response() MonitorList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter MonitorListIterator) Value() Monitor { + if !iter.page.NotDone() { + return Monitor{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the MonitorListIterator type. +func NewMonitorListIterator(page MonitorListPage) MonitorListIterator { + return MonitorListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ml MonitorList) IsEmpty() bool { + return ml.Value == nil || len(*ml.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (ml MonitorList) hasNextLink() bool { + return ml.NextLink != nil && len(*ml.NextLink) != 0 +} + +// monitorListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ml MonitorList) monitorListPreparer(ctx context.Context) (*http.Request, error) { + if !ml.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ml.NextLink))) +} + +// MonitorListPage contains a page of Monitor values. +type MonitorListPage struct { + fn func(context.Context, MonitorList) (MonitorList, error) + ml MonitorList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *MonitorListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.ml) + if err != nil { + return err + } + page.ml = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *MonitorListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page MonitorListPage) NotDone() bool { + return !page.ml.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page MonitorListPage) Response() MonitorList { + return page.ml +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page MonitorListPage) Values() []Monitor { + if page.ml.IsEmpty() { + return nil + } + return *page.ml.Value +} + +// Creates a new instance of the MonitorListPage type. +func NewMonitorListPage(getNextPage func(context.Context, MonitorList) (MonitorList, error)) MonitorListPage { + return MonitorListPage{fn: getNextPage} +} + +// MonitorProperties properties of the monitor. +type MonitorProperties struct { + // MonitorName - Human-readable name of this monitor. + MonitorName *string `json:"monitorName,omitempty"` + // MonitorType - Type of this monitor. + MonitorType *string `json:"monitorType,omitempty"` + // MonitoredObject - Dynamic monitored object of this monitor. + MonitoredObject *string `json:"monitoredObject,omitempty"` + // ParentMonitorName - Name of this monitor's parent. + ParentMonitorName *string `json:"parentMonitorName,omitempty"` + // PreviousMonitorState - Current health state of this monitor. Possible values include: 'Healthy', 'Critical', 'Warning', 'Unknown' + PreviousMonitorState HealthState `json:"previousMonitorState,omitempty"` + // CurrentMonitorState - Current health state of this monitor. Possible values include: 'Healthy', 'Critical', 'Warning', 'Unknown' + CurrentMonitorState HealthState `json:"currentMonitorState,omitempty"` + // EvaluationTimestamp - Timestamp that this monitor was last evaluated. + EvaluationTimestamp *string `json:"evaluationTimestamp,omitempty"` + // CurrentStateFirstObservedTimestamp - Timestamp of this monitor's last state change. + CurrentStateFirstObservedTimestamp *string `json:"currentStateFirstObservedTimestamp,omitempty"` + // LastReportedTimestamp - Timestamp of this monitor's last reported state. + LastReportedTimestamp *string `json:"lastReportedTimestamp,omitempty"` + // Evidence - Evidence of this monitor's last state change. + Evidence interface{} `json:"evidence,omitempty"` + // MonitorConfiguration - Configuration settings at the time of this monitor's last state change. + MonitorConfiguration interface{} `json:"monitorConfiguration,omitempty"` +} + +// MonitorStateChange information about a state transition of a monitor. +type MonitorStateChange struct { + autorest.Response `json:"-"` + *MonitorStateChangeProperties `json:"properties,omitempty"` + // ID - READ-ONLY; Arm ID of this monitor. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Url-encoded monitor name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Type of ARM resource. + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for MonitorStateChange. +func (msc MonitorStateChange) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if msc.MonitorStateChangeProperties != nil { + objectMap["properties"] = msc.MonitorStateChangeProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for MonitorStateChange struct. +func (msc *MonitorStateChange) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var monitorStateChangeProperties MonitorStateChangeProperties + err = json.Unmarshal(*v, &monitorStateChangeProperties) + if err != nil { + return err + } + msc.MonitorStateChangeProperties = &monitorStateChangeProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + msc.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + msc.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + msc.Type = &typeVar + } + } + } + + return nil +} + +// MonitorStateChangeList the monitor history of a monitor +type MonitorStateChangeList struct { + autorest.Response `json:"-"` + // Value - Array of state change transitions. + Value *[]MonitorStateChange `json:"value,omitempty"` + // NextLink - Link to next page if list is too long. + NextLink *string `json:"nextLink,omitempty"` +} + +// MonitorStateChangeListIterator provides access to a complete listing of MonitorStateChange values. +type MonitorStateChangeListIterator struct { + i int + page MonitorStateChangeListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *MonitorStateChangeListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorStateChangeListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *MonitorStateChangeListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter MonitorStateChangeListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter MonitorStateChangeListIterator) Response() MonitorStateChangeList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter MonitorStateChangeListIterator) Value() MonitorStateChange { + if !iter.page.NotDone() { + return MonitorStateChange{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the MonitorStateChangeListIterator type. +func NewMonitorStateChangeListIterator(page MonitorStateChangeListPage) MonitorStateChangeListIterator { + return MonitorStateChangeListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (mscl MonitorStateChangeList) IsEmpty() bool { + return mscl.Value == nil || len(*mscl.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (mscl MonitorStateChangeList) hasNextLink() bool { + return mscl.NextLink != nil && len(*mscl.NextLink) != 0 +} + +// monitorStateChangeListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (mscl MonitorStateChangeList) monitorStateChangeListPreparer(ctx context.Context) (*http.Request, error) { + if !mscl.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(mscl.NextLink))) +} + +// MonitorStateChangeListPage contains a page of MonitorStateChange values. +type MonitorStateChangeListPage struct { + fn func(context.Context, MonitorStateChangeList) (MonitorStateChangeList, error) + mscl MonitorStateChangeList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *MonitorStateChangeListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorStateChangeListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.mscl) + if err != nil { + return err + } + page.mscl = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *MonitorStateChangeListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page MonitorStateChangeListPage) NotDone() bool { + return !page.mscl.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page MonitorStateChangeListPage) Response() MonitorStateChangeList { + return page.mscl +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page MonitorStateChangeListPage) Values() []MonitorStateChange { + if page.mscl.IsEmpty() { + return nil + } + return *page.mscl.Value +} + +// Creates a new instance of the MonitorStateChangeListPage type. +func NewMonitorStateChangeListPage(getNextPage func(context.Context, MonitorStateChangeList) (MonitorStateChangeList, error)) MonitorStateChangeListPage { + return MonitorStateChangeListPage{fn: getNextPage} +} + +// MonitorStateChangeProperties properties of the monitor. +type MonitorStateChangeProperties struct { + // MonitorName - Human-readable name of this monitor. + MonitorName *string `json:"monitorName,omitempty"` + // MonitorType - Type of this monitor. + MonitorType *string `json:"monitorType,omitempty"` + // MonitoredObject - Dynamic monitored object of this monitor. + MonitoredObject *string `json:"monitoredObject,omitempty"` + // EvaluationTimestamp - Timestamp of that this event ocurred. + EvaluationTimestamp *string `json:"evaluationTimestamp,omitempty"` + // CurrentStateFirstObservedTimestamp - Timestamp of that this health state first ocurred. + CurrentStateFirstObservedTimestamp *string `json:"currentStateFirstObservedTimestamp,omitempty"` + // PreviousMonitorState - Previous health state. Possible values include: 'Healthy', 'Critical', 'Warning', 'Unknown' + PreviousMonitorState HealthState `json:"previousMonitorState,omitempty"` + // CurrentMonitorState - New health state. Possible values include: 'Healthy', 'Critical', 'Warning', 'Unknown' + CurrentMonitorState HealthState `json:"currentMonitorState,omitempty"` + // Evidence - Evidence of this monitor's last state change. + Evidence interface{} `json:"evidence,omitempty"` + // MonitorConfiguration - Configuration settings at the time of this monitor's last state change. + MonitorConfiguration interface{} `json:"monitorConfiguration,omitempty"` +} + +// Operation operation supported by the resource provider. +type Operation struct { + // Name - Name of the operation. + Name *string `json:"name,omitempty"` + // Display - The properties of the resource operation. + Display *OperationDisplay `json:"display,omitempty"` + // Origin - The origin of the operation. + Origin *string `json:"origin,omitempty"` +} + +// OperationDisplay the properties of the resource operation. +type OperationDisplay struct { + // Provider - Provider name of this operation. + Provider *string `json:"provider,omitempty"` + // Resource - Resource name of this operation. + Resource *string `json:"resource,omitempty"` + // Operation - Operation name of the operation. + Operation *string `json:"operation,omitempty"` + // Description - Description of the operation. + Description *string `json:"description,omitempty"` +} + +// OperationList list of possible operations. +type OperationList struct { + autorest.Response `json:"-"` + // Value - Array of possible operations. + Value *[]Operation `json:"value,omitempty"` + // NextLink - Link to next page if list is too long. + NextLink *string `json:"nextLink,omitempty"` +} + +// OperationListIterator provides access to a complete listing of Operation values. +type OperationListIterator struct { + i int + page OperationListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OperationListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *OperationListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OperationListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OperationListIterator) Response() OperationList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OperationListIterator) Value() Operation { + if !iter.page.NotDone() { + return Operation{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the OperationListIterator type. +func NewOperationListIterator(page OperationListPage) OperationListIterator { + return OperationListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ol OperationList) IsEmpty() bool { + return ol.Value == nil || len(*ol.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (ol OperationList) hasNextLink() bool { + return ol.NextLink != nil && len(*ol.NextLink) != 0 +} + +// operationListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ol OperationList) operationListPreparer(ctx context.Context) (*http.Request, error) { + if !ol.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ol.NextLink))) +} + +// OperationListPage contains a page of Operation values. +type OperationListPage struct { + fn func(context.Context, OperationList) (OperationList, error) + ol OperationList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OperationListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.ol) + if err != nil { + return err + } + page.ol = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *OperationListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OperationListPage) NotDone() bool { + return !page.ol.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OperationListPage) Response() OperationList { + return page.ol +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OperationListPage) Values() []Operation { + if page.ol.IsEmpty() { + return nil + } + return *page.ol.Value +} + +// Creates a new instance of the OperationListPage type. +func NewOperationListPage(getNextPage func(context.Context, OperationList) (OperationList, error)) OperationListPage { + return OperationListPage{fn: getNextPage} +} + +// Resource the resource model definition for the ARM proxy resource, 'microsoft.workloadmonitor/monitors'. +type Resource struct { + // ID - READ-ONLY; Arm ID of this monitor. + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; Url-encoded monitor name. + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; Type of ARM resource. + Type *string `json:"type,omitempty"` +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/monitors.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/monitors.go new file mode 100644 index 000000000000..fbeeedb3798f --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/monitors.go @@ -0,0 +1,487 @@ +package workloadmonitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// MonitorsClient is the workload Monitor API +type MonitorsClient struct { + BaseClient +} + +// NewMonitorsClient creates an instance of the MonitorsClient client. +func NewMonitorsClient() MonitorsClient { + return NewMonitorsClientWithBaseURI(DefaultBaseURI) +} + +// NewMonitorsClientWithBaseURI creates an instance of the MonitorsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewMonitorsClientWithBaseURI(baseURI string) MonitorsClient { + return MonitorsClient{NewWithBaseURI(baseURI)} +} + +// Get sends the get request. +// Parameters: +// subscriptionID - the subscriptionId of the resource +// resourceGroupName - the resourceGroupName of the resource +// resourceNamespace - the resourceNamespace of the resource +// resourceType - the resourceType of the resource +// resourceName - the resourceType of the resource +// monitorID - the monitorId of the resource (url encoded) +// expand - ex: $expand=evidence,configuration +func (client MonitorsClient) Get(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, expand string) (result Monitor, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, monitorID, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client MonitorsClient) GetPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, expand string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "monitorId": autorest.Encode("path", monitorID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "resourceNamespace": autorest.Encode("path", resourceNamespace), + "resourceType": autorest.Encode("path", resourceType), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2020-01-13-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client MonitorsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client MonitorsClient) GetResponder(resp *http.Response) (result Monitor, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetStateChange sends the get state change request. +// Parameters: +// subscriptionID - the subscriptionId of the resource +// resourceGroupName - the resourceGroupName of the resource +// resourceNamespace - the resourceNamespace of the resource +// resourceType - the resourceType of the resource +// resourceName - the resourceType of the resource +// monitorID - the monitorId of the resource (url encoded) +// timestampUnix - the timestamp of the state change (Unix format) +// expand - ex: $expand=evidence,configuration +func (client MonitorsClient) GetStateChange(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, timestampUnix string, expand string) (result MonitorStateChange, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.GetStateChange") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetStateChangePreparer(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, monitorID, timestampUnix, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "GetStateChange", nil, "Failure preparing request") + return + } + + resp, err := client.GetStateChangeSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "GetStateChange", resp, "Failure sending request") + return + } + + result, err = client.GetStateChangeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "GetStateChange", resp, "Failure responding to request") + } + + return +} + +// GetStateChangePreparer prepares the GetStateChange request. +func (client MonitorsClient) GetStateChangePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, timestampUnix string, expand string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "monitorId": autorest.Encode("path", monitorID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "resourceNamespace": autorest.Encode("path", resourceNamespace), + "resourceType": autorest.Encode("path", resourceType), + "subscriptionId": autorest.Encode("path", subscriptionID), + "timestampUnix": autorest.Encode("path", timestampUnix), + } + + const APIVersion = "2020-01-13-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetStateChangeSender sends the GetStateChange request. The method will close the +// http.Response Body if it receives an error. +func (client MonitorsClient) GetStateChangeSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetStateChangeResponder handles the response to the GetStateChange request. The method always +// closes the http.Response Body. +func (client MonitorsClient) GetStateChangeResponder(resp *http.Response) (result MonitorStateChange, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List sends the list request. +// Parameters: +// subscriptionID - the subscriptionId of the resource +// resourceGroupName - the resourceGroupName of the resource +// resourceNamespace - the resourceNamespace of the resource +// resourceType - the resourceType of the resource +// resourceName - the resourceType of the resource +// filter - list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; history example: +// $filter=isHeartbeat eq false +// expand - ex: $expand=evidence,configuration +func (client MonitorsClient) List(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, filter string, expand string) (result MonitorListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.List") + defer func() { + sc := -1 + if result.ml.Response.Response != nil { + sc = result.ml.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, filter, expand) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.ml.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "List", resp, "Failure sending request") + return + } + + result.ml, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "List", resp, "Failure responding to request") + } + if result.ml.hasNextLink() && result.ml.IsEmpty() { + err = result.NextWithContext(ctx) + } + + return +} + +// ListPreparer prepares the List request. +func (client MonitorsClient) ListPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, filter string, expand string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "resourceNamespace": autorest.Encode("path", resourceNamespace), + "resourceType": autorest.Encode("path", resourceType), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2020-01-13-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client MonitorsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client MonitorsClient) ListResponder(resp *http.Response) (result MonitorList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client MonitorsClient) listNextResults(ctx context.Context, lastResults MonitorList) (result MonitorList, err error) { + req, err := lastResults.monitorListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client MonitorsClient) ListComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, filter string, expand string) (result MonitorListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, filter, expand) + return +} + +// ListStateChanges sends the list state changes request. +// Parameters: +// subscriptionID - the subscriptionId of the resource +// resourceGroupName - the resourceGroupName of the resource +// resourceNamespace - the resourceNamespace of the resource +// resourceType - the resourceType of the resource +// resourceName - the resourceType of the resource +// monitorID - the monitorId of the resource (url encoded) +// filter - list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; history example: +// $filter=isHeartbeat eq false +// expand - ex: $expand=evidence,configuration +// startTimestampUtc - the start Timestamp for the desired history +// endTimestampUtc - the end Timestamp for the desired history +func (client MonitorsClient) ListStateChanges(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, filter string, expand string, startTimestampUtc *date.Time, endTimestampUtc *date.Time) (result MonitorStateChangeListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.ListStateChanges") + defer func() { + sc := -1 + if result.mscl.Response.Response != nil { + sc = result.mscl.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listStateChangesNextResults + req, err := client.ListStateChangesPreparer(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, monitorID, filter, expand, startTimestampUtc, endTimestampUtc) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "ListStateChanges", nil, "Failure preparing request") + return + } + + resp, err := client.ListStateChangesSender(req) + if err != nil { + result.mscl.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "ListStateChanges", resp, "Failure sending request") + return + } + + result.mscl, err = client.ListStateChangesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "ListStateChanges", resp, "Failure responding to request") + } + if result.mscl.hasNextLink() && result.mscl.IsEmpty() { + err = result.NextWithContext(ctx) + } + + return +} + +// ListStateChangesPreparer prepares the ListStateChanges request. +func (client MonitorsClient) ListStateChangesPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, filter string, expand string, startTimestampUtc *date.Time, endTimestampUtc *date.Time) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "monitorId": autorest.Encode("path", monitorID), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "resourceNamespace": autorest.Encode("path", resourceNamespace), + "resourceType": autorest.Encode("path", resourceType), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2020-01-13-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if startTimestampUtc != nil { + queryParameters["startTimestampUtc"] = autorest.Encode("query", *startTimestampUtc) + } + if endTimestampUtc != nil { + queryParameters["endTimestampUtc"] = autorest.Encode("query", *endTimestampUtc) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListStateChangesSender sends the ListStateChanges request. The method will close the +// http.Response Body if it receives an error. +func (client MonitorsClient) ListStateChangesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListStateChangesResponder handles the response to the ListStateChanges request. The method always +// closes the http.Response Body. +func (client MonitorsClient) ListStateChangesResponder(resp *http.Response) (result MonitorStateChangeList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listStateChangesNextResults retrieves the next set of results, if any. +func (client MonitorsClient) listStateChangesNextResults(ctx context.Context, lastResults MonitorStateChangeList) (result MonitorStateChangeList, err error) { + req, err := lastResults.monitorStateChangeListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listStateChangesNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListStateChangesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listStateChangesNextResults", resp, "Failure sending next results request") + } + result, err = client.ListStateChangesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorsClient", "listStateChangesNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListStateChangesComplete enumerates all values, automatically crossing page boundaries as required. +func (client MonitorsClient) ListStateChangesComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, filter string, expand string, startTimestampUtc *date.Time, endTimestampUtc *date.Time) (result MonitorStateChangeListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/MonitorsClient.ListStateChanges") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListStateChanges(ctx, subscriptionID, resourceGroupName, resourceNamespace, resourceType, resourceName, monitorID, filter, expand, startTimestampUtc, endTimestampUtc) + return +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/operations.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/operations.go new file mode 100644 index 000000000000..b52f030367f2 --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/operations.go @@ -0,0 +1,149 @@ +package workloadmonitor + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OperationsClient is the workload Monitor API +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient() OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewOperationsClientWithBaseURI(baseURI string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI)} +} + +// List sends the list request. +func (client OperationsClient) List(ctx context.Context) (result OperationListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.ol.Response.Response != nil { + sc = result.ol.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.ol.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "List", resp, "Failure sending request") + return + } + + result.ol, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "List", resp, "Failure responding to request") + } + if result.ol.hasNextLink() && result.ol.IsEmpty() { + err = result.NextWithContext(ctx) + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2020-01-13-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.WorkloadMonitor/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationList) (result OperationList, err error) { + req, err := lastResults.operationListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.OperationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx) + return +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/version.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/version.go new file mode 100644 index 000000000000..9b759d093c85 --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/version.go @@ -0,0 +1,30 @@ +package workloadmonitor + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + Version() + " workloadmonitor/2020-01-13-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/workloadmonitorapi/interfaces.go b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/workloadmonitorapi/interfaces.go new file mode 100644 index 000000000000..2c6109af12bb --- /dev/null +++ b/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor/workloadmonitorapi/interfaces.go @@ -0,0 +1,44 @@ +package workloadmonitorapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/services/preview/workloadmonitor/mgmt/2020-01-13-preview/workloadmonitor" + "github.com/Azure/go-autorest/autorest/date" +) + +// OperationsClientAPI contains the set of methods on the OperationsClient type. +type OperationsClientAPI interface { + List(ctx context.Context) (result workloadmonitor.OperationListPage, err error) + ListComplete(ctx context.Context) (result workloadmonitor.OperationListIterator, err error) +} + +var _ OperationsClientAPI = (*workloadmonitor.OperationsClient)(nil) + +// MonitorsClientAPI contains the set of methods on the MonitorsClient type. +type MonitorsClientAPI interface { + Get(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, expand string) (result workloadmonitor.Monitor, err error) + GetStateChange(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, timestampUnix string, expand string) (result workloadmonitor.MonitorStateChange, err error) + List(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, filter string, expand string) (result workloadmonitor.MonitorListPage, err error) + ListComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, filter string, expand string) (result workloadmonitor.MonitorListIterator, err error) + ListStateChanges(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, filter string, expand string, startTimestampUtc *date.Time, endTimestampUtc *date.Time) (result workloadmonitor.MonitorStateChangeListPage, err error) + ListStateChangesComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, monitorID string, filter string, expand string, startTimestampUtc *date.Time, endTimestampUtc *date.Time) (result workloadmonitor.MonitorStateChangeListIterator, err error) +} + +var _ MonitorsClientAPI = (*workloadmonitor.MonitorsClient)(nil)