~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to state/state.go

[r=wallyworld] Add container support to force-machine

The deploy --force-machine option now supports containers,
either deploying to existing containers or creating new
ones on nominated machines.

Example syntax:

 juju deploy mysql --force-machine 23
 juju deploy mysql --force-machine 24/lxc/3
 juju deploy mysql --force-machine lxc:25

The last example creates a new lxc container on
machine 25.

The add-machine syntax has been tweaked to remove the
leading "/" from the container arg.

https://codereview.appspot.com/10777044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
const serviceSnippet = "[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0-9]*)*"
72
72
const numberSnippet = "(0|[1-9][0-9]*)"
73
73
const containerSnippet = "(/[a-z]+/" + numberSnippet + ")"
 
74
const machineSnippet = numberSnippet + containerSnippet + "*"
 
75
const containerSpecSnippet = "(([a-z])*:)?"
74
76
 
75
77
var (
76
 
        validService = regexp.MustCompile("^" + serviceSnippet + "$")
77
 
        validUnit    = regexp.MustCompile("^" + serviceSnippet + "/" + numberSnippet + "$")
78
 
        validMachine = regexp.MustCompile("^" + numberSnippet + containerSnippet + "*$")
 
78
        validService               = regexp.MustCompile("^" + serviceSnippet + "$")
 
79
        validUnit                  = regexp.MustCompile("^" + serviceSnippet + "/" + numberSnippet + "$")
 
80
        validMachine               = regexp.MustCompile("^" + machineSnippet + "$")
 
81
        validMachineOrNewContainer = regexp.MustCompile("^" + containerSpecSnippet + machineSnippet + "$")
79
82
)
80
83
 
81
84
// BootstrapNonce is used as a nonce for the state server machine.
92
95
}
93
96
 
94
97
// IsMachineId returns whether id is a valid machine id.
95
 
func IsMachineId(name string) bool {
96
 
        return validMachine.MatchString(name)
 
98
func IsMachineId(id string) bool {
 
99
        return validMachine.MatchString(id)
 
100
}
 
101
 
 
102
// IsMachineOrNewContainer returns whether spec is a valid machine id or new container definition.
 
103
func IsMachineOrNewContainer(spec string) bool {
 
104
        return validMachineOrNewContainer.MatchString(spec)
97
105
}
98
106
 
99
107
// State represents the state of an environment