// SetUnit sets the Unit field's value.
970542
func (s *CustomizedLoadMetricSpecification) SetUnit(v string) *CustomizedLoadMetricSpecification {
	s.Unit = &v
	return s
}
1208262
func (pb *Bar) SetUnits(units Units) *Bar {
	pb.Units = units
	return pb
}
717197
func (s *MetricAlarm) SetUnit(v string) *MetricAlarm {
	s.Unit = &v
	return s
}
977098
func (s *ReportDefinition) SetTimeUnit(v string) *ReportDefinition {
	s.TimeUnit = &v
	return s
}
359156
func (s *BudgetPerformanceHistory) SetTimeUnit(v string) *BudgetPerformanceHistory {
	s.TimeUnit = &v
	return s
}
944540
func (s *CloudWatchAlarmDefinition) SetUnit(v string) *CloudWatchAlarmDefinition {
	s.Unit = &v
	return s
}
831078
func (s *AutoScalingSettingsUpdate) SetMinimumUnits(v int64) *AutoScalingSettingsUpdate {
	s.MinimumUnits = &v
	return s
}
8078
func (uw *UnitWriter) WriteUnit(path string, errmsg string, opts ...*unit.UnitOption) {
	if uw.err != nil {
		return
	}

	file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		uw.err = errwrap.Wrap(errors.New(errmsg), err)
		return
	}
	defer file.Close()

	if _, err = io.Copy(file, unit.Serialize(opts)); err != nil {
		uw.err = errwrap.Wrap(errors.New(errmsg), err)
		return
	}
	if err := user.ShiftFiles([]string{path}, &uw.p.UidRange); err != nil {
		uw.err = errwrap.Wrap(errors.New(errmsg), err)
		return
	}
}
1055444
func (a *Application) AddUnit(args AddUnitParams) (unit *Unit, err error) {
	defer errors.DeferredAnnotatef(&err, "cannot add unit to application %q", a)
	name, ops, err := a.addUnitOps("", args, nil)
	if err != nil {
		return nil, err
	}

	if err := a.st.db().RunTransaction(ops); err == txn.ErrAborted {
		if alive, err := isAlive(a.st, applicationsC, a.doc.DocID); err != nil {
			return nil, err
		} else if !alive {
			return nil, applicationNotAliveErr
		}
		return nil, errors.New("inconsistent state")
	} else if err != nil {
		return nil, err
	}
	return a.st.Unit(name)
}
39490
func (s *CustomizedMetricSpecification) SetUnit(v string) *CustomizedMetricSpecification {
	s.Unit = &v
	return s
}
1210220
func (s *AutoScalingSettingsDescription) SetMaximumUnits(v int64) *AutoScalingSettingsDescription {
	s.MaximumUnits = &v
	return s
}
1283886
func (s *DescribeOrganizationalUnitOutput) SetOrganizationalUnit(v *OrganizationalUnit) *DescribeOrganizationalUnitOutput {
	s.OrganizationalUnit = v
	return s
}
1368740
func (s *CustomizedScalingMetricSpecification) SetUnit(v string) *CustomizedScalingMetricSpecification {
	s.Unit = &v
	return s
}
1017084
func (s *CreateRule) SetIntervalUnit(v string) *CreateRule {
	s.IntervalUnit = &v
	return s
}
1354516
func (s *AutoScalingSettingsDescription) SetMinimumUnits(v int64) *AutoScalingSettingsDescription {
	s.MinimumUnits = &v
	return s
}
294075
func (u *Unit) SetMeterStatus(codeStr, info string) error {
	code, err := isValidMeterStatusCode(codeStr)
	if err != nil {
		return errors.Trace(err)
	}
	meterDoc, err := u.getMeterStatusDoc()
	if err != nil {
		return errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
	}
	if meterDoc.Code == code.String() && meterDoc.Info == info {
		return nil
	}

	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			err := u.Refresh()
			if err != nil {
				return nil, errors.Trace(err)
			}
			meterDoc, err = u.getMeterStatusDoc()
			if err != nil {
				return nil, errors.Annotatef(err, "cannot update meter status for unit %s", u.Name())
			}
			if meterDoc.Code == code.String() && meterDoc.Info == info {
				return nil, jujutxn.ErrNoOperations
			}
		}
		return []txn.Op{
			{
				C:      unitsC,
				Id:     u.doc.DocID,
				Assert: isAliveDoc,
			}, {
				C:      meterStatusC,
				Id:     u.st.docID(u.globalMeterStatusKey()),
				Assert: txn.DocExists,
				Update: bson.D{{"$set", bson.D{{"code", code.String()}, {"info", info}}}},
			}}, nil
	}
	return errors.Annotatef(u.st.db().Run(buildTxn), "cannot set meter state for unit %s", u.Name())
}
555499
func (a Amount) ToUnit(u AmountUnit) float64 {
	return float64(a) / math.Pow10(int(u+8))
}