github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_vm_interface.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  // WritableVMInterface writable VM interface
    35  //
    36  // swagger:model WritableVMInterface
    37  type WritableVMInterface struct {
    38  
    39  	// Count ipaddresses
    40  	// Read Only: true
    41  	CountIpaddresses int64 `json:"count_ipaddresses,omitempty"`
    42  
    43  	// Created
    44  	// Read Only: true
    45  	// Format: date
    46  	Created strfmt.Date `json:"created,omitempty"`
    47  
    48  	// Custom fields
    49  	CustomFields interface{} `json:"custom_fields,omitempty"`
    50  
    51  	// Description
    52  	// Max Length: 200
    53  	Description string `json:"description,omitempty"`
    54  
    55  	// Display
    56  	// Read Only: true
    57  	Display string `json:"display,omitempty"`
    58  
    59  	// Enabled
    60  	Enabled bool `json:"enabled,omitempty"`
    61  
    62  	// Id
    63  	// Read Only: true
    64  	ID int64 `json:"id,omitempty"`
    65  
    66  	// Last updated
    67  	// Read Only: true
    68  	// Format: date-time
    69  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    70  
    71  	// MAC Address
    72  	MacAddress *string `json:"mac_address,omitempty"`
    73  
    74  	// Mode
    75  	// Enum: [access tagged tagged-all]
    76  	Mode string `json:"mode,omitempty"`
    77  
    78  	// MTU
    79  	// Maximum: 65536
    80  	// Minimum: 1
    81  	Mtu *int64 `json:"mtu,omitempty"`
    82  
    83  	// Name
    84  	// Required: true
    85  	// Max Length: 64
    86  	// Min Length: 1
    87  	Name *string `json:"name"`
    88  
    89  	// Parent interface
    90  	Parent *int64 `json:"parent,omitempty"`
    91  
    92  	// tagged vlans
    93  	// Unique: true
    94  	TaggedVlans []int64 `json:"tagged_vlans"`
    95  
    96  	// tags
    97  	Tags []*NestedTag `json:"tags"`
    98  
    99  	// Untagged VLAN
   100  	UntaggedVlan *int64 `json:"untagged_vlan,omitempty"`
   101  
   102  	// Url
   103  	// Read Only: true
   104  	// Format: uri
   105  	URL strfmt.URI `json:"url,omitempty"`
   106  
   107  	// Virtual machine
   108  	// Required: true
   109  	VirtualMachine *int64 `json:"virtual_machine"`
   110  }
   111  
   112  // Validate validates this writable VM interface
   113  func (m *WritableVMInterface) Validate(formats strfmt.Registry) error {
   114  	var res []error
   115  
   116  	if err := m.validateCreated(formats); err != nil {
   117  		res = append(res, err)
   118  	}
   119  
   120  	if err := m.validateDescription(formats); err != nil {
   121  		res = append(res, err)
   122  	}
   123  
   124  	if err := m.validateLastUpdated(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if err := m.validateMode(formats); err != nil {
   129  		res = append(res, err)
   130  	}
   131  
   132  	if err := m.validateMtu(formats); err != nil {
   133  		res = append(res, err)
   134  	}
   135  
   136  	if err := m.validateName(formats); err != nil {
   137  		res = append(res, err)
   138  	}
   139  
   140  	if err := m.validateTaggedVlans(formats); err != nil {
   141  		res = append(res, err)
   142  	}
   143  
   144  	if err := m.validateTags(formats); err != nil {
   145  		res = append(res, err)
   146  	}
   147  
   148  	if err := m.validateURL(formats); err != nil {
   149  		res = append(res, err)
   150  	}
   151  
   152  	if err := m.validateVirtualMachine(formats); err != nil {
   153  		res = append(res, err)
   154  	}
   155  
   156  	if len(res) > 0 {
   157  		return errors.CompositeValidationError(res...)
   158  	}
   159  	return nil
   160  }
   161  
   162  func (m *WritableVMInterface) validateCreated(formats strfmt.Registry) error {
   163  	if swag.IsZero(m.Created) { // not required
   164  		return nil
   165  	}
   166  
   167  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   168  		return err
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  func (m *WritableVMInterface) validateDescription(formats strfmt.Registry) error {
   175  	if swag.IsZero(m.Description) { // not required
   176  		return nil
   177  	}
   178  
   179  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   180  		return err
   181  	}
   182  
   183  	return nil
   184  }
   185  
   186  func (m *WritableVMInterface) validateLastUpdated(formats strfmt.Registry) error {
   187  	if swag.IsZero(m.LastUpdated) { // not required
   188  		return nil
   189  	}
   190  
   191  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   192  		return err
   193  	}
   194  
   195  	return nil
   196  }
   197  
   198  var writableVmInterfaceTypeModePropEnum []interface{}
   199  
   200  func init() {
   201  	var res []string
   202  	if err := json.Unmarshal([]byte(`["access","tagged","tagged-all"]`), &res); err != nil {
   203  		panic(err)
   204  	}
   205  	for _, v := range res {
   206  		writableVmInterfaceTypeModePropEnum = append(writableVmInterfaceTypeModePropEnum, v)
   207  	}
   208  }
   209  
   210  const (
   211  
   212  	// WritableVMInterfaceModeAccess captures enum value "access"
   213  	WritableVMInterfaceModeAccess string = "access"
   214  
   215  	// WritableVMInterfaceModeTagged captures enum value "tagged"
   216  	WritableVMInterfaceModeTagged string = "tagged"
   217  
   218  	// WritableVMInterfaceModeTaggedDashAll captures enum value "tagged-all"
   219  	WritableVMInterfaceModeTaggedDashAll string = "tagged-all"
   220  )
   221  
   222  // prop value enum
   223  func (m *WritableVMInterface) validateModeEnum(path, location string, value string) error {
   224  	if err := validate.EnumCase(path, location, value, writableVmInterfaceTypeModePropEnum, true); err != nil {
   225  		return err
   226  	}
   227  	return nil
   228  }
   229  
   230  func (m *WritableVMInterface) validateMode(formats strfmt.Registry) error {
   231  	if swag.IsZero(m.Mode) { // not required
   232  		return nil
   233  	}
   234  
   235  	// value enum
   236  	if err := m.validateModeEnum("mode", "body", m.Mode); err != nil {
   237  		return err
   238  	}
   239  
   240  	return nil
   241  }
   242  
   243  func (m *WritableVMInterface) validateMtu(formats strfmt.Registry) error {
   244  	if swag.IsZero(m.Mtu) { // not required
   245  		return nil
   246  	}
   247  
   248  	if err := validate.MinimumInt("mtu", "body", *m.Mtu, 1, false); err != nil {
   249  		return err
   250  	}
   251  
   252  	if err := validate.MaximumInt("mtu", "body", *m.Mtu, 65536, false); err != nil {
   253  		return err
   254  	}
   255  
   256  	return nil
   257  }
   258  
   259  func (m *WritableVMInterface) validateName(formats strfmt.Registry) error {
   260  
   261  	if err := validate.Required("name", "body", m.Name); err != nil {
   262  		return err
   263  	}
   264  
   265  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   266  		return err
   267  	}
   268  
   269  	if err := validate.MaxLength("name", "body", *m.Name, 64); err != nil {
   270  		return err
   271  	}
   272  
   273  	return nil
   274  }
   275  
   276  func (m *WritableVMInterface) validateTaggedVlans(formats strfmt.Registry) error {
   277  	if swag.IsZero(m.TaggedVlans) { // not required
   278  		return nil
   279  	}
   280  
   281  	if err := validate.UniqueItems("tagged_vlans", "body", m.TaggedVlans); err != nil {
   282  		return err
   283  	}
   284  
   285  	return nil
   286  }
   287  
   288  func (m *WritableVMInterface) validateTags(formats strfmt.Registry) error {
   289  	if swag.IsZero(m.Tags) { // not required
   290  		return nil
   291  	}
   292  
   293  	for i := 0; i < len(m.Tags); i++ {
   294  		if swag.IsZero(m.Tags[i]) { // not required
   295  			continue
   296  		}
   297  
   298  		if m.Tags[i] != nil {
   299  			if err := m.Tags[i].Validate(formats); err != nil {
   300  				if ve, ok := err.(*errors.Validation); ok {
   301  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   302  				} else if ce, ok := err.(*errors.CompositeError); ok {
   303  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   304  				}
   305  				return err
   306  			}
   307  		}
   308  
   309  	}
   310  
   311  	return nil
   312  }
   313  
   314  func (m *WritableVMInterface) validateURL(formats strfmt.Registry) error {
   315  	if swag.IsZero(m.URL) { // not required
   316  		return nil
   317  	}
   318  
   319  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   320  		return err
   321  	}
   322  
   323  	return nil
   324  }
   325  
   326  func (m *WritableVMInterface) validateVirtualMachine(formats strfmt.Registry) error {
   327  
   328  	if err := validate.Required("virtual_machine", "body", m.VirtualMachine); err != nil {
   329  		return err
   330  	}
   331  
   332  	return nil
   333  }
   334  
   335  // ContextValidate validate this writable VM interface based on the context it is used
   336  func (m *WritableVMInterface) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   337  	var res []error
   338  
   339  	if err := m.contextValidateCountIpaddresses(ctx, formats); err != nil {
   340  		res = append(res, err)
   341  	}
   342  
   343  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   344  		res = append(res, err)
   345  	}
   346  
   347  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   348  		res = append(res, err)
   349  	}
   350  
   351  	if err := m.contextValidateID(ctx, formats); err != nil {
   352  		res = append(res, err)
   353  	}
   354  
   355  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   356  		res = append(res, err)
   357  	}
   358  
   359  	if err := m.contextValidateTags(ctx, formats); err != nil {
   360  		res = append(res, err)
   361  	}
   362  
   363  	if err := m.contextValidateURL(ctx, formats); err != nil {
   364  		res = append(res, err)
   365  	}
   366  
   367  	if len(res) > 0 {
   368  		return errors.CompositeValidationError(res...)
   369  	}
   370  	return nil
   371  }
   372  
   373  func (m *WritableVMInterface) contextValidateCountIpaddresses(ctx context.Context, formats strfmt.Registry) error {
   374  
   375  	if err := validate.ReadOnly(ctx, "count_ipaddresses", "body", int64(m.CountIpaddresses)); err != nil {
   376  		return err
   377  	}
   378  
   379  	return nil
   380  }
   381  
   382  func (m *WritableVMInterface) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   383  
   384  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   385  		return err
   386  	}
   387  
   388  	return nil
   389  }
   390  
   391  func (m *WritableVMInterface) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   392  
   393  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   394  		return err
   395  	}
   396  
   397  	return nil
   398  }
   399  
   400  func (m *WritableVMInterface) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   401  
   402  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   403  		return err
   404  	}
   405  
   406  	return nil
   407  }
   408  
   409  func (m *WritableVMInterface) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   410  
   411  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   412  		return err
   413  	}
   414  
   415  	return nil
   416  }
   417  
   418  func (m *WritableVMInterface) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   419  
   420  	for i := 0; i < len(m.Tags); i++ {
   421  
   422  		if m.Tags[i] != nil {
   423  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   424  				if ve, ok := err.(*errors.Validation); ok {
   425  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   426  				} else if ce, ok := err.(*errors.CompositeError); ok {
   427  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   428  				}
   429  				return err
   430  			}
   431  		}
   432  
   433  	}
   434  
   435  	return nil
   436  }
   437  
   438  func (m *WritableVMInterface) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   439  
   440  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   441  		return err
   442  	}
   443  
   444  	return nil
   445  }
   446  
   447  // MarshalBinary interface implementation
   448  func (m *WritableVMInterface) MarshalBinary() ([]byte, error) {
   449  	if m == nil {
   450  		return nil, nil
   451  	}
   452  	return swag.WriteJSON(m)
   453  }
   454  
   455  // UnmarshalBinary interface implementation
   456  func (m *WritableVMInterface) UnmarshalBinary(b []byte) error {
   457  	var res WritableVMInterface
   458  	if err := swag.ReadJSON(b, &res); err != nil {
   459  		return err
   460  	}
   461  	*m = res
   462  	return nil
   463  }