github.com/digitalocean/go-netbox@v0.0.2/netbox/models/writable_ip_address.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  // WritableIPAddress writable IP address
    35  //
    36  // swagger:model WritableIPAddress
    37  type WritableIPAddress struct {
    38  
    39  	// Address
    40  	//
    41  	// IPv4 or IPv6 address (with mask)
    42  	// Required: true
    43  	Address *string `json:"address"`
    44  
    45  	// Assigned object
    46  	// Read Only: true
    47  	AssignedObject map[string]*string `json:"assigned_object,omitempty"`
    48  
    49  	// Assigned object id
    50  	// Maximum: 2.147483647e+09
    51  	// Minimum: 0
    52  	AssignedObjectID *int64 `json:"assigned_object_id,omitempty"`
    53  
    54  	// Assigned object type
    55  	AssignedObjectType *string `json:"assigned_object_type,omitempty"`
    56  
    57  	// Created
    58  	// Read Only: true
    59  	// Format: date
    60  	Created strfmt.Date `json:"created,omitempty"`
    61  
    62  	// Custom fields
    63  	CustomFields interface{} `json:"custom_fields,omitempty"`
    64  
    65  	// Description
    66  	// Max Length: 200
    67  	Description string `json:"description,omitempty"`
    68  
    69  	// Display
    70  	// Read Only: true
    71  	Display string `json:"display,omitempty"`
    72  
    73  	// DNS Name
    74  	//
    75  	// Hostname or FQDN (not case-sensitive)
    76  	// Max Length: 255
    77  	// Pattern: ^[0-9A-Za-z._-]+$
    78  	DNSName string `json:"dns_name,omitempty"`
    79  
    80  	// Family
    81  	// Read Only: true
    82  	Family string `json:"family,omitempty"`
    83  
    84  	// Id
    85  	// Read Only: true
    86  	ID int64 `json:"id,omitempty"`
    87  
    88  	// Last updated
    89  	// Read Only: true
    90  	// Format: date-time
    91  	LastUpdated strfmt.DateTime `json:"last_updated,omitempty"`
    92  
    93  	// NAT (Inside)
    94  	//
    95  	// The IP for which this address is the "outside" IP
    96  	NatInside *int64 `json:"nat_inside,omitempty"`
    97  
    98  	// Nat outside
    99  	// Read Only: true
   100  	NatOutside string `json:"nat_outside,omitempty"`
   101  
   102  	// Role
   103  	//
   104  	// The functional role of this IP
   105  	// Enum: [loopback secondary anycast vip vrrp hsrp glbp carp]
   106  	Role string `json:"role,omitempty"`
   107  
   108  	// Status
   109  	//
   110  	// The operational status of this IP
   111  	// Enum: [active reserved deprecated dhcp slaac]
   112  	Status string `json:"status,omitempty"`
   113  
   114  	// tags
   115  	Tags []*NestedTag `json:"tags"`
   116  
   117  	// Tenant
   118  	Tenant *int64 `json:"tenant,omitempty"`
   119  
   120  	// Url
   121  	// Read Only: true
   122  	// Format: uri
   123  	URL strfmt.URI `json:"url,omitempty"`
   124  
   125  	// VRF
   126  	Vrf *int64 `json:"vrf,omitempty"`
   127  }
   128  
   129  // Validate validates this writable IP address
   130  func (m *WritableIPAddress) Validate(formats strfmt.Registry) error {
   131  	var res []error
   132  
   133  	if err := m.validateAddress(formats); err != nil {
   134  		res = append(res, err)
   135  	}
   136  
   137  	if err := m.validateAssignedObjectID(formats); err != nil {
   138  		res = append(res, err)
   139  	}
   140  
   141  	if err := m.validateCreated(formats); err != nil {
   142  		res = append(res, err)
   143  	}
   144  
   145  	if err := m.validateDescription(formats); err != nil {
   146  		res = append(res, err)
   147  	}
   148  
   149  	if err := m.validateDNSName(formats); err != nil {
   150  		res = append(res, err)
   151  	}
   152  
   153  	if err := m.validateLastUpdated(formats); err != nil {
   154  		res = append(res, err)
   155  	}
   156  
   157  	if err := m.validateRole(formats); err != nil {
   158  		res = append(res, err)
   159  	}
   160  
   161  	if err := m.validateStatus(formats); err != nil {
   162  		res = append(res, err)
   163  	}
   164  
   165  	if err := m.validateTags(formats); err != nil {
   166  		res = append(res, err)
   167  	}
   168  
   169  	if err := m.validateURL(formats); err != nil {
   170  		res = append(res, err)
   171  	}
   172  
   173  	if len(res) > 0 {
   174  		return errors.CompositeValidationError(res...)
   175  	}
   176  	return nil
   177  }
   178  
   179  func (m *WritableIPAddress) validateAddress(formats strfmt.Registry) error {
   180  
   181  	if err := validate.Required("address", "body", m.Address); err != nil {
   182  		return err
   183  	}
   184  
   185  	return nil
   186  }
   187  
   188  func (m *WritableIPAddress) validateAssignedObjectID(formats strfmt.Registry) error {
   189  	if swag.IsZero(m.AssignedObjectID) { // not required
   190  		return nil
   191  	}
   192  
   193  	if err := validate.MinimumInt("assigned_object_id", "body", *m.AssignedObjectID, 0, false); err != nil {
   194  		return err
   195  	}
   196  
   197  	if err := validate.MaximumInt("assigned_object_id", "body", *m.AssignedObjectID, 2.147483647e+09, false); err != nil {
   198  		return err
   199  	}
   200  
   201  	return nil
   202  }
   203  
   204  func (m *WritableIPAddress) validateCreated(formats strfmt.Registry) error {
   205  	if swag.IsZero(m.Created) { // not required
   206  		return nil
   207  	}
   208  
   209  	if err := validate.FormatOf("created", "body", "date", m.Created.String(), formats); err != nil {
   210  		return err
   211  	}
   212  
   213  	return nil
   214  }
   215  
   216  func (m *WritableIPAddress) validateDescription(formats strfmt.Registry) error {
   217  	if swag.IsZero(m.Description) { // not required
   218  		return nil
   219  	}
   220  
   221  	if err := validate.MaxLength("description", "body", m.Description, 200); err != nil {
   222  		return err
   223  	}
   224  
   225  	return nil
   226  }
   227  
   228  func (m *WritableIPAddress) validateDNSName(formats strfmt.Registry) error {
   229  	if swag.IsZero(m.DNSName) { // not required
   230  		return nil
   231  	}
   232  
   233  	if err := validate.MaxLength("dns_name", "body", m.DNSName, 255); err != nil {
   234  		return err
   235  	}
   236  
   237  	if err := validate.Pattern("dns_name", "body", m.DNSName, `^[0-9A-Za-z._-]+$`); err != nil {
   238  		return err
   239  	}
   240  
   241  	return nil
   242  }
   243  
   244  func (m *WritableIPAddress) validateLastUpdated(formats strfmt.Registry) error {
   245  	if swag.IsZero(m.LastUpdated) { // not required
   246  		return nil
   247  	}
   248  
   249  	if err := validate.FormatOf("last_updated", "body", "date-time", m.LastUpdated.String(), formats); err != nil {
   250  		return err
   251  	}
   252  
   253  	return nil
   254  }
   255  
   256  var writableIpAddressTypeRolePropEnum []interface{}
   257  
   258  func init() {
   259  	var res []string
   260  	if err := json.Unmarshal([]byte(`["loopback","secondary","anycast","vip","vrrp","hsrp","glbp","carp"]`), &res); err != nil {
   261  		panic(err)
   262  	}
   263  	for _, v := range res {
   264  		writableIpAddressTypeRolePropEnum = append(writableIpAddressTypeRolePropEnum, v)
   265  	}
   266  }
   267  
   268  const (
   269  
   270  	// WritableIPAddressRoleLoopback captures enum value "loopback"
   271  	WritableIPAddressRoleLoopback string = "loopback"
   272  
   273  	// WritableIPAddressRoleSecondary captures enum value "secondary"
   274  	WritableIPAddressRoleSecondary string = "secondary"
   275  
   276  	// WritableIPAddressRoleAnycast captures enum value "anycast"
   277  	WritableIPAddressRoleAnycast string = "anycast"
   278  
   279  	// WritableIPAddressRoleVip captures enum value "vip"
   280  	WritableIPAddressRoleVip string = "vip"
   281  
   282  	// WritableIPAddressRoleVrrp captures enum value "vrrp"
   283  	WritableIPAddressRoleVrrp string = "vrrp"
   284  
   285  	// WritableIPAddressRoleHsrp captures enum value "hsrp"
   286  	WritableIPAddressRoleHsrp string = "hsrp"
   287  
   288  	// WritableIPAddressRoleGlbp captures enum value "glbp"
   289  	WritableIPAddressRoleGlbp string = "glbp"
   290  
   291  	// WritableIPAddressRoleCarp captures enum value "carp"
   292  	WritableIPAddressRoleCarp string = "carp"
   293  )
   294  
   295  // prop value enum
   296  func (m *WritableIPAddress) validateRoleEnum(path, location string, value string) error {
   297  	if err := validate.EnumCase(path, location, value, writableIpAddressTypeRolePropEnum, true); err != nil {
   298  		return err
   299  	}
   300  	return nil
   301  }
   302  
   303  func (m *WritableIPAddress) validateRole(formats strfmt.Registry) error {
   304  	if swag.IsZero(m.Role) { // not required
   305  		return nil
   306  	}
   307  
   308  	// value enum
   309  	if err := m.validateRoleEnum("role", "body", m.Role); err != nil {
   310  		return err
   311  	}
   312  
   313  	return nil
   314  }
   315  
   316  var writableIpAddressTypeStatusPropEnum []interface{}
   317  
   318  func init() {
   319  	var res []string
   320  	if err := json.Unmarshal([]byte(`["active","reserved","deprecated","dhcp","slaac"]`), &res); err != nil {
   321  		panic(err)
   322  	}
   323  	for _, v := range res {
   324  		writableIpAddressTypeStatusPropEnum = append(writableIpAddressTypeStatusPropEnum, v)
   325  	}
   326  }
   327  
   328  const (
   329  
   330  	// WritableIPAddressStatusActive captures enum value "active"
   331  	WritableIPAddressStatusActive string = "active"
   332  
   333  	// WritableIPAddressStatusReserved captures enum value "reserved"
   334  	WritableIPAddressStatusReserved string = "reserved"
   335  
   336  	// WritableIPAddressStatusDeprecated captures enum value "deprecated"
   337  	WritableIPAddressStatusDeprecated string = "deprecated"
   338  
   339  	// WritableIPAddressStatusDhcp captures enum value "dhcp"
   340  	WritableIPAddressStatusDhcp string = "dhcp"
   341  
   342  	// WritableIPAddressStatusSlaac captures enum value "slaac"
   343  	WritableIPAddressStatusSlaac string = "slaac"
   344  )
   345  
   346  // prop value enum
   347  func (m *WritableIPAddress) validateStatusEnum(path, location string, value string) error {
   348  	if err := validate.EnumCase(path, location, value, writableIpAddressTypeStatusPropEnum, true); err != nil {
   349  		return err
   350  	}
   351  	return nil
   352  }
   353  
   354  func (m *WritableIPAddress) validateStatus(formats strfmt.Registry) error {
   355  	if swag.IsZero(m.Status) { // not required
   356  		return nil
   357  	}
   358  
   359  	// value enum
   360  	if err := m.validateStatusEnum("status", "body", m.Status); err != nil {
   361  		return err
   362  	}
   363  
   364  	return nil
   365  }
   366  
   367  func (m *WritableIPAddress) validateTags(formats strfmt.Registry) error {
   368  	if swag.IsZero(m.Tags) { // not required
   369  		return nil
   370  	}
   371  
   372  	for i := 0; i < len(m.Tags); i++ {
   373  		if swag.IsZero(m.Tags[i]) { // not required
   374  			continue
   375  		}
   376  
   377  		if m.Tags[i] != nil {
   378  			if err := m.Tags[i].Validate(formats); err != nil {
   379  				if ve, ok := err.(*errors.Validation); ok {
   380  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   381  				} else if ce, ok := err.(*errors.CompositeError); ok {
   382  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   383  				}
   384  				return err
   385  			}
   386  		}
   387  
   388  	}
   389  
   390  	return nil
   391  }
   392  
   393  func (m *WritableIPAddress) validateURL(formats strfmt.Registry) error {
   394  	if swag.IsZero(m.URL) { // not required
   395  		return nil
   396  	}
   397  
   398  	if err := validate.FormatOf("url", "body", "uri", m.URL.String(), formats); err != nil {
   399  		return err
   400  	}
   401  
   402  	return nil
   403  }
   404  
   405  // ContextValidate validate this writable IP address based on the context it is used
   406  func (m *WritableIPAddress) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   407  	var res []error
   408  
   409  	if err := m.contextValidateAssignedObject(ctx, formats); err != nil {
   410  		res = append(res, err)
   411  	}
   412  
   413  	if err := m.contextValidateCreated(ctx, formats); err != nil {
   414  		res = append(res, err)
   415  	}
   416  
   417  	if err := m.contextValidateDisplay(ctx, formats); err != nil {
   418  		res = append(res, err)
   419  	}
   420  
   421  	if err := m.contextValidateFamily(ctx, formats); err != nil {
   422  		res = append(res, err)
   423  	}
   424  
   425  	if err := m.contextValidateID(ctx, formats); err != nil {
   426  		res = append(res, err)
   427  	}
   428  
   429  	if err := m.contextValidateLastUpdated(ctx, formats); err != nil {
   430  		res = append(res, err)
   431  	}
   432  
   433  	if err := m.contextValidateNatOutside(ctx, formats); err != nil {
   434  		res = append(res, err)
   435  	}
   436  
   437  	if err := m.contextValidateTags(ctx, formats); err != nil {
   438  		res = append(res, err)
   439  	}
   440  
   441  	if err := m.contextValidateURL(ctx, formats); err != nil {
   442  		res = append(res, err)
   443  	}
   444  
   445  	if len(res) > 0 {
   446  		return errors.CompositeValidationError(res...)
   447  	}
   448  	return nil
   449  }
   450  
   451  func (m *WritableIPAddress) contextValidateAssignedObject(ctx context.Context, formats strfmt.Registry) error {
   452  
   453  	return nil
   454  }
   455  
   456  func (m *WritableIPAddress) contextValidateCreated(ctx context.Context, formats strfmt.Registry) error {
   457  
   458  	if err := validate.ReadOnly(ctx, "created", "body", strfmt.Date(m.Created)); err != nil {
   459  		return err
   460  	}
   461  
   462  	return nil
   463  }
   464  
   465  func (m *WritableIPAddress) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {
   466  
   467  	if err := validate.ReadOnly(ctx, "display", "body", string(m.Display)); err != nil {
   468  		return err
   469  	}
   470  
   471  	return nil
   472  }
   473  
   474  func (m *WritableIPAddress) contextValidateFamily(ctx context.Context, formats strfmt.Registry) error {
   475  
   476  	if err := validate.ReadOnly(ctx, "family", "body", string(m.Family)); err != nil {
   477  		return err
   478  	}
   479  
   480  	return nil
   481  }
   482  
   483  func (m *WritableIPAddress) contextValidateID(ctx context.Context, formats strfmt.Registry) error {
   484  
   485  	if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil {
   486  		return err
   487  	}
   488  
   489  	return nil
   490  }
   491  
   492  func (m *WritableIPAddress) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {
   493  
   494  	if err := validate.ReadOnly(ctx, "last_updated", "body", strfmt.DateTime(m.LastUpdated)); err != nil {
   495  		return err
   496  	}
   497  
   498  	return nil
   499  }
   500  
   501  func (m *WritableIPAddress) contextValidateNatOutside(ctx context.Context, formats strfmt.Registry) error {
   502  
   503  	if err := validate.ReadOnly(ctx, "nat_outside", "body", string(m.NatOutside)); err != nil {
   504  		return err
   505  	}
   506  
   507  	return nil
   508  }
   509  
   510  func (m *WritableIPAddress) contextValidateTags(ctx context.Context, formats strfmt.Registry) error {
   511  
   512  	for i := 0; i < len(m.Tags); i++ {
   513  
   514  		if m.Tags[i] != nil {
   515  			if err := m.Tags[i].ContextValidate(ctx, formats); err != nil {
   516  				if ve, ok := err.(*errors.Validation); ok {
   517  					return ve.ValidateName("tags" + "." + strconv.Itoa(i))
   518  				} else if ce, ok := err.(*errors.CompositeError); ok {
   519  					return ce.ValidateName("tags" + "." + strconv.Itoa(i))
   520  				}
   521  				return err
   522  			}
   523  		}
   524  
   525  	}
   526  
   527  	return nil
   528  }
   529  
   530  func (m *WritableIPAddress) contextValidateURL(ctx context.Context, formats strfmt.Registry) error {
   531  
   532  	if err := validate.ReadOnly(ctx, "url", "body", strfmt.URI(m.URL)); err != nil {
   533  		return err
   534  	}
   535  
   536  	return nil
   537  }
   538  
   539  // MarshalBinary interface implementation
   540  func (m *WritableIPAddress) MarshalBinary() ([]byte, error) {
   541  	if m == nil {
   542  		return nil, nil
   543  	}
   544  	return swag.WriteJSON(m)
   545  }
   546  
   547  // UnmarshalBinary interface implementation
   548  func (m *WritableIPAddress) UnmarshalBinary(b []byte) error {
   549  	var res WritableIPAddress
   550  	if err := swag.ReadJSON(b, &res); err != nil {
   551  		return err
   552  	}
   553  	*m = res
   554  	return nil
   555  }