Beispiel #1
0
// SetStatus sets the status of the service if the passed unitName,
// corresponding to the calling unit, is of the leader.
func (s *Service) SetStatus(unitName string, status params.Status, info string, data map[string]interface{}) error {
	//TODO(perrito666) bump api version for this?
	if s.st.facade.BestAPIVersion() < 2 {
		return errors.NotImplementedf("SetStatus")
	}
	tag := names.NewUnitTag(unitName)
	var result params.ErrorResults
	args := params.SetStatus{
		Entities: []params.EntityStatusArgs{
			{
				Tag:    tag.String(),
				Status: status,
				Info:   info,
				Data:   data,
			},
		},
	}
	err := s.st.facade.FacadeCall("SetServiceStatus", args, &result)
	if err != nil {
		if params.IsCodeNotImplemented(err) {
			return errors.NotImplementedf("SetServiceStatus")
		}
		return errors.Trace(err)
	}
	return result.OneError()
}
Beispiel #2
0
// DescribeVolumes is defined on storage.VolumeSource.
func (s *VolumeSource) DescribeVolumes(volIds []string) ([]storage.VolumeInfo, error) {
	s.MethodCall(s, "DescribeVolumes", volIds)
	if s.DescribeVolumesFunc != nil {
		return s.DescribeVolumesFunc(volIds)
	}
	return nil, errors.NotImplementedf("DescribeVolumes")
}
Beispiel #3
0
// AttachVolumes is defined on storage.VolumeSource.
func (s *VolumeSource) AttachVolumes(params []storage.VolumeAttachmentParams) ([]storage.VolumeAttachment, error) {
	s.MethodCall(s, "AttachVolumes", params)
	if s.AttachVolumesFunc != nil {
		return s.AttachVolumesFunc(params)
	}
	return nil, errors.NotImplementedf("AttachVolumes")
}
Beispiel #4
0
func (ma *mockAdapter) CreateVolume(args cinder.CreateVolumeVolumeParams) (*cinder.Volume, error) {
	ma.MethodCall(ma, "CreateVolume", args)
	if ma.createVolume != nil {
		return ma.createVolume(args)
	}
	return nil, errors.NotImplementedf("CreateVolume")
}
Beispiel #5
0
func (ma *mockAdapter) AttachVolume(serverId, volumeId, mountPoint string) (*nova.VolumeAttachment, error) {
	ma.MethodCall(ma, "AttachVolume", serverId, volumeId, mountPoint)
	if ma.attachVolume != nil {
		return ma.attachVolume(serverId, volumeId, mountPoint)
	}
	return nil, errors.NotImplementedf("AttachVolume")
}
Beispiel #6
0
// AllMachinePorts returns all port ranges currently open on the given
// machine, mapped to the tags of the unit that opened them and the
// relation that applies.
func (st *State) AllMachinePorts(machineTag names.MachineTag) (map[network.PortRange]params.RelationUnit, error) {
	if st.BestAPIVersion() < 1 {
		// AllMachinePorts() was introduced in UniterAPIV1.
		return nil, errors.NotImplementedf("AllMachinePorts() (need V1+)")
	}
	var results params.MachinePortsResults
	args := params.Entities{
		Entities: []params.Entity{{Tag: machineTag.String()}},
	}
	err := st.facade.FacadeCall("AllMachinePorts", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != 1 {
		return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
	}
	result := results.Results[0]
	if result.Error != nil {
		return nil, result.Error
	}
	portsMap := make(map[network.PortRange]params.RelationUnit)
	for _, ports := range result.Ports {
		portRange := ports.PortRange.NetworkPortRange()
		portsMap[portRange] = params.RelationUnit{
			Unit:     ports.UnitTag,
			Relation: ports.RelationTag,
		}
	}
	return portsMap, nil
}
Beispiel #7
0
func (s *machineSuite) TestSinglePollWhenInstancInfoUnimplemented(c *gc.C) {
	s.PatchValue(&ShortPoll, 1*time.Millisecond)
	s.PatchValue(&LongPoll, 1*time.Millisecond)
	count := int32(0)
	getInstanceInfo := func(id instance.Id) (instanceInfo, error) {
		c.Check(id, gc.Equals, instance.Id("i1234"))
		atomic.AddInt32(&count, 1)
		return instanceInfo{}, errors.NotImplementedf("instance address")
	}
	context := &testMachineContext{
		getInstanceInfo: getInstanceInfo,
		dyingc:          make(chan struct{}),
	}
	m := &testMachine{
		id:         "99",
		instanceId: "i1234",
		refresh:    func() error { return nil },
		life:       state.Alive,
	}
	died := make(chan machine)

	go runMachine(context, m, nil, died)

	time.Sleep(coretesting.ShortWait)
	killMachineLoop(c, m, context.dyingc, died)
	c.Assert(context.killAllErr, gc.Equals, nil)
	c.Assert(count, gc.Equals, int32(1))
}
Beispiel #8
0
// CreateVolumes is defined on storage.VolumeSource.
func (s *VolumeSource) CreateVolumes(params []storage.VolumeParams) ([]storage.CreateVolumesResult, error) {
	s.MethodCall(s, "CreateVolumes", params)
	if s.CreateVolumesFunc != nil {
		return s.CreateVolumesFunc(params)
	}
	return nil, errors.NotImplementedf("CreateVolumes")
}
Beispiel #9
0
// ErrIfNotVersionFn returns a function which can be used to check for
// the minimum supported version, and, if appropriate, generate an
// error.
func ErrIfNotVersionFn(minVersion int, bestApiVersion int) func(string) error {
	return func(fnName string) error {
		if minVersion <= bestApiVersion {
			return nil
		}
		return errors.NotImplementedf("%s(...) requires v%d+", fnName, minVersion)
	}
}
Beispiel #10
0
// DetachVolumes is defined on storage.VolumeSource.
func (s *VolumeSource) DetachVolumes(params []storage.VolumeAttachmentParams) error {
	s.MethodCall(s, "DetachVolumes", params)
	if s.DetachVolumesFunc != nil {
		return s.DetachVolumesFunc(params)
	}
	return errors.NotImplementedf("DetachVolumes")

}
Beispiel #11
0
// InstanceDistributor implements state.Policy.
func (p environStatePolicy) InstanceDistributor() (instance.Distributor, error) {
	env, err := p.getEnviron(p.st)
	if err != nil {
		return nil, err
	}
	if p, ok := env.(instance.Distributor); ok {
		return p, nil
	}
	return nil, errors.NotImplementedf("InstanceDistributor")
}
Beispiel #12
0
// ProviderConfigSchemaSource implements state.Policy.
func (p environStatePolicy) ProviderConfigSchemaSource() (config.ConfigSchemaSource, error) {
	provider, err := environProvider(p.st)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if cs, ok := provider.(config.ConfigSchemaSource); ok {
		return cs, nil
	}
	return nil, errors.NotImplementedf("config.ConfigSource")
}
Beispiel #13
0
func (environStatePolicy) InstanceDistributor(cfg *config.Config) (state.InstanceDistributor, error) {
	env, err := New(cfg)
	if err != nil {
		return nil, err
	}
	if p, ok := env.(state.InstanceDistributor); ok {
		return p, nil
	}
	return nil, errors.NotImplementedf("InstanceDistributor")
}
Beispiel #14
0
// DestroyVolumes is defined on storage.VolumeSource.
func (s *VolumeSource) DestroyVolumes(volIds []string) []error {
	s.MethodCall(s, "DestroyVolumes", volIds)
	if s.DestroyVolumesFunc != nil {
		return s.DestroyVolumesFunc(volIds)
	}
	errs := make([]error, len(volIds))
	for i := range errs {
		errs[i] = errors.NotImplementedf("DestroyVolumes")
	}
	return errs
}
Beispiel #15
0
func (s *EnvironCapabilitySuite) TestEnvironCapabilityUnimplemented(c *gc.C) {
	var capabilityErr error
	s.policy.GetEnvironCapability = func(*config.Config) (state.EnvironCapability, error) {
		return nil, capabilityErr
	}
	_, err := s.addOneMachine(c)
	c.Assert(err, gc.ErrorMatches, "cannot add a new machine: policy returned nil EnvironCapability without an error")
	capabilityErr = errors.NotImplementedf("EnvironCapability")
	_, err = s.addOneMachine(c)
	c.Assert(err, gc.IsNil)
}
Beispiel #16
0
func (s *PrecheckerSuite) TestPrecheckPrecheckerUnimplemented(c *gc.C) {
	var precheckerErr error
	s.policy.GetPrechecker = func(*config.Config) (state.Prechecker, error) {
		return nil, precheckerErr
	}
	_, err := s.addOneMachine(c, constraints.Value{}, "placement")
	c.Assert(err, gc.ErrorMatches, "cannot add a new machine: policy returned nil prechecker without an error")
	precheckerErr = errors.NotImplementedf("Prechecker")
	_, err = s.addOneMachine(c, constraints.Value{}, "placement")
	c.Assert(err, jc.ErrorIsNil)
}
Beispiel #17
0
func (s *ConfigValidatorSuite) TestConfigValidateUnimplemented(c *gc.C) {
	var configValidatorErr error
	s.policy.GetConfigValidator = func() (config.Validator, error) {
		return nil, configValidatorErr
	}

	err := s.updateModelConfig(c)
	c.Assert(err, gc.ErrorMatches, "policy returned nil configValidator without an error")
	configValidatorErr = errors.NotImplementedf("Validator")
	err = s.updateModelConfig(c)
	c.Assert(err, jc.ErrorIsNil)
}
Beispiel #18
0
func (s *ConfigValidatorSuite) TestConfigValidateUnimplemented(c *gc.C) {
	var configValidatorErr error
	s.policy.getConfigValidator = func(string) (state.ConfigValidator, error) {
		return nil, configValidatorErr
	}

	err := s.updateEnvironConfig(c)
	c.Assert(err, gc.ErrorMatches, "policy returned nil configValidator without an error")
	configValidatorErr = errors.NotImplementedf("Validator")
	err = s.updateEnvironConfig(c)
	c.Assert(err, gc.IsNil)
}
Beispiel #19
0
func (s *InstanceDistributorSuite) TestInstanceDistributorUnimplemented(c *gc.C) {
	s.setupScenario(c)
	var distributorErr error
	s.policy.GetInstanceDistributor = func(*config.Config) (state.InstanceDistributor, error) {
		return nil, distributorErr
	}
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, gc.IsNil)
	_, err = unit.AssignToCleanMachine()
	c.Assert(err, gc.ErrorMatches, `cannot assign unit "wordpress/1" to clean machine: policy returned nil instance distributor without an error`)
	distributorErr = errors.NotImplementedf("InstanceDistributor")
	_, err = unit.AssignToCleanMachine()
	c.Assert(err, gc.IsNil)
}
Beispiel #20
0
func (h *localLoginHandlers) serveLoginGet(p httprequest.Params) (interface{}, error) {
	if p.Request.Header.Get("Accept") == "application/json" {
		// The application/json content-type is used to
		// inform the client of the supported auth methods.
		return map[string]string{
			"juju_userpass": p.Request.URL.String(),
		}, nil
	}
	// TODO(axw) return an HTML form. If waitid is supplied,
	// it should be passed through so we can unblock a request
	// on the /auth/wait endpoint. We should also support logging
	// in when not specifically directed to the login page.
	return nil, errors.NotImplementedf("GET")
}
Beispiel #21
0
func (inst *localInstance) Addresses() ([]network.Address, error) {
	if inst.id == bootstrapInstanceId {
		addrs := []network.Address{{
			Scope: network.ScopePublic,
			Type:  network.HostName,
			Value: "localhost",
		}, {
			Scope: network.ScopeCloudLocal,
			Type:  network.IPv4Address,
			Value: inst.env.bridgeAddress,
		}}
		return addrs, nil
	}
	return nil, errors.NotImplementedf("localInstance.Addresses")
}
Beispiel #22
0
func (t *localServerSuite) TestStartInstanceDistributionAZNotImplemented(c *gc.C) {
	env := t.Prepare(c)
	envtesting.UploadFakeTools(c, env.Storage())
	err := bootstrap.Bootstrap(coretesting.Context(c), env, environs.BootstrapParams{})
	c.Assert(err, gc.IsNil)

	mock := mockAvailabilityZoneAllocations{
		err: jujuerrors.NotImplementedf("availability zones"),
	}
	t.PatchValue(openstack.AvailabilityZoneAllocations, mock.AvailabilityZoneAllocations)

	// Instance will be created without an availability zone specified.
	inst, _ := testing.AssertStartInstance(c, env, "1")
	c.Assert(openstack.InstanceServerDetail(inst).AvailabilityZone, gc.Equals, "")
}
Beispiel #23
0
// StorageAttachmentLife returns the lifecycle state of the storage attachments
// with the specified IDs.
func (sa *StorageAccessor) StorageAttachmentLife(ids []params.StorageAttachmentId) ([]params.LifeResult, error) {
	if sa.facade.BestAPIVersion() < 2 {
		return nil, errors.NotImplementedf("StorageAttachmentLife() (need V2+)")
	}
	args := params.StorageAttachmentIds{ids}
	var results params.LifeResults
	err := sa.facade.FacadeCall("StorageAttachmentLife", args, &results)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if len(results.Results) != len(ids) {
		panic(errors.Errorf("expected %d results, got %d", len(ids), len(results.Results)))
	}
	return results.Results, nil
}
Beispiel #24
0
// UnitStatusHistory retrieves the last <size> results of <kind:combined|agent|workload> status
// for <unitName> unit
func (c *Client) UnitStatusHistory(kind params.HistoryKind, unitName string, size int) (*UnitStatusHistory, error) {
	var results UnitStatusHistory
	args := params.StatusHistory{
		Kind: kind,
		Size: size,
		Name: unitName,
	}
	err := c.facade.FacadeCall("UnitStatusHistory", args, &results)
	if err != nil {
		if params.IsCodeNotImplemented(err) {
			return &UnitStatusHistory{}, errors.NotImplementedf("UnitStatusHistory")
		}
		return &UnitStatusHistory{}, errors.Trace(err)
	}
	return &results, nil
}
Beispiel #25
0
// SetUnitStatus sets the status of the unit.
func (u *Unit) SetUnitStatus(status params.Status, info string, data map[string]interface{}) error {
	if u.st.facade.BestAPIVersion() < 2 {
		return errors.NotImplementedf("SetUnitStatus")
	}
	var result params.ErrorResults
	args := params.SetStatus{
		Entities: []params.EntityStatusArgs{
			{Tag: u.tag.String(), Status: status, Info: info, Data: data},
		},
	}
	err := u.st.facade.FacadeCall("SetUnitStatus", args, &result)
	if err != nil {
		return errors.Trace(err)
	}
	return result.OneError()
}
Beispiel #26
0
// maybeCopyControllerSecrets asks the specified provider for all possible config
// attributes representing credential values and copies those across from the
// controller config into the new model's config attrs if not already present.
func maybeCopyControllerSecrets(provider environs.ProviderCredentials, controllerAttrs, attrs map[string]interface{}) {
	requiredControllerAttrNames := []string{"authorized-keys"}
	var controllerCredentialAttrNames []string
	for _, schema := range provider.CredentialSchemas() {
		// possibleCredentialValues holds any values from attrs that belong to
		// the credential schema.
		possibleCredentialValues := make(map[string]string)
		for _, attr := range schema {
			attrName := attr.Name
			if v, ok := attrs[attrName]; ok && v != "" {
				possibleCredentialValues[attrName] = fmt.Sprintf("%v", attrs[attrName])
			}
			controllerCredentialAttrNames = append(controllerCredentialAttrNames, attrName)
		}
		// readFile is not needed server side.
		readFile := func(string) ([]byte, error) {
			return nil, errors.NotImplementedf("read file")
		}
		// If the user has passed in valid credentials, we'll use
		// those and not the ones from the controller.
		if len(possibleCredentialValues) == 0 {
			continue
		}
		finalValues, err := schema.Finalize(possibleCredentialValues, readFile)
		if err == nil {
			for k, v := range finalValues {
				attrs[k] = v
			}
			controllerCredentialAttrNames = nil
			break
		}
	}

	// Ensure any required attributes which are empty are copied from the controller config.
	for _, attrName := range requiredControllerAttrNames {
		if _, ok := attrs[attrName]; !ok {
			attrs[attrName] = controllerAttrs[attrName]
		}
	}
	for _, attrName := range controllerCredentialAttrNames {
		if _, ok := attrs[attrName]; !ok {
			attrs[attrName] = controllerAttrs[attrName]
		}
	}
}
Beispiel #27
0
// AvailabilityZones returns a slice of availability zones.
func (e *Environ) AvailabilityZones() ([]common.AvailabilityZone, error) {
	e.availabilityZonesMutex.Lock()
	defer e.availabilityZonesMutex.Unlock()
	if e.availabilityZones == nil {
		zones, err := novaListAvailabilityZones(e.nova())
		if gooseerrors.IsNotImplemented(err) {
			return nil, errors.NotImplementedf("availability zones")
		}
		if err != nil {
			return nil, err
		}
		e.availabilityZones = make([]common.AvailabilityZone, len(zones))
		for i, z := range zones {
			e.availabilityZones[i] = &openstackAvailabilityZone{z}
		}
	}
	return e.availabilityZones, nil
}
Beispiel #28
0
// WriteContent writes the resource file to the given path
// within the directory.
func (dir *Directory) WriteContent(relPath string, content Content) error {
	if len(relPath) == 0 {
		// TODO(ericsnow) Use rd.readInfo().Path, like openResource() does?
		return errors.NotImplementedf("")
	}
	filename := dir.Resolve(relPath)

	target, err := dir.Deps.CreateWriter(filename)
	if err != nil {
		return errors.Annotate(err, "could not create new file for resource")
	}
	defer dir.Deps.CloseAndLog(target, filename)

	if err := dir.Deps.WriteContent(target, content); err != nil {
		return errors.Trace(err)
	}

	return nil
}
Beispiel #29
0
// AddStorage adds desired storage instances to a unit.
func (u *Unit) AddStorage(constraints map[string][]params.StorageConstraints) error {
	if u.st.facade.BestAPIVersion() < 2 {
		return errors.NotImplementedf("AddStorage() (need V2+)")
	}

	all := make([]params.StorageAddParams, 0, len(constraints))
	for storage, cons := range constraints {
		for _, one := range cons {
			all = append(all, params.StorageAddParams{u.Tag().String(), storage, one})
		}
	}

	args := params.StoragesAddParams{Storages: all}
	var results params.ErrorResults
	err := u.st.facade.FacadeCall("AddUnitStorage", args, &results)
	if err != nil {
		return err
	}

	return results.Combine()
}
Beispiel #30
0
// DestroyUnitStorageAttachments ensures that the specified unit's storage
// attachments will be removed at some point in the future.
func (sa *StorageAccessor) DestroyUnitStorageAttachments(unitTag names.UnitTag) error {
	if sa.facade.BestAPIVersion() < 2 {
		return errors.NotImplementedf("DestroyUnitStorageAttachments() (need V2+)")
	}
	args := params.Entities{
		Entities: []params.Entity{{Tag: unitTag.String()}},
	}
	var results params.ErrorResults
	err := sa.facade.FacadeCall("DestroyUnitStorageAttachments", args, &results)
	if err != nil {
		return errors.Trace(err)
	}
	if len(results.Results) != 1 {
		panic(errors.Errorf("expected 1 result, got %d", len(results.Results)))
	}
	result := results.Results[0]
	if result.Error != nil {
		return result.Error
	}
	return nil
}