github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_device_with_config_context.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  	"encoding/json"
    26  	"strconv"
    27  
    28  	"github.com/go-openapi/errors"
    29  	"github.com/go-openapi/strfmt"
    30  	"github.com/go-openapi/swag"
    31  	"github.com/go-openapi/validate"
    32  )
    33  
    34  // WritableDeviceWithConfigContext writable device with config context
    35  //
    36  // swagger:model WritableDeviceWithConfigContext
    37  type WritableDeviceWithConfigContext struct {
    38  
    39  	// Asset tag
    40  	//
    41  	// A unique tag used to identify this device
    42  	// Max Length: 50
    43  	AssetTag *string `json:"asset_tag,omitempty"`
    44  
    45  	// Cluster
    46  	Cluster *int64 `json:"cluster,omitempty"`
    47  
    48  	// Comments
    49  	Comments string `json:"comments,omitempty"`
    50  
    51  	// Config context
    52  	// Read Only: true
    53  	ConfigContext map[string]*string `json:"config_context,omitempty"`
    54  
    55  	// Created
    56  	// Read Only: true
    57  	// Format: date
    58  	Created strfmt.Date `json:"created,omitempty"`
    59  
    60  	// Custom fields
    61  	CustomFields interface{} `json:"custom_fields,omitempty"`
    62  
    63  	// Device role
    64  	// Required: true
    65  	DeviceRole *int64 `json:"device_role"`
    66  
    67  	// Device type
    68  	// Required: true
    69  	DeviceType *int64 `json:"device_type"`
    70  
    71  	// Display
    72  	// Read Only: true
    73  	Display string `json:"display,omitempty"`
    74  
    75  	// Display name
    76  	// Read Only: true
    77  	DisplayName string `json:"display_name,omitempty"`
    78  
    79  	// Rack face
    80  	// Enum: [front rear]
    81  	Face string `json:"face,omitempty"`
    82  
    83  	// Id
    84  	// Read Only: true
    85  	ID int64 `json:"id,omitempty"`
    86  
    87  	// Last updated
    88  	// Read Only: true
    89  	// Format: date-time
    90  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    91  
    92  	// Local context data
    93  	LocalContextData *string `json:"local_context_data,omitempty"`
    94  
    95  	// Location
    96  	Location *int64 `json:"location,omitempty"`
    97  
    98  	// Name
    99  	// Max Length: 64
   100  	Name *string `json:"name,omitempty"`
   101  
   102  	// parent device
   103  	ParentDevice *NestedDevice `json:"parent_device,omitempty"`
   104  
   105  	// Platform
   106  	Platform *int64 `json:"platform,omitempty"`
   107  
   108  	// Position (U)
   109  	//
   110  	// The lowest-numbered unit occupied by the device
   111  	// Maximum: 32767
   112  	// Minimum: 1
   113  	Position *int64 `json:"position,omitempty"`
   114  
   115  	// Primary ip
   116  	// Read Only: true
   117  	PrimaryIP string `json:"primary_ip,omitempty"`
   118  
   119  	// Primary IPv4
   120  	PrimaryIp4 *int64 `json:"primary_ip4,omitempty"`
   121  
   122  	// Primary IPv6
   123  	PrimaryIp6 *int64 `json:"primary_ip6,omitempty"`
   124  
   125  	// Rack
   126  	Rack *int64 `json:"rack,omitempty"`
   127  
   128  	// Serial number
   129  	// Max Length: 50
   130  	Serial string `json:"serial,omitempty"`
   131  
   132  	// Site
   133  	// Required: true
   134  	Site *int64 `json:"site"`
   135  
   136  	// Status
   137  	// Enum: [offline active planned staged failed inventory decommissioning]
   138  	Status string `json:"status,omitempty"`
   139  
   140  	// tags
   141  	Tags []*NestedTag `json:"tags"`
   142  
   143  	// Tenant
   144  	Tenant *int64 `json:"tenant,omitempty"`
   145  
   146  	// Url
   147  	// Read Only: true
   148  	// Format: uri
   149  	URL strfmt.URI `json:"url,omitempty"`
   150  
   151  	// Vc position
   152  	// Maximum: 255
   153  	// Minimum: 0
   154  	VcPosition *int64 `json:"vc_position,omitempty"`
   155  
   156  	// Vc priority
   157  	// Maximum: 255
   158  	// Minimum: 0
   159  	VcPriority *int64 `json:"vc_priority,omitempty"`
   160  
   161  	// Virtual chassis
   162  	VirtualChassis *int64 `json:"virtual_chassis,omitempty"`
   163  }
   164  
   165  // Validate validates this writable device with config context
   166  func (m *WritableDeviceWithConfigContext) Validate(formats strfmt.Registry) error {
   167  	var res []error
   168  
   169  	if err := m.validateAssetTag(formats); err != nil {
   170  		res = append(res, err)
   171  	}
   172  
   173  	if err := m.validateCreated(formats); err != nil {
   174  		res = append(res, err)
   175  	}
   176  
   177  	if err := m.validateDeviceRole(formats); err != nil {
   178  		res = append(res, err)
   179  	}
   180  
   181  	if err := m.validateDeviceType(formats); err != nil {
   182  		res = append(res, err)
   183  	}
   184  
   185  	if err := m.validateFace(formats); err != nil {
   186  		res = append(res, err)
   187  	}
   188  
   189  	if err := m.validateLastUpdated(formats); err != nil {
   190  		res = append(res, err)
   191  	}
   192  
   193  	if err := m.validateName(formats); err != nil {
   194  		res = append(res, err)
   195  	}
   196  
   197  	if err := m.validateParentDevice(formats); err != nil {
   198  		res = append(res, err)
   199  	}
   200  
   201  	if err := m.validatePosition(formats); err != nil {
   202  		res = append(res, err)
   203  	}
   204  
   205  	if err := m.validateSerial(formats); err != nil {
   206  		res = append(res, err)
   207  	}
   208  
   209  	if err := m.validateSite(formats); err != nil {
   210  		res = append(res, err)
   211  	}
   212  
   213  	if err := m.validateStatus(formats); err != nil {
   214  		res = append(res, err)
   215  	}
   216  
   217  	if err := m.validateTags(formats); err != nil {
   218  		res = append(res, err)
   219  	}
   220  
   221  	if err := m.validateURL(formats); err != nil {
   222  		res = append(res, err)
   223  	}
   224  
   225  	if err := m.validateVcPosition(formats); err != nil {
   226  		res = append(res, err)
   227  	}
   228  
   229  	if err := m.validateVcPriority(formats); err != nil {
   230  		res = append(res, err)
   231  	}
   232  
   233  	if len(res) > 0 {
   234  		return errors.CompositeValidationError(res...)
   235  	}
   236  	return nil
   237  }
   238  
   239  func (m *WritableDeviceWithConfigContext) validateAssetTag(formats strfmt.Registry) error {
   240  	if swag.IsZero(m.AssetTag) { // not required
   241  		return nil
   242  	}
   243  
   244  	if err := validate.MaxLength("asset_tag", "body", *m.AssetTag, 50); err != nil {
   245  		return err
   246  	}
   247  
   248  	return nil
   249  }
   250  
   251  func (m *WritableDeviceWithConfigContext) validateCreated(formats strfmt.Registry) error {
   252  	if swag.IsZero(m.Created) { // not required
   253  		return nil
   254  	}
   255  
   256  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   257  		return err
   258  	}
   259  
   260  	return nil
   261  }
   262  
   263  func (m *WritableDeviceWithConfigContext) validateDeviceRole(formats strfmt.Registry) error {
   264  
   265  	if err := validate.Required("device_role", "body", m.DeviceRole); err != nil {
   266  		return err
   267  	}
   268  
   269  	return nil
   270  }
   271  
   272  func (m *WritableDeviceWithConfigContext) validateDeviceType(formats strfmt.Registry) error {
   273  
   274  	if err := validate.Required("device_type", "body", m.DeviceType); err != nil {
   275  		return err
   276  	}
   277  
   278  	return nil
   279  }
   280  
   281  var writableDeviceWithConfigContextTypeFacePropEnum []interface{}
   282  
   283  func init() {
   284  	var res []string
   285  	if err := json.Unmarshal([]byte(`["front","rear"]`), &res); err != nil {
   286  		panic(err)
   287  	}
   288  	for _, v := range res {
   289  		writableDeviceWithConfigContextTypeFacePropEnum = append(writableDeviceWithConfigContextTypeFacePropEnum, v)
   290  	}
   291  }
   292  
   293  const (
   294  
   295  	// WritableDeviceWithConfigContextFaceFront captures enum value "front"
   296  	WritableDeviceWithConfigContextFaceFront string = "front"
   297  
   298  	// WritableDeviceWithConfigContextFaceRear captures enum value "rear"
   299  	WritableDeviceWithConfigContextFaceRear string = "rear"
   300  )
   301  
   302  // prop value enum
   303  func (m *WritableDeviceWithConfigContext) validateFaceEnum(path, location string, value string) error {
   304  	if err := validate.EnumCase(path, location, value, writableDeviceWithConfigContextTypeFacePropEnum, true); err != nil {
   305  		return err
   306  	}
   307  	return nil
   308  }
   309  
   310  func (m *WritableDeviceWithConfigContext) validateFace(formats strfmt.Registry) error {
   311  	if swag.IsZero(m.Face) { // not required
   312  		return nil
   313  	}
   314  
   315  	// value enum
   316  	if err := m.validateFaceEnum("face", "body", m.Face); err != nil {
   317  		return err
   318  	}
   319  
   320  	return nil
   321  }
   322  
   323  func (m *WritableDeviceWithConfigContext) validateLastUpdated(formats strfmt.Registry) error {
   324  	if swag.IsZero(m.LastUpdated) { // not required
   325  		return nil
   326  	}
   327  
   328  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   329  		return err
   330  	}
   331  
   332  	return nil
   333  }
   334  
   335  func (m *WritableDeviceWithConfigContext) validateName(formats strfmt.Registry) error {
   336  	if swag.IsZero(m.Name) { // not required
   337  		return nil
   338  	}
   339  
   340  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   341  		return err
   342  	}
   343  
   344  	return nil
   345  }
   346  
   347  func (m *WritableDeviceWithConfigContext) validateParentDevice(formats strfmt.Registry) error {
   348  	if swag.IsZero(m.ParentDevice) { // not required
   349  		return nil
   350  	}
   351  
   352  	if m.ParentDevice != nil {
   353  		if err := m.ParentDevice.Validate(formats); err != nil {
   354  			if ve, ok := err.(*errors.Validation); ok {
   355  				return ve.ValidateName("parent_device")
   356  			} else if ce, ok := err.(*errors.CompositeError); ok {
   357  				return ce.ValidateName("parent_device")
   358  			}
   359  			return err
   360  		}
   361  	}
   362  
   363  	return nil
   364  }
   365  
   366  func (m *WritableDeviceWithConfigContext) validatePosition(formats strfmt.Registry) error {
   367  	if swag.IsZero(m.Position) { // not required
   368  		return nil
   369  	}
   370  
   371  	if err := validate.MinimumInt("position", "body", *m.Position, 1, false); err != nil {
   372  		return err
   373  	}
   374  
   375  	if err := validate.MaximumInt("position", "body", *m.Position, 32767, false); err != nil {
   376  		return err
   377  	}
   378  
   379  	return nil
   380  }
   381  
   382  func (m *WritableDeviceWithConfigContext) validateSerial(formats strfmt.Registry) error {
   383  	if swag.IsZero(m.Serial) { // not required
   384  		return nil
   385  	}
   386  
   387  	if err := validate.MaxLength("serial", "body", m.Serial, 50); err != nil {
   388  		return err
   389  	}
   390  
   391  	return nil
   392  }
   393  
   394  func (m *WritableDeviceWithConfigContext) validateSite(formats strfmt.Registry) error {
   395  
   396  	if err := validate.Required("site", "body", m.Site); err != nil {
   397  		return err
   398  	}
   399  
   400  	return nil
   401  }
   402  
   403  var writableDeviceWithConfigContextTypeStatusPropEnum []interface{}
   404  
   405  func init() {
   406  	var res []string
   407  	if err := json.Unmarshal([]byte(`["offline","active","planned","staged","failed","inventory","decommissioning"]`), &res); err != nil {
   408  		panic(err)
   409  	}
   410  	for _, v := range res {
   411  		writableDeviceWithConfigContextTypeStatusPropEnum = append(writableDeviceWithConfigContextTypeStatusPropEnum, v)
   412  	}
   413  }
   414  
   415  const (
   416  
   417  	// WritableDeviceWithConfigContextStatusOffline captures enum value "offline"
   418  	WritableDeviceWithConfigContextStatusOffline string = "offline"
   419  
   420  	// WritableDeviceWithConfigContextStatusActive captures enum value "active"
   421  	WritableDeviceWithConfigContextStatusActive string = "active"
   422  
   423  	// WritableDeviceWithConfigContextStatusPlanned captures enum value "planned"
   424  	WritableDeviceWithConfigContextStatusPlanned string = "planned"
   425  
   426  	// WritableDeviceWithConfigContextStatusStaged captures enum value "staged"
   427  	WritableDeviceWithConfigContextStatusStaged string = "staged"
   428  
   429  	// WritableDeviceWithConfigContextStatusFailed captures enum value "failed"
   430  	WritableDeviceWithConfigContextStatusFailed string = "failed"
   431  
   432  	// WritableDeviceWithConfigContextStatusInventory captures enum value "inventory"
   433  	WritableDeviceWithConfigContextStatusInventory string = "inventory"
   434  
   435  	// WritableDeviceWithConfigContextStatusDecommissioning captures enum value "decommissioning"
   436  	WritableDeviceWithConfigContextStatusDecommissioning string = "decommissioning"
   437  )
   438  
   439  // prop value enum
   440  func (m *WritableDeviceWithConfigContext) validateStatusEnum(path, location string, value string) error {
   441  	if err := validate.EnumCase(path, location, value, writableDeviceWithConfigContextTypeStatusPropEnum, true); err != nil {
   442  		return err
   443  	}
   444  	return nil
   445  }
   446  
   447  func (m *WritableDeviceWithConfigContext) validateStatus(formats strfmt.Registry) error {
   448  	if swag.IsZero(m.Status) { // not required
   449  		return nil
   450  	}
   451  
   452  	// value enum
   453  	if err := m.validateStatusEnum("status", "body", m.Status); err != nil {
   454  		return err
   455  	}
   456  
   457  	return nil
   458  }
   459  
   460  func (m *WritableDeviceWithConfigContext) validateTags(formats strfmt.Registry) error {
   461  	if swag.IsZero(m.Tags) { // not required
   462  		return nil
   463  	}
   464  
   465  	for i := 0; i < len(m.Tags); i++ {
   466  		if swag.IsZero(m.Tags[i]) { // not required
   467  			continue
   468  		}
   469  
   470  		if m.Tags[i] != nil {
   471  			if err := m.Tags[i].Validate(formats); err != nil {
   472  				if ve, ok := err.(*errors.Validation); ok {
   473  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   474  				} else if ce, ok := err.(*errors.CompositeError); ok {
   475  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   476  				}
   477  				return err
   478  			}
   479  		}
   480  
   481  	}
   482  
   483  	return nil
   484  }
   485  
   486  func (m *WritableDeviceWithConfigContext) validateURL(formats strfmt.Registry) error {
   487  	if swag.IsZero(m.URL) { // not required
   488  		return nil
   489  	}
   490  
   491  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   492  		return err
   493  	}
   494  
   495  	return nil
   496  }
   497  
   498  func (m *WritableDeviceWithConfigContext) validateVcPosition(formats strfmt.Registry) error {
   499  	if swag.IsZero(m.VcPosition) { // not required
   500  		return nil
   501  	}
   502  
   503  	if err := validate.MinimumInt("vc_position", "body", *m.VcPosition, 0, false); err != nil {
   504  		return err
   505  	}
   506  
   507  	if err := validate.MaximumInt("vc_position", "body", *m.VcPosition, 255, false); err != nil {
   508  		return err
   509  	}
   510  
   511  	return nil
   512  }
   513  
   514  func (m *WritableDeviceWithConfigContext) validateVcPriority(formats strfmt.Registry) error {
   515  	if swag.IsZero(m.VcPriority) { // not required
   516  		return nil
   517  	}
   518  
   519  	if err := validate.MinimumInt("vc_priority", "body", *m.VcPriority, 0, false); err != nil {
   520  		return err
   521  	}
   522  
   523  	if err := validate.MaximumInt("vc_priority", "body", *m.VcPriority, 255, false); err != nil {
   524  		return err
   525  	}
   526  
   527  	return nil
   528  }
   529  
   530  // ContextValidate validate this writable device with config context based on the context it is used
   531  func (m *WritableDeviceWithConfigContext) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   532  	var res []error
   533  
   534  	if err := m.contextValidateConfigContext(ctx, formats); err != nil {
   535  		res = append(res, err)
   536  	}
   537  
   538  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   539  		res = append(res, err)
   540  	}
   541  
   542  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   543  		res = append(res, err)
   544  	}
   545  
   546  	if err := m.contextValidateDisplayName(ctx, formats); err != nil {
   547  		res = append(res, err)
   548  	}
   549  
   550  	if err := m.contextValidateID(ctx, formats); err != nil {
   551  		res = append(res, err)
   552  	}
   553  
   554  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   555  		res = append(res, err)
   556  	}
   557  
   558  	if err := m.contextValidateParentDevice(ctx, formats); err != nil {
   559  		res = append(res, err)
   560  	}
   561  
   562  	if err := m.contextValidatePrimaryIP(ctx, formats); err != nil {
   563  		res = append(res, err)
   564  	}
   565  
   566  	if err := m.contextValidateTags(ctx, formats); err != nil {
   567  		res = append(res, err)
   568  	}
   569  
   570  	if err := m.contextValidateURL(ctx, formats); err != nil {
   571  		res = append(res, err)
   572  	}
   573  
   574  	if len(res) > 0 {
   575  		return errors.CompositeValidationError(res...)
   576  	}
   577  	return nil
   578  }
   579  
   580  func (m *WritableDeviceWithConfigContext) contextValidateConfigContext(ctx context.Context, formats strfmt.Registry) error {
   581  
   582  	return nil
   583  }
   584  
   585  func (m *WritableDeviceWithConfigContext) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   586  
   587  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   588  		return err
   589  	}
   590  
   591  	return nil
   592  }
   593  
   594  func (m *WritableDeviceWithConfigContext) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   595  
   596  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   597  		return err
   598  	}
   599  
   600  	return nil
   601  }
   602  
   603  func (m *WritableDeviceWithConfigContext) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error {
   604  
   605  	if err := validate.ReadOnly(ctx, "display_name", "body", string(m.DisplayName)); err != nil {
   606  		return err
   607  	}
   608  
   609  	return nil
   610  }
   611  
   612  func (m *WritableDeviceWithConfigContext) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   613  
   614  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   615  		return err
   616  	}
   617  
   618  	return nil
   619  }
   620  
   621  func (m *WritableDeviceWithConfigContext) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   622  
   623  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   624  		return err
   625  	}
   626  
   627  	return nil
   628  }
   629  
   630  func (m *WritableDeviceWithConfigContext) contextValidateParentDevice(ctx context.Context, formats strfmt.Registry) error {
   631  
   632  	if m.ParentDevice != nil {
   633  		if err := m.ParentDevice.ContextValidate(ctx, formats); err != nil {
   634  			if ve, ok := err.(*errors.Validation); ok {
   635  				return ve.ValidateName("parent_device")
   636  			} else if ce, ok := err.(*errors.CompositeError); ok {
   637  				return ce.ValidateName("parent_device")
   638  			}
   639  			return err
   640  		}
   641  	}
   642  
   643  	return nil
   644  }
   645  
   646  func (m *WritableDeviceWithConfigContext) contextValidatePrimaryIP(ctx context.Context, formats strfmt.Registry) error {
   647  
   648  	if err := validate.ReadOnly(ctx, "primary_ip", "body", string(m.PrimaryIP)); err != nil {
   649  		return err
   650  	}
   651  
   652  	return nil
   653  }
   654  
   655  func (m *WritableDeviceWithConfigContext) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   656  
   657  	for i := 0; i < len(m.Tags); i++ {
   658  
   659  		if m.Tags[i] != nil {
   660  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   661  				if ve, ok := err.(*errors.Validation); ok {
   662  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   663  				} else if ce, ok := err.(*errors.CompositeError); ok {
   664  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   665  				}
   666  				return err
   667  			}
   668  		}
   669  
   670  	}
   671  
   672  	return nil
   673  }
   674  
   675  func (m *WritableDeviceWithConfigContext) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   676  
   677  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   678  		return err
   679  	}
   680  
   681  	return nil
   682  }
   683  
   684  // MarshalBinary interface implementation
   685  func (m *WritableDeviceWithConfigContext) MarshalBinary() ([]byte, error) {
   686  	if m == nil {
   687  		return nil, nil
   688  	}
   689  	return swag.WriteJSON(m)
   690  }
   691  
   692  // UnmarshalBinary interface implementation
   693  func (m *WritableDeviceWithConfigContext) UnmarshalBinary(b []byte) error {
   694  	var res WritableDeviceWithConfigContext
   695  	if err := swag.ReadJSON(b, &res); err != nil {
   696  		return err
   697  	}
   698  	*m = res
   699  	return nil
   700  }