github.com/digitalocean/go-netbox@v0.0.2/netbox/models/circuit_circuit_termination.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright 2020 The go-netbox Authors.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //   http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  //
    17  
    18  package models
    19  
    20  // This file was generated by the swagger tool.
    21  // Editing this file might prove futile when you re-run the swagger generate command
    22  
    23  import (
    24  	"context"
    25  
    26  	"github.com/go-openapi/errors"
    27  	"github.com/go-openapi/strfmt"
    28  	"github.com/go-openapi/swag"
    29  	"github.com/go-openapi/validate"
    30  )
    31  
    32  // CircuitCircuitTermination circuit circuit termination
    33  //
    34  // swagger:model CircuitCircuitTermination
    35  type CircuitCircuitTermination struct {
    36  
    37  	// Display
    38  	// Read Only: true
    39  	Display string `json:"display,omitempty"`
    40  
    41  	// Id
    42  	// Read Only: true
    43  	ID int64 `json:"id,omitempty"`
    44  
    45  	// Port speed (Kbps)
    46  	// Maximum: 2.147483647e+09
    47  	// Minimum: 0
    48  	PortSpeed *int64 `json:"port_speed,omitempty"`
    49  
    50  	// provider network
    51  	// Required: true
    52  	ProviderNetwork *NestedProviderNetwork `json:"provider_network"`
    53  
    54  	// site
    55  	// Required: true
    56  	Site *NestedSite `json:"site"`
    57  
    58  	// Upstream speed (Kbps)
    59  	//
    60  	// Upstream speed, if different from port speed
    61  	// Maximum: 2.147483647e+09
    62  	// Minimum: 0
    63  	UpstreamSpeed *int64 `json:"upstream_speed,omitempty"`
    64  
    65  	// Url
    66  	// Read Only: true
    67  	// Format: uri
    68  	URL strfmt.URI `json:"url,omitempty"`
    69  
    70  	// Cross-connect ID
    71  	// Max Length: 50
    72  	XconnectID string `json:"xconnect_id,omitempty"`
    73  }
    74  
    75  // Validate validates this circuit circuit termination
    76  func (m *CircuitCircuitTermination) Validate(formats strfmt.Registry) error {
    77  	var res []error
    78  
    79  	if err := m.validatePortSpeed(formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	if err := m.validateProviderNetwork(formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	if err := m.validateSite(formats); err != nil {
    88  		res = append(res, err)
    89  	}
    90  
    91  	if err := m.validateUpstreamSpeed(formats); err != nil {
    92  		res = append(res, err)
    93  	}
    94  
    95  	if err := m.validateURL(formats); err != nil {
    96  		res = append(res, err)
    97  	}
    98  
    99  	if err := m.validateXconnectID(formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if len(res) > 0 {
   104  		return errors.CompositeValidationError(res...)
   105  	}
   106  	return nil
   107  }
   108  
   109  func (m *CircuitCircuitTermination) validatePortSpeed(formats strfmt.Registry) error {
   110  	if swag.IsZero(m.PortSpeed) { // not required
   111  		return nil
   112  	}
   113  
   114  	if err := validate.MinimumInt("port_speed", "body", *m.PortSpeed, 0, false); err != nil {
   115  		return err
   116  	}
   117  
   118  	if err := validate.MaximumInt("port_speed", "body", *m.PortSpeed, 2.147483647e+09, false); err != nil {
   119  		return err
   120  	}
   121  
   122  	return nil
   123  }
   124  
   125  func (m *CircuitCircuitTermination) validateProviderNetwork(formats strfmt.Registry) error {
   126  
   127  	if err := validate.Required("provider_network", "body", m.ProviderNetwork); err != nil {
   128  		return err
   129  	}
   130  
   131  	if m.ProviderNetwork != nil {
   132  		if err := m.ProviderNetwork.Validate(formats); err != nil {
   133  			if ve, ok := err.(*errors.Validation); ok {
   134  				return ve.ValidateName("provider_network")
   135  			} else if ce, ok := err.(*errors.CompositeError); ok {
   136  				return ce.ValidateName("provider_network")
   137  			}
   138  			return err
   139  		}
   140  	}
   141  
   142  	return nil
   143  }
   144  
   145  func (m *CircuitCircuitTermination) validateSite(formats strfmt.Registry) error {
   146  
   147  	if err := validate.Required("site", "body", m.Site); err != nil {
   148  		return err
   149  	}
   150  
   151  	if m.Site != nil {
   152  		if err := m.Site.Validate(formats); err != nil {
   153  			if ve, ok := err.(*errors.Validation); ok {
   154  				return ve.ValidateName("site")
   155  			} else if ce, ok := err.(*errors.CompositeError); ok {
   156  				return ce.ValidateName("site")
   157  			}
   158  			return err
   159  		}
   160  	}
   161  
   162  	return nil
   163  }
   164  
   165  func (m *CircuitCircuitTermination) validateUpstreamSpeed(formats strfmt.Registry) error {
   166  	if swag.IsZero(m.UpstreamSpeed) { // not required
   167  		return nil
   168  	}
   169  
   170  	if err := validate.MinimumInt("upstream_speed", "body", *m.UpstreamSpeed, 0, false); err != nil {
   171  		return err
   172  	}
   173  
   174  	if err := validate.MaximumInt("upstream_speed", "body", *m.UpstreamSpeed, 2.147483647e+09, false); err != nil {
   175  		return err
   176  	}
   177  
   178  	return nil
   179  }
   180  
   181  func (m *CircuitCircuitTermination) validateURL(formats strfmt.Registry) error {
   182  	if swag.IsZero(m.URL) { // not required
   183  		return nil
   184  	}
   185  
   186  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   187  		return err
   188  	}
   189  
   190  	return nil
   191  }
   192  
   193  func (m *CircuitCircuitTermination) validateXconnectID(formats strfmt.Registry) error {
   194  	if swag.IsZero(m.XconnectID) { // not required
   195  		return nil
   196  	}
   197  
   198  	if err := validate.MaxLength("xconnect_id", "body", m.XconnectID, 50); err != nil {
   199  		return err
   200  	}
   201  
   202  	return nil
   203  }
   204  
   205  // ContextValidate validate this circuit circuit termination based on the context it is used
   206  func (m *CircuitCircuitTermination) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   207  	var res []error
   208  
   209  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   210  		res = append(res, err)
   211  	}
   212  
   213  	if err := m.contextValidateID(ctx, formats); err != nil {
   214  		res = append(res, err)
   215  	}
   216  
   217  	if err := m.contextValidateProviderNetwork(ctx, formats); err != nil {
   218  		res = append(res, err)
   219  	}
   220  
   221  	if err := m.contextValidateSite(ctx, formats); err != nil {
   222  		res = append(res, err)
   223  	}
   224  
   225  	if err := m.contextValidateURL(ctx, formats); err != nil {
   226  		res = append(res, err)
   227  	}
   228  
   229  	if len(res) > 0 {
   230  		return errors.CompositeValidationError(res...)
   231  	}
   232  	return nil
   233  }
   234  
   235  func (m *CircuitCircuitTermination) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   236  
   237  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   238  		return err
   239  	}
   240  
   241  	return nil
   242  }
   243  
   244  func (m *CircuitCircuitTermination) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   245  
   246  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   247  		return err
   248  	}
   249  
   250  	return nil
   251  }
   252  
   253  func (m *CircuitCircuitTermination) contextValidateProviderNetwork(ctx context.Context, formats strfmt.Registry) error {
   254  
   255  	if m.ProviderNetwork != nil {
   256  		if err := m.ProviderNetwork.ContextValidate(ctx, formats); err != nil {
   257  			if ve, ok := err.(*errors.Validation); ok {
   258  				return ve.ValidateName("provider_network")
   259  			} else if ce, ok := err.(*errors.CompositeError); ok {
   260  				return ce.ValidateName("provider_network")
   261  			}
   262  			return err
   263  		}
   264  	}
   265  
   266  	return nil
   267  }
   268  
   269  func (m *CircuitCircuitTermination) contextValidateSite(ctx context.Context, formats strfmt.Registry) error {
   270  
   271  	if m.Site != nil {
   272  		if err := m.Site.ContextValidate(ctx, formats); err != nil {
   273  			if ve, ok := err.(*errors.Validation); ok {
   274  				return ve.ValidateName("site")
   275  			} else if ce, ok := err.(*errors.CompositeError); ok {
   276  				return ce.ValidateName("site")
   277  			}
   278  			return err
   279  		}
   280  	}
   281  
   282  	return nil
   283  }
   284  
   285  func (m *CircuitCircuitTermination) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   286  
   287  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   288  		return err
   289  	}
   290  
   291  	return nil
   292  }
   293  
   294  // MarshalBinary interface implementation
   295  func (m *CircuitCircuitTermination) MarshalBinary() ([]byte, error) {
   296  	if m == nil {
   297  		return nil, nil
   298  	}
   299  	return swag.WriteJSON(m)
   300  }
   301  
   302  // UnmarshalBinary interface implementation
   303  func (m *CircuitCircuitTermination) UnmarshalBinary(b []byte) error {
   304  	var res CircuitCircuitTermination
   305  	if err := swag.ReadJSON(b, &res); err != nil {
   306  		return err
   307  	}
   308  	*m = res
   309  	return nil
   310  }