~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/altoros/gosigma/nicrt.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 ALTOROS
 
2
// Licensed under the AGPLv3, see LICENSE file for details.
 
3
 
 
4
package gosigma
 
5
 
 
6
import (
 
7
        "fmt"
 
8
 
 
9
        "github.com/altoros/gosigma/data"
 
10
)
 
11
 
 
12
// A RuntimeNIC interface represents runtime information for network interface card
 
13
type RuntimeNIC interface {
 
14
        // Convert to string
 
15
        fmt.Stringer
 
16
 
 
17
        // IPv4 configuration
 
18
        IPv4() Resource
 
19
 
 
20
        // Type of network interface card (public, private, etc)
 
21
        Type() string
 
22
}
 
23
 
 
24
// A runtimeNIC implements runtime information for network interface card
 
25
type runtimeNIC struct {
 
26
        obj *data.RuntimeNetwork
 
27
}
 
28
 
 
29
var _ RuntimeNIC = runtimeNIC{}
 
30
 
 
31
// String method is used to print values passed as an operand to any format that
 
32
// accepts a string or to an unformatted printer such as Print.
 
33
func (r runtimeNIC) String() string {
 
34
        return fmt.Sprintf(`{Type: %q, IPv4: %v}`, r.Type(), r.IPv4())
 
35
}
 
36
 
 
37
// IPv4 configuration
 
38
func (r runtimeNIC) IPv4() Resource {
 
39
        if r.obj.IPv4 != nil {
 
40
                return resource{r.obj.IPv4}
 
41
        }
 
42
        return nil
 
43
}
 
44
 
 
45
// Type of network interface card (public, private, etc)
 
46
func (r runtimeNIC) Type() string { return r.obj.InterfaceType }