~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/instance/instance.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
// HardwareCharacteristics represents the characteristics of the instance (if known).
58
58
// Attributes that are nil are unknown or not supported.
59
59
type HardwareCharacteristics struct {
60
 
        Arch     *string   `json:"arch,omitempty" yaml:"arch,omitempty"`
61
 
        Mem      *uint64   `json:"mem,omitempty" yaml:"mem,omitempty"`
62
 
        RootDisk *uint64   `json:"root-disk,omitempty" yaml:"rootdisk,omitempty"`
63
 
        CpuCores *uint64   `json:"cpu-cores,omitempty" yaml:"cpucores,omitempty"`
64
 
        CpuPower *uint64   `json:"cpu-power,omitempty" yaml:"cpupower,omitempty"`
65
 
        Tags     *[]string `json:"tags,omitempty" yaml:"tags,omitempty"`
66
 
 
 
60
        // Arch is the architecture of the processor.
 
61
        Arch *string `json:"arch,omitempty" yaml:"arch,omitempty"`
 
62
 
 
63
        // Mem is the size of RAM in megabytes.
 
64
        Mem *uint64 `json:"mem,omitempty" yaml:"mem,omitempty"`
 
65
 
 
66
        // RootDisk is the size of the disk in megabytes.
 
67
        RootDisk *uint64 `json:"root-disk,omitempty" yaml:"rootdisk,omitempty"`
 
68
 
 
69
        // CpuCores is the number of logical cores the processor has.
 
70
        CpuCores *uint64 `json:"cpu-cores,omitempty" yaml:"cpucores,omitempty"`
 
71
 
 
72
        // CpuPower is a relative representation of the speed of the processor.
 
73
        CpuPower *uint64 `json:"cpu-power,omitempty" yaml:"cpupower,omitempty"`
 
74
 
 
75
        // Tags is a list of strings that identify the machine.
 
76
        Tags *[]string `json:"tags,omitempty" yaml:"tags,omitempty"`
 
77
 
 
78
        // AvailabilityZone defines the zone in which the machine resides.
67
79
        AvailabilityZone *string `json:"availability-zone,omitempty" yaml:"availabilityzone,omitempty"`
68
80
}
69
81
 
73
85
                strs = append(strs, fmt.Sprintf("arch=%s", *hc.Arch))
74
86
        }
75
87
        if hc.CpuCores != nil {
76
 
                strs = append(strs, fmt.Sprintf("cpu-cores=%d", *hc.CpuCores))
 
88
                strs = append(strs, fmt.Sprintf("cores=%d", *hc.CpuCores))
77
89
        }
78
90
        if hc.CpuPower != nil {
79
91
                strs = append(strs, fmt.Sprintf("cpu-power=%d", *hc.CpuPower))
93
105
        return strings.Join(strs, " ")
94
106
}
95
107
 
96
 
// Implement gnuflag.Value
97
 
func (hc *HardwareCharacteristics) Set(s string) error {
98
 
        parsed, err := ParseHardware(s)
99
 
        if err != nil {
100
 
                return err
101
 
        }
102
 
        *hc = parsed
103
 
        return nil
104
 
}
105
 
 
106
108
// MustParseHardware constructs a HardwareCharacteristics from the supplied arguments,
107
109
// as Parse, but panics on failure.
108
110
func MustParseHardware(args ...string) HardwareCharacteristics {
143
145
        switch name {
144
146
        case "arch":
145
147
                err = hc.setArch(str)
146
 
        case "cpu-cores":
 
148
        case "cores":
147
149
                err = hc.setCpuCores(str)
148
150
        case "cpu-power":
149
151
                err = hc.setCpuPower(str)