Пример #1
0
func addInterfaces2(
	params *gomaasapi.AllocateMachineArgs,
	bindings []interfaceBinding,
	positiveSpaces, negativeSpaces []network.SpaceInfo,
) error {
	combinedBindings, negatives, err := getBindings(bindings, positiveSpaces, negativeSpaces)
	if err != nil {
		return errors.Trace(err)
	}

	if len(combinedBindings) > 0 {
		interfaceSpecs := make([]gomaasapi.InterfaceSpec, len(combinedBindings))
		for i, space := range combinedBindings {
			interfaceSpecs[i] = gomaasapi.InterfaceSpec{space.Name, space.SpaceProviderId}
		}
		params.Interfaces = interfaceSpecs
	}
	if len(negatives) > 0 {
		negativeStrings := make([]string, len(negatives))
		for i, space := range negatives {
			negativeStrings[i] = space.SpaceProviderId
		}
		params.NotSpace = negativeStrings
	}
	return nil
}
Пример #2
0
// convertConstraints2 converts the given constraints into a
// gomaasapi.AllocateMachineArgs for paasing to MAAS 2.
func convertConstraints2(cons constraints.Value) gomaasapi.AllocateMachineArgs {
	params := gomaasapi.AllocateMachineArgs{}
	if cons.Arch != nil {
		params.Architecture = *cons.Arch
	}
	if cons.CpuCores != nil {
		params.MinCPUCount = int(*cons.CpuCores)
	}
	if cons.Mem != nil {
		params.MinMemory = int(*cons.Mem)
	}
	if cons.Tags != nil {
		positives, negatives := parseDelimitedValues(*cons.Tags)
		if len(positives) > 0 {
			params.Tags = positives
		}
		if len(negatives) > 0 {
			params.NotTags = negatives
		}
	}
	if cons.CpuPower != nil {
		logger.Warningf("ignoring unsupported constraint 'cpu-power'")
	}
	return params
}
Пример #3
0
// addStorage2 adds volume information onto a gomaasapi.AllocateMachineArgs
// object suitable to pass to MAAS 2 when acquiring a node.
func addStorage2(params *gomaasapi.AllocateMachineArgs, volumes []volumeInfo) {
	if len(volumes) == 0 {
		return
	}
	var volParams []gomaasapi.StorageSpec
	for _, v := range volumes {
		volSpec := gomaasapi.StorageSpec{
			Label: v.name,
			Size:  int(v.sizeInGB),
			Tags:  v.tags,
		}
		volParams = append(volParams, volSpec)
	}
	params.Storage = volParams
}
Пример #4
0
func (suite *maas2EnvironSuite) injectControllerWithSpacesAndCheck(c *gc.C, spaces []gomaasapi.Space, expected gomaasapi.AllocateMachineArgs) *maasEnviron {
	var env *maasEnviron
	check := func(args gomaasapi.AllocateMachineArgs) {
		expected.AgentName = env.ecfg().maasAgentName()
		c.Assert(args, gc.DeepEquals, expected)
	}
	controller := &fakeController{
		allocateMachineArgsCheck: check,
		allocateMachine:          newFakeMachine("Bruce Sterling", arch.HostArch(), ""),
		allocateMachineMatches: gomaasapi.ConstraintMatches{
			Storage: map[string][]gomaasapi.BlockDevice{},
		},
		spaces: spaces,
	}
	suite.injectController(controller)
	suite.setupFakeTools(c)
	env = suite.makeEnviron(c, nil)
	return env
}