Ejemplo n.º 1
0
// PrivateAddress returns the private address for each given unit, if set.
func (u *UniterAPI) PrivateAddress(args params.Entities) (params.StringResults, error) {
	result := params.StringResults{
		Results: make([]params.StringResult, len(args.Entities)),
	}
	canAccess, err := u.accessUnit()
	if err != nil {
		return params.StringResults{}, err
	}
	for i, entity := range args.Entities {
		err := common.ErrPerm
		if canAccess(entity.Tag) {
			var unit *state.Unit
			unit, err = u.getUnit(entity.Tag)
			if err == nil {
				address, ok := unit.PrivateAddress()
				if ok {
					result.Results[i].Result = address
				} else {
					err = common.NoAddressSetError(entity.Tag, "private")
				}
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
Ejemplo n.º 2
0
Archivo: uniter.go Proyecto: bac/juju
// PrivateAddress returns the private address for each given unit, if set.
func (u *UniterAPIV3) PrivateAddress(args params.Entities) (params.StringResults, error) {
	result := params.StringResults{
		Results: make([]params.StringResult, len(args.Entities)),
	}
	canAccess, err := u.accessUnit()
	if err != nil {
		return params.StringResults{}, err
	}
	for i, entity := range args.Entities {
		tag, err := names.ParseUnitTag(entity.Tag)
		if err != nil {
			result.Results[i].Error = common.ServerError(common.ErrPerm)
			continue
		}
		err = common.ErrPerm
		if canAccess(tag) {
			var unit *state.Unit
			unit, err = u.getUnit(tag)
			if err == nil {
				var address network.Address
				address, err = unit.PrivateAddress()
				if err == nil {
					result.Results[i].Result = address.Value
				} else if network.IsNoAddressError(err) {
					err = common.NoAddressSetError(tag, "private")
				}
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
Ejemplo n.º 3
0
func unitMatchSubnet(u *state.Unit, patterns []string) (bool, bool, error) {
	pub, pubOK := u.PublicAddress()
	priv, privOK := u.PrivateAddress()
	if !pubOK && !privOK {
		return true, false, nil
	}
	return matchSubnet(patterns, pub, priv)
}
Ejemplo n.º 4
0
func unitMatchSubnet(u *state.Unit, patterns []string) (bool, bool, error) {
	pub, pubErr := u.PublicAddress()
	if pubErr != nil && !network.IsNoAddress(pubErr) {
		return true, false, errors.Trace(pubErr)
	}
	priv, privErr := u.PrivateAddress()
	if privErr != nil && !network.IsNoAddress(privErr) {
		return true, false, errors.Trace(privErr)
	}
	if pubErr != nil && privErr != nil {
		return true, false, nil
	}
	return matchSubnet(patterns, pub.Value, priv.Value)
}