github.com/digitalocean/go-netbox@v0.0.2/netbox/models/cluster.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  // Cluster cluster
    34  //
    35  // swagger:model Cluster
    36  type Cluster struct {
    37  
    38  	// Comments
    39  	Comments string `json:"comments,omitempty"`
    40  
    41  	// Created
    42  	// Read Only: true
    43  	// Format: date
    44  	Created strfmt.Date `json:"created,omitempty"`
    45  
    46  	// Custom fields
    47  	CustomFields interface{} `json:"custom_fields,omitempty"`
    48  
    49  	// Device count
    50  	// Read Only: true
    51  	DeviceCount int64 `json:"device_count,omitempty"`
    52  
    53  	// Display
    54  	// Read Only: true
    55  	Display string `json:"display,omitempty"`
    56  
    57  	// group
    58  	Group *NestedClusterGroup `json:"group,omitempty"`
    59  
    60  	// Id
    61  	// Read Only: true
    62  	ID int64 `json:"id,omitempty"`
    63  
    64  	// Last updated
    65  	// Read Only: true
    66  	// Format: date-time
    67  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    68  
    69  	// Name
    70  	// Required: true
    71  	// Max Length: 100
    72  	// Min Length: 1
    73  	Name *string `json:"name"`
    74  
    75  	// site
    76  	Site *NestedSite `json:"site,omitempty"`
    77  
    78  	// tags
    79  	Tags []*NestedTag `json:"tags"`
    80  
    81  	// tenant
    82  	Tenant *NestedTenant `json:"tenant,omitempty"`
    83  
    84  	// type
    85  	// Required: true
    86  	Type *NestedClusterType `json:"type"`
    87  
    88  	// Url
    89  	// Read Only: true
    90  	// Format: uri
    91  	URL strfmt.URI `json:"url,omitempty"`
    92  
    93  	// Virtualmachine count
    94  	// Read Only: true
    95  	VirtualmachineCount int64 `json:"virtualmachine_count,omitempty"`
    96  }
    97  
    98  // Validate validates this cluster
    99  func (m *Cluster) Validate(formats strfmt.Registry) error {
   100  	var res []error
   101  
   102  	if err := m.validateCreated(formats); err != nil {
   103  		res = append(res, err)
   104  	}
   105  
   106  	if err := m.validateGroup(formats); err != nil {
   107  		res = append(res, err)
   108  	}
   109  
   110  	if err := m.validateLastUpdated(formats); err != nil {
   111  		res = append(res, err)
   112  	}
   113  
   114  	if err := m.validateName(formats); err != nil {
   115  		res = append(res, err)
   116  	}
   117  
   118  	if err := m.validateSite(formats); err != nil {
   119  		res = append(res, err)
   120  	}
   121  
   122  	if err := m.validateTags(formats); err != nil {
   123  		res = append(res, err)
   124  	}
   125  
   126  	if err := m.validateTenant(formats); err != nil {
   127  		res = append(res, err)
   128  	}
   129  
   130  	if err := m.validateType(formats); err != nil {
   131  		res = append(res, err)
   132  	}
   133  
   134  	if err := m.validateURL(formats); err != nil {
   135  		res = append(res, err)
   136  	}
   137  
   138  	if len(res) > 0 {
   139  		return errors.CompositeValidationError(res...)
   140  	}
   141  	return nil
   142  }
   143  
   144  func (m *Cluster) validateCreated(formats strfmt.Registry) error {
   145  	if swag.IsZero(m.Created) { // not required
   146  		return nil
   147  	}
   148  
   149  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   150  		return err
   151  	}
   152  
   153  	return nil
   154  }
   155  
   156  func (m *Cluster) validateGroup(formats strfmt.Registry) error {
   157  	if swag.IsZero(m.Group) { // not required
   158  		return nil
   159  	}
   160  
   161  	if m.Group != nil {
   162  		if err := m.Group.Validate(formats); err != nil {
   163  			if ve, ok := err.(*errors.Validation); ok {
   164  				return ve.ValidateName("group")
   165  			} else if ce, ok := err.(*errors.CompositeError); ok {
   166  				return ce.ValidateName("group")
   167  			}
   168  			return err
   169  		}
   170  	}
   171  
   172  	return nil
   173  }
   174  
   175  func (m *Cluster) validateLastUpdated(formats strfmt.Registry) error {
   176  	if swag.IsZero(m.LastUpdated) { // not required
   177  		return nil
   178  	}
   179  
   180  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   181  		return err
   182  	}
   183  
   184  	return nil
   185  }
   186  
   187  func (m *Cluster) validateName(formats strfmt.Registry) error {
   188  
   189  	if err := validate.Required("name", "body", m.Name); err != nil {
   190  		return err
   191  	}
   192  
   193  	if err := validate.MinLength("name", "body", *m.Name, 1); err != nil {
   194  		return err
   195  	}
   196  
   197  	if err := validate.MaxLength("name", "body", *m.Name, 100); err != nil {
   198  		return err
   199  	}
   200  
   201  	return nil
   202  }
   203  
   204  func (m *Cluster) validateSite(formats strfmt.Registry) error {
   205  	if swag.IsZero(m.Site) { // not required
   206  		return nil
   207  	}
   208  
   209  	if m.Site != nil {
   210  		if err := m.Site.Validate(formats); err != nil {
   211  			if ve, ok := err.(*errors.Validation); ok {
   212  				return ve.ValidateName("site")
   213  			} else if ce, ok := err.(*errors.CompositeError); ok {
   214  				return ce.ValidateName("site")
   215  			}
   216  			return err
   217  		}
   218  	}
   219  
   220  	return nil
   221  }
   222  
   223  func (m *Cluster) validateTags(formats strfmt.Registry) error {
   224  	if swag.IsZero(m.Tags) { // not required
   225  		return nil
   226  	}
   227  
   228  	for i := 0; i < len(m.Tags); i++ {
   229  		if swag.IsZero(m.Tags[i]) { // not required
   230  			continue
   231  		}
   232  
   233  		if m.Tags[i] != nil {
   234  			if err := m.Tags[i].Validate(formats); err != nil {
   235  				if ve, ok := err.(*errors.Validation); ok {
   236  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   237  				} else if ce, ok := err.(*errors.CompositeError); ok {
   238  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   239  				}
   240  				return err
   241  			}
   242  		}
   243  
   244  	}
   245  
   246  	return nil
   247  }
   248  
   249  func (m *Cluster) validateTenant(formats strfmt.Registry) error {
   250  	if swag.IsZero(m.Tenant) { // not required
   251  		return nil
   252  	}
   253  
   254  	if m.Tenant != nil {
   255  		if err := m.Tenant.Validate(formats); err != nil {
   256  			if ve, ok := err.(*errors.Validation); ok {
   257  				return ve.ValidateName("tenant")
   258  			} else if ce, ok := err.(*errors.CompositeError); ok {
   259  				return ce.ValidateName("tenant")
   260  			}
   261  			return err
   262  		}
   263  	}
   264  
   265  	return nil
   266  }
   267  
   268  func (m *Cluster) validateType(formats strfmt.Registry) error {
   269  
   270  	if err := validate.Required("type", "body", m.Type); err != nil {
   271  		return err
   272  	}
   273  
   274  	if m.Type != nil {
   275  		if err := m.Type.Validate(formats); err != nil {
   276  			if ve, ok := err.(*errors.Validation); ok {
   277  				return ve.ValidateName("type")
   278  			} else if ce, ok := err.(*errors.CompositeError); ok {
   279  				return ce.ValidateName("type")
   280  			}
   281  			return err
   282  		}
   283  	}
   284  
   285  	return nil
   286  }
   287  
   288  func (m *Cluster) validateURL(formats strfmt.Registry) error {
   289  	if swag.IsZero(m.URL) { // not required
   290  		return nil
   291  	}
   292  
   293  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   294  		return err
   295  	}
   296  
   297  	return nil
   298  }
   299  
   300  // ContextValidate validate this cluster based on the context it is used
   301  func (m *Cluster) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   302  	var res []error
   303  
   304  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   305  		res = append(res, err)
   306  	}
   307  
   308  	if err := m.contextValidateDeviceCount(ctx, formats); err != nil {
   309  		res = append(res, err)
   310  	}
   311  
   312  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   313  		res = append(res, err)
   314  	}
   315  
   316  	if err := m.contextValidateGroup(ctx, formats); err != nil {
   317  		res = append(res, err)
   318  	}
   319  
   320  	if err := m.contextValidateID(ctx, formats); err != nil {
   321  		res = append(res, err)
   322  	}
   323  
   324  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   325  		res = append(res, err)
   326  	}
   327  
   328  	if err := m.contextValidateSite(ctx, formats); err != nil {
   329  		res = append(res, err)
   330  	}
   331  
   332  	if err := m.contextValidateTags(ctx, formats); err != nil {
   333  		res = append(res, err)
   334  	}
   335  
   336  	if err := m.contextValidateTenant(ctx, formats); err != nil {
   337  		res = append(res, err)
   338  	}
   339  
   340  	if err := m.contextValidateType(ctx, formats); err != nil {
   341  		res = append(res, err)
   342  	}
   343  
   344  	if err := m.contextValidateURL(ctx, formats); err != nil {
   345  		res = append(res, err)
   346  	}
   347  
   348  	if err := m.contextValidateVirtualmachineCount(ctx, formats); err != nil {
   349  		res = append(res, err)
   350  	}
   351  
   352  	if len(res) > 0 {
   353  		return errors.CompositeValidationError(res...)
   354  	}
   355  	return nil
   356  }
   357  
   358  func (m *Cluster) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   359  
   360  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   361  		return err
   362  	}
   363  
   364  	return nil
   365  }
   366  
   367  func (m *Cluster) contextValidateDeviceCount(ctx context.Context, formats strfmt.Registry) error {
   368  
   369  	if err := validate.ReadOnly(ctx, "device_count", "body", int64(m.DeviceCount)); err != nil {
   370  		return err
   371  	}
   372  
   373  	return nil
   374  }
   375  
   376  func (m *Cluster) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   377  
   378  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   379  		return err
   380  	}
   381  
   382  	return nil
   383  }
   384  
   385  func (m *Cluster) contextValidateGroup(ctx context.Context, formats strfmt.Registry) error {
   386  
   387  	if m.Group != nil {
   388  		if err := m.Group.ContextValidate(ctx, formats); err != nil {
   389  			if ve, ok := err.(*errors.Validation); ok {
   390  				return ve.ValidateName("group")
   391  			} else if ce, ok := err.(*errors.CompositeError); ok {
   392  				return ce.ValidateName("group")
   393  			}
   394  			return err
   395  		}
   396  	}
   397  
   398  	return nil
   399  }
   400  
   401  func (m *Cluster) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   402  
   403  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   404  		return err
   405  	}
   406  
   407  	return nil
   408  }
   409  
   410  func (m *Cluster) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   411  
   412  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   413  		return err
   414  	}
   415  
   416  	return nil
   417  }
   418  
   419  func (m *Cluster) contextValidateSite(ctx context.Context, formats strfmt.Registry) error {
   420  
   421  	if m.Site != nil {
   422  		if err := m.Site.ContextValidate(ctx, formats); err != nil {
   423  			if ve, ok := err.(*errors.Validation); ok {
   424  				return ve.ValidateName("site")
   425  			} else if ce, ok := err.(*errors.CompositeError); ok {
   426  				return ce.ValidateName("site")
   427  			}
   428  			return err
   429  		}
   430  	}
   431  
   432  	return nil
   433  }
   434  
   435  func (m *Cluster) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   436  
   437  	for i := 0; i < len(m.Tags); i++ {
   438  
   439  		if m.Tags[i] != nil {
   440  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   441  				if ve, ok := err.(*errors.Validation); ok {
   442  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   443  				} else if ce, ok := err.(*errors.CompositeError); ok {
   444  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   445  				}
   446  				return err
   447  			}
   448  		}
   449  
   450  	}
   451  
   452  	return nil
   453  }
   454  
   455  func (m *Cluster) contextValidateTenant(ctx context.Context, formats strfmt.Registry) error {
   456  
   457  	if m.Tenant != nil {
   458  		if err := m.Tenant.ContextValidate(ctx, formats); err != nil {
   459  			if ve, ok := err.(*errors.Validation); ok {
   460  				return ve.ValidateName("tenant")
   461  			} else if ce, ok := err.(*errors.CompositeError); ok {
   462  				return ce.ValidateName("tenant")
   463  			}
   464  			return err
   465  		}
   466  	}
   467  
   468  	return nil
   469  }
   470  
   471  func (m *Cluster) contextValidateType(ctx context.Context, formats strfmt.Registry) error {
   472  
   473  	if m.Type != nil {
   474  		if err := m.Type.ContextValidate(ctx, formats); err != nil {
   475  			if ve, ok := err.(*errors.Validation); ok {
   476  				return ve.ValidateName("type")
   477  			} else if ce, ok := err.(*errors.CompositeError); ok {
   478  				return ce.ValidateName("type")
   479  			}
   480  			return err
   481  		}
   482  	}
   483  
   484  	return nil
   485  }
   486  
   487  func (m *Cluster) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   488  
   489  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   490  		return err
   491  	}
   492  
   493  	return nil
   494  }
   495  
   496  func (m *Cluster) contextValidateVirtualmachineCount(ctx context.Context, formats strfmt.Registry) error {
   497  
   498  	if err := validate.ReadOnly(ctx, "virtualmachine_count", "body", int64(m.VirtualmachineCount)); err != nil {
   499  		return err
   500  	}
   501  
   502  	return nil
   503  }
   504  
   505  // MarshalBinary interface implementation
   506  func (m *Cluster) MarshalBinary() ([]byte, error) {
   507  	if m == nil {
   508  		return nil, nil
   509  	}
   510  	return swag.WriteJSON(m)
   511  }
   512  
   513  // UnmarshalBinary interface implementation
   514  func (m *Cluster) UnmarshalBinary(b []byte) error {
   515  	var res Cluster
   516  	if err := swag.ReadJSON(b, &res); err != nil {
   517  		return err
   518  	}
   519  	*m = res
   520  	return nil
   521  }