github.com/digitalocean/go-netbox@v0.0.2/netbox/models/v_r_f.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  	"strconv"
    26  
    27  	"github.com/go-openapi/errors"
    28  	"github.com/go-openapi/strfmt"
    29  	"github.com/go-openapi/swag"
    30  	"github.com/go-openapi/validate"
    31  )
    32  
    33  // VRF v r f
    34  //
    35  // swagger:model VRF
    36  type VRF struct {
    37  
    38  	// Created
    39  	// Read Only: true
    40  	// Format: date
    41  	Created strfmt.Date `json:"created,omitempty"`
    42  
    43  	// Custom fields
    44  	CustomFields interface{} `json:"custom_fields,omitempty"`
    45  
    46  	// Description
    47  	// Max Length: 200
    48  	Description string `json:"description,omitempty"`
    49  
    50  	// Display
    51  	// Read Only: true
    52  	Display string `json:"display,omitempty"`
    53  
    54  	// Display name
    55  	// Read Only: true
    56  	DisplayName string `json:"display_name,omitempty"`
    57  
    58  	// Enforce unique space
    59  	//
    60  	// Prevent duplicate prefixes/IP addresses within this VRF
    61  	EnforceUnique bool `json:"enforce_unique,omitempty"`
    62  
    63  	// export targets
    64  	// Unique: true
    65  	ExportTargets []*NestedRouteTarget `json:"export_targets"`
    66  
    67  	// Id
    68  	// Read Only: true
    69  	ID int64 `json:"id,omitempty"`
    70  
    71  	// import targets
    72  	// Unique: true
    73  	ImportTargets []*NestedRouteTarget `json:"import_targets"`
    74  
    75  	// Ipaddress count
    76  	// Read Only: true
    77  	IpaddressCount int64 `json:"ipaddress_count,omitempty"`
    78  
    79  	// Last updated
    80  	// Read Only: true
    81  	// Format: date-time
    82  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    83  
    84  	// Name
    85  	// Required: true
    86  	// Max Length: 100
    87  	// Min Length: 1
    88  	Name *string `json:"name"`
    89  
    90  	// Prefix count
    91  	// Read Only: true
    92  	PrefixCount int64 `json:"prefix_count,omitempty"`
    93  
    94  	// Route distinguisher
    95  	//
    96  	// Unique route distinguisher (as defined in RFC 4364)
    97  	// Max Length: 21
    98  	Rd *string `json:"rd,omitempty"`
    99  
   100  	// tags
   101  	Tags []*NestedTag `json:"tags"`
   102  
   103  	// tenant
   104  	Tenant *NestedTenant `json:"tenant,omitempty"`
   105  
   106  	// Url
   107  	// Read Only: true
   108  	// Format: uri
   109  	URL strfmt.URI `json:"url,omitempty"`
   110  }
   111  
   112  // Validate validates this v r f
   113  func (m *VRF) 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.validateExportTargets(formats); err != nil {
   125  		res = append(res, err)
   126  	}
   127  
   128  	if err := m.validateImportTargets(formats); err != nil {
   129  		res = append(res, err)
   130  	}
   131  
   132  	if err := m.validateLastUpdated(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.validateRd(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.validateTenant(formats); err != nil {
   149  		res = append(res, err)
   150  	}
   151  
   152  	if err := m.validateURL(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 *VRF) 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 *VRF) 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 *VRF) validateExportTargets(formats strfmt.Registry) error {
   187  	if swag.IsZero(m.ExportTargets) { // not required
   188  		return nil
   189  	}
   190  
   191  	if err := validate.UniqueItems("export_targets", "body", m.ExportTargets); err != nil {
   192  		return err
   193  	}
   194  
   195  	for i := 0; i < len(m.ExportTargets); i++ {
   196  		if swag.IsZero(m.ExportTargets[i]) { // not required
   197  			continue
   198  		}
   199  
   200  		if m.ExportTargets[i] != nil {
   201  			if err := m.ExportTargets[i].Validate(formats); err != nil {
   202  				if ve, ok := err.(*errors.Validation); ok {
   203  					return ve.ValidateName("export_targets" + "." + strconv.Itoa(i))
   204  				} else if ce, ok := err.(*errors.CompositeError); ok {
   205  					return ce.ValidateName("export_targets" + "." + strconv.Itoa(i))
   206  				}
   207  				return err
   208  			}
   209  		}
   210  
   211  	}
   212  
   213  	return nil
   214  }
   215  
   216  func (m *VRF) validateImportTargets(formats strfmt.Registry) error {
   217  	if swag.IsZero(m.ImportTargets) { // not required
   218  		return nil
   219  	}
   220  
   221  	if err := validate.UniqueItems("import_targets", "body", m.ImportTargets); err != nil {
   222  		return err
   223  	}
   224  
   225  	for i := 0; i < len(m.ImportTargets); i++ {
   226  		if swag.IsZero(m.ImportTargets[i]) { // not required
   227  			continue
   228  		}
   229  
   230  		if m.ImportTargets[i] != nil {
   231  			if err := m.ImportTargets[i].Validate(formats); err != nil {
   232  				if ve, ok := err.(*errors.Validation); ok {
   233  					return ve.ValidateName("import_targets" + "." + strconv.Itoa(i))
   234  				} else if ce, ok := err.(*errors.CompositeError); ok {
   235  					return ce.ValidateName("import_targets" + "." + strconv.Itoa(i))
   236  				}
   237  				return err
   238  			}
   239  		}
   240  
   241  	}
   242  
   243  	return nil
   244  }
   245  
   246  func (m *VRF) validateLastUpdated(formats strfmt.Registry) error {
   247  	if swag.IsZero(m.LastUpdated) { // not required
   248  		return nil
   249  	}
   250  
   251  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   252  		return err
   253  	}
   254  
   255  	return nil
   256  }
   257  
   258  func (m *VRF) validateName(formats strfmt.Registry) error {
   259  
   260  	if err := validate.Required("name", "body", m.Name); err != nil {
   261  		return err
   262  	}
   263  
   264  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   265  		return err
   266  	}
   267  
   268  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   269  		return err
   270  	}
   271  
   272  	return nil
   273  }
   274  
   275  func (m *VRF) validateRd(formats strfmt.Registry) error {
   276  	if swag.IsZero(m.Rd) { // not required
   277  		return nil
   278  	}
   279  
   280  	if err := validate.MaxLength("rd", "body", *m.Rd, 21); err != nil {
   281  		return err
   282  	}
   283  
   284  	return nil
   285  }
   286  
   287  func (m *VRF) validateTags(formats strfmt.Registry) error {
   288  	if swag.IsZero(m.Tags) { // not required
   289  		return nil
   290  	}
   291  
   292  	for i := 0; i < len(m.Tags); i++ {
   293  		if swag.IsZero(m.Tags[i]) { // not required
   294  			continue
   295  		}
   296  
   297  		if m.Tags[i] != nil {
   298  			if err := m.Tags[i].Validate(formats); err != nil {
   299  				if ve, ok := err.(*errors.Validation); ok {
   300  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   301  				} else if ce, ok := err.(*errors.CompositeError); ok {
   302  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   303  				}
   304  				return err
   305  			}
   306  		}
   307  
   308  	}
   309  
   310  	return nil
   311  }
   312  
   313  func (m *VRF) validateTenant(formats strfmt.Registry) error {
   314  	if swag.IsZero(m.Tenant) { // not required
   315  		return nil
   316  	}
   317  
   318  	if m.Tenant != nil {
   319  		if err := m.Tenant.Validate(formats); err != nil {
   320  			if ve, ok := err.(*errors.Validation); ok {
   321  				return ve.ValidateName("tenant")
   322  			} else if ce, ok := err.(*errors.CompositeError); ok {
   323  				return ce.ValidateName("tenant")
   324  			}
   325  			return err
   326  		}
   327  	}
   328  
   329  	return nil
   330  }
   331  
   332  func (m *VRF) validateURL(formats strfmt.Registry) error {
   333  	if swag.IsZero(m.URL) { // not required
   334  		return nil
   335  	}
   336  
   337  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   338  		return err
   339  	}
   340  
   341  	return nil
   342  }
   343  
   344  // ContextValidate validate this v r f based on the context it is used
   345  func (m *VRF) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   346  	var res []error
   347  
   348  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   349  		res = append(res, err)
   350  	}
   351  
   352  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   353  		res = append(res, err)
   354  	}
   355  
   356  	if err := m.contextValidateDisplayName(ctx, formats); err != nil {
   357  		res = append(res, err)
   358  	}
   359  
   360  	if err := m.contextValidateExportTargets(ctx, formats); err != nil {
   361  		res = append(res, err)
   362  	}
   363  
   364  	if err := m.contextValidateID(ctx, formats); err != nil {
   365  		res = append(res, err)
   366  	}
   367  
   368  	if err := m.contextValidateImportTargets(ctx, formats); err != nil {
   369  		res = append(res, err)
   370  	}
   371  
   372  	if err := m.contextValidateIpaddressCount(ctx, formats); err != nil {
   373  		res = append(res, err)
   374  	}
   375  
   376  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   377  		res = append(res, err)
   378  	}
   379  
   380  	if err := m.contextValidatePrefixCount(ctx, formats); err != nil {
   381  		res = append(res, err)
   382  	}
   383  
   384  	if err := m.contextValidateTags(ctx, formats); err != nil {
   385  		res = append(res, err)
   386  	}
   387  
   388  	if err := m.contextValidateTenant(ctx, formats); err != nil {
   389  		res = append(res, err)
   390  	}
   391  
   392  	if err := m.contextValidateURL(ctx, formats); err != nil {
   393  		res = append(res, err)
   394  	}
   395  
   396  	if len(res) > 0 {
   397  		return errors.CompositeValidationError(res...)
   398  	}
   399  	return nil
   400  }
   401  
   402  func (m *VRF) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   403  
   404  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   405  		return err
   406  	}
   407  
   408  	return nil
   409  }
   410  
   411  func (m *VRF) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   412  
   413  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   414  		return err
   415  	}
   416  
   417  	return nil
   418  }
   419  
   420  func (m *VRF) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error {
   421  
   422  	if err := validate.ReadOnly(ctx, "display_name", "body", string(m.DisplayName)); err != nil {
   423  		return err
   424  	}
   425  
   426  	return nil
   427  }
   428  
   429  func (m *VRF) contextValidateExportTargets(ctx context.Context, formats strfmt.Registry) error {
   430  
   431  	for i := 0; i < len(m.ExportTargets); i++ {
   432  
   433  		if m.ExportTargets[i] != nil {
   434  			if err := m.ExportTargets[i].ContextValidate(ctx, formats); err != nil {
   435  				if ve, ok := err.(*errors.Validation); ok {
   436  					return ve.ValidateName("export_targets" + "." + strconv.Itoa(i))
   437  				} else if ce, ok := err.(*errors.CompositeError); ok {
   438  					return ce.ValidateName("export_targets" + "." + strconv.Itoa(i))
   439  				}
   440  				return err
   441  			}
   442  		}
   443  
   444  	}
   445  
   446  	return nil
   447  }
   448  
   449  func (m *VRF) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   450  
   451  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   452  		return err
   453  	}
   454  
   455  	return nil
   456  }
   457  
   458  func (m *VRF) contextValidateImportTargets(ctx context.Context, formats strfmt.Registry) error {
   459  
   460  	for i := 0; i < len(m.ImportTargets); i++ {
   461  
   462  		if m.ImportTargets[i] != nil {
   463  			if err := m.ImportTargets[i].ContextValidate(ctx, formats); err != nil {
   464  				if ve, ok := err.(*errors.Validation); ok {
   465  					return ve.ValidateName("import_targets" + "." + strconv.Itoa(i))
   466  				} else if ce, ok := err.(*errors.CompositeError); ok {
   467  					return ce.ValidateName("import_targets" + "." + strconv.Itoa(i))
   468  				}
   469  				return err
   470  			}
   471  		}
   472  
   473  	}
   474  
   475  	return nil
   476  }
   477  
   478  func (m *VRF) contextValidateIpaddressCount(ctx context.Context, formats strfmt.Registry) error {
   479  
   480  	if err := validate.ReadOnly(ctx, "ipaddress_count", "body", int64(m.IpaddressCount)); err != nil {
   481  		return err
   482  	}
   483  
   484  	return nil
   485  }
   486  
   487  func (m *VRF) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   488  
   489  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   490  		return err
   491  	}
   492  
   493  	return nil
   494  }
   495  
   496  func (m *VRF) contextValidatePrefixCount(ctx context.Context, formats strfmt.Registry) error {
   497  
   498  	if err := validate.ReadOnly(ctx, "prefix_count", "body", int64(m.PrefixCount)); err != nil {
   499  		return err
   500  	}
   501  
   502  	return nil
   503  }
   504  
   505  func (m *VRF) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   506  
   507  	for i := 0; i < len(m.Tags); i++ {
   508  
   509  		if m.Tags[i] != nil {
   510  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   511  				if ve, ok := err.(*errors.Validation); ok {
   512  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   513  				} else if ce, ok := err.(*errors.CompositeError); ok {
   514  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   515  				}
   516  				return err
   517  			}
   518  		}
   519  
   520  	}
   521  
   522  	return nil
   523  }
   524  
   525  func (m *VRF) contextValidateTenant(ctx context.Context, formats strfmt.Registry) error {
   526  
   527  	if m.Tenant != nil {
   528  		if err := m.Tenant.ContextValidate(ctx, formats); err != nil {
   529  			if ve, ok := err.(*errors.Validation); ok {
   530  				return ve.ValidateName("tenant")
   531  			} else if ce, ok := err.(*errors.CompositeError); ok {
   532  				return ce.ValidateName("tenant")
   533  			}
   534  			return err
   535  		}
   536  	}
   537  
   538  	return nil
   539  }
   540  
   541  func (m *VRF) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   542  
   543  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   544  		return err
   545  	}
   546  
   547  	return nil
   548  }
   549  
   550  // MarshalBinary interface implementation
   551  func (m *VRF) MarshalBinary() ([]byte, error) {
   552  	if m == nil {
   553  		return nil, nil
   554  	}
   555  	return swag.WriteJSON(m)
   556  }
   557  
   558  // UnmarshalBinary interface implementation
   559  func (m *VRF) UnmarshalBinary(b []byte) error {
   560  	var res VRF
   561  	if err := swag.ReadJSON(b, &res); err != nil {
   562  		return err
   563  	}
   564  	*m = res
   565  	return nil
   566  }