本文整理汇总了Golang中github.com/juju/juju/apiserver/params.AddMachineParams.Placement方法的典型用法代码示例。如果您正苦于以下问题:Golang AddMachineParams.Placement方法的具体用法?Golang AddMachineParams.Placement怎么用?Golang AddMachineParams.Placement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/params.AddMachineParams
的用法示例。
在下文中一共展示了AddMachineParams.Placement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *addCommand) Run(ctx *cmd.Context) error {
client, err := c.getClientAPI()
if err != nil {
return errors.Trace(err)
}
defer client.Close()
var machineManager MachineManagerAPI
if len(c.Disks) > 0 {
machineManager, err = c.getMachineManagerAPI()
if err != nil {
return errors.Trace(err)
}
defer machineManager.Close()
if machineManager.BestAPIVersion() < 1 {
return errors.New("cannot add machines with disks: not supported by the API server")
}
}
logger.Infof("load config")
var config *config.Config
if defaultStore, err := configstore.Default(); err != nil {
return err
} else if config, err = c.Config(defaultStore, client); err != nil {
return err
}
if c.Placement != nil && c.Placement.Scope == "ssh" {
logger.Infof("manual provisioning")
args := manual.ProvisionMachineArgs{
Host: c.Placement.Directive,
Client: client,
Stdin: ctx.Stdin,
Stdout: ctx.Stdout,
Stderr: ctx.Stderr,
UpdateBehavior: ¶ms.UpdateBehavior{
config.EnableOSRefreshUpdate(),
config.EnableOSUpgrade(),
},
}
machineId, err := manualProvisioner(args)
if err == nil {
ctx.Infof("created machine %v", machineId)
}
return err
}
logger.Infof("environment provisioning")
if c.Placement != nil && c.Placement.Scope == "env-uuid" {
c.Placement.Scope = client.EnvironmentUUID()
}
if c.Placement != nil && c.Placement.Scope == instance.MachineScope {
// It does not make sense to add-machine <id>.
return fmt.Errorf("machine-id cannot be specified when adding machines")
}
jobs := []multiwatcher.MachineJob{multiwatcher.JobHostUnits}
envVersion, err := envcmd.GetEnvironmentVersion(client)
if err != nil {
return err
}
// Servers before 1.21-alpha2 don't have the networker so don't
// try to use JobManageNetworking with them.
//
// In case of MAAS and Joyent JobManageNetworking is not added
// to ensure the non-intrusive start of a networker like above
// for the manual provisioning. See this related joyent bug
// http://pad.lv/1401423
if envVersion.Compare(version.MustParse("1.21-alpha2")) >= 0 &&
config.Type() != provider.MAAS &&
config.Type() != provider.Joyent {
jobs = append(jobs, multiwatcher.JobManageNetworking)
}
machineParams := params.AddMachineParams{
Placement: c.Placement,
Series: c.Series,
Constraints: c.Constraints,
Jobs: jobs,
Disks: c.Disks,
}
machines := make([]params.AddMachineParams, c.NumMachines)
for i := 0; i < c.NumMachines; i++ {
machines[i] = machineParams
}
var results []params.AddMachinesResult
// If storage is specified, we attempt to use a new API on the service facade.
if len(c.Disks) > 0 {
results, err = machineManager.AddMachines(machines)
} else {
results, err = client.AddMachines(machines)
if params.IsCodeNotImplemented(err) {
if c.Placement != nil {
containerType, parseErr := instance.ParseContainerType(c.Placement.Scope)
if parseErr != nil {
// The user specified a non-container placement directive:
//.........这里部分代码省略.........
示例2: addOneMachine
func (c *Client) addOneMachine(p params.AddMachineParams) (*state.Machine, error) {
if p.ParentId != "" && p.ContainerType == "" {
return nil, fmt.Errorf("parent machine specified without container type")
}
if p.ContainerType != "" && p.Placement != nil {
return nil, fmt.Errorf("container type and placement are mutually exclusive")
}
if p.Placement != nil {
// Extract container type and parent from container placement directives.
containerType, err := instance.ParseContainerType(p.Placement.Scope)
if err == nil {
p.ContainerType = containerType
p.ParentId = p.Placement.Directive
p.Placement = nil
}
}
if p.ContainerType != "" || p.Placement != nil {
// Guard against dubious client by making sure that
// the following attributes can only be set when we're
// not using placement.
p.InstanceId = ""
p.Nonce = ""
p.HardwareCharacteristics = instance.HardwareCharacteristics{}
p.Addrs = nil
}
if p.Series == "" {
conf, err := c.api.state.EnvironConfig()
if err != nil {
return nil, err
}
p.Series = config.PreferredSeries(conf)
}
var placementDirective string
if p.Placement != nil {
env, err := c.api.state.Environment()
if err != nil {
return nil, err
}
// For 1.21 we should support both UUID and name, and with 1.22
// just support UUID
if p.Placement.Scope != env.Name() && p.Placement.Scope != env.UUID() {
return nil, fmt.Errorf("invalid environment name %q", p.Placement.Scope)
}
placementDirective = p.Placement.Directive
}
jobs, err := common.StateJobs(p.Jobs)
if err != nil {
return nil, err
}
template := state.MachineTemplate{
Series: p.Series,
Constraints: p.Constraints,
InstanceId: p.InstanceId,
Jobs: jobs,
Nonce: p.Nonce,
HardwareCharacteristics: p.HardwareCharacteristics,
Addresses: params.NetworkAddresses(p.Addrs),
Placement: placementDirective,
}
if p.ContainerType == "" {
return c.api.state.AddOneMachine(template)
}
if p.ParentId != "" {
return c.api.state.AddMachineInsideMachine(template, p.ParentId, p.ContainerType)
}
return c.api.state.AddMachineInsideNewMachine(template, template, p.ContainerType)
}
示例3: addOneMachine
func (mm *MachineManagerAPI) addOneMachine(p params.AddMachineParams) (*state.Machine, error) {
if p.ParentId != "" && p.ContainerType == "" {
return nil, fmt.Errorf("parent machine specified without container type")
}
if p.ContainerType != "" && p.Placement != nil {
return nil, fmt.Errorf("container type and placement are mutually exclusive")
}
if p.Placement != nil {
// Extract container type and parent from container placement directives.
containerType, err := instance.ParseContainerType(p.Placement.Scope)
if err == nil {
p.ContainerType = containerType
p.ParentId = p.Placement.Directive
p.Placement = nil
}
}
if p.ContainerType != "" || p.Placement != nil {
// Guard against dubious client by making sure that
// the following attributes can only be set when we're
// not using placement.
p.InstanceId = ""
p.Nonce = ""
p.HardwareCharacteristics = instance.HardwareCharacteristics{}
p.Addrs = nil
}
if p.Series == "" {
conf, err := mm.st.ModelConfig()
if err != nil {
return nil, err
}
p.Series = config.PreferredSeries(conf)
}
var placementDirective string
if p.Placement != nil {
env, err := mm.st.Model()
if err != nil {
return nil, err
}
// For 1.21 we should support both UUID and name, and with 1.22
// just support UUID
if p.Placement.Scope != env.Name() && p.Placement.Scope != env.UUID() {
return nil, fmt.Errorf("invalid model name %q", p.Placement.Scope)
}
placementDirective = p.Placement.Directive
}
volumes := make([]state.MachineVolumeParams, 0, len(p.Disks))
for _, cons := range p.Disks {
if cons.Count == 0 {
return nil, errors.Errorf("invalid volume params: count not specified")
}
// Pool and Size are validated by AddMachineX.
volumeParams := state.VolumeParams{
Pool: cons.Pool,
Size: cons.Size,
}
volumeAttachmentParams := state.VolumeAttachmentParams{}
for i := uint64(0); i < cons.Count; i++ {
volumes = append(volumes, state.MachineVolumeParams{
volumeParams, volumeAttachmentParams,
})
}
}
jobs, err := common.StateJobs(p.Jobs)
if err != nil {
return nil, err
}
template := state.MachineTemplate{
Series: p.Series,
Constraints: p.Constraints,
Volumes: volumes,
InstanceId: p.InstanceId,
Jobs: jobs,
Nonce: p.Nonce,
HardwareCharacteristics: p.HardwareCharacteristics,
Addresses: params.NetworkAddresses(p.Addrs),
Placement: placementDirective,
}
if p.ContainerType == "" {
return mm.st.AddOneMachine(template)
}
if p.ParentId != "" {
return mm.st.AddMachineInsideMachine(template, p.ParentId, p.ContainerType)
}
return mm.st.AddMachineInsideNewMachine(template, template, p.ContainerType)
}