github.com/onosproject/onos-api/go@v0.10.32/onos/config/device/types.go (about)

     1  // SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package device
     6  
     7  import (
     8  	"fmt"
     9  	types "github.com/onosproject/onos-api/go/onos/config"
    10  	"strings"
    11  )
    12  
    13  const separator = ":"
    14  
    15  // ID is a device ID
    16  type ID string
    17  
    18  // Type is a device type
    19  type Type string
    20  
    21  // Role is a device role
    22  type Role string
    23  // Version is a device version
    24  type Version string
    25  
    26  // VersionedID is a versioned device ID
    27  type VersionedID types.ID
    28  
    29  // NewVersionedID returns a new versioned device identifier
    30  func NewVersionedID(id ID, version Version) VersionedID {
    31  	return VersionedID(fmt.Sprintf("%s%s%s", id, separator, version))
    32  }
    33  
    34  // GetID returns the device ID
    35  func (i VersionedID) GetID() ID {
    36  	return ID(i[:strings.Index(string(i), separator)])
    37  }
    38  
    39  // GetVersion returns the device version
    40  func (i VersionedID) GetVersion() Version {
    41  	return Version(i[strings.Index(string(i), separator)+1:])
    42  }