本文整理汇总了Golang中github.com/juju/version.Number类的典型用法代码示例。如果您正苦于以下问题:Golang Number类的具体用法?Golang Number怎么用?Golang Number使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Number类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: bundleTools
// bundleTools bundles all the current juju tools in gzipped tar
// format to the given writer.
// If forceVersion is not nil, a FORCE-VERSION file is included in
// the tools bundle so it will lie about its current version number.
func bundleTools(build bool, w io.Writer, forceVersion *version.Number) (tvers version.Binary, sha256Hash string, err error) {
dir, err := ioutil.TempDir("", "juju-tools")
if err != nil {
return version.Binary{}, "", err
}
defer os.RemoveAll(dir)
if err := packageLocalTools(dir, build); err != nil {
return version.Binary{}, "", err
}
// Extract the version number that the jujud binary was built with.
// This is used to check compatibility with the version of the client
// being used to bootstrap.
tvers, err = getVersionFromJujud(dir)
if err != nil {
return version.Binary{}, "", errors.Trace(err)
}
if forceVersion != nil {
logger.Debugf("forcing version to %s", forceVersion)
if err := ioutil.WriteFile(filepath.Join(dir, "FORCE-VERSION"), []byte(forceVersion.String()), 0666); err != nil {
return version.Binary{}, "", err
}
}
sha256hash, err := archiveAndSHA256(w, dir)
if err != nil {
return version.Binary{}, "", err
}
return tvers, sha256hash, err
}
示例2: NewDbLogger
// NewDbLogger returns a DbLogger instance which is used to write logs
// to the database.
func NewDbLogger(st ModelSessioner, entity names.Tag, ver version.Number) *DbLogger {
_, logsColl := initLogsSession(st)
return &DbLogger{
logsColl: logsColl,
modelUUID: st.ModelUUID(),
entity: entity.String(),
version: ver.String(),
}
}
示例3: TestUpgradeOperationsOrdered
func (s *upgradeSuite) TestUpgradeOperationsOrdered(c *gc.C) {
var previous version.Number
for i, utv := range (*upgrades.UpgradeOperations)() {
vers := utv.TargetVersion()
if i > 0 {
c.Check(previous.Compare(vers), gc.Equals, -1)
}
previous = vers
}
}
示例4: checkUpgradeInfoSanity
func checkUpgradeInfoSanity(st *State, machineId string, previousVersion, targetVersion version.Number) (bson.D, error) {
if previousVersion.Compare(targetVersion) != -1 {
return nil, errors.Errorf("cannot sanely upgrade from %s to %s", previousVersion, targetVersion)
}
controllerInfo, err := st.ControllerInfo()
if err != nil {
return nil, errors.Annotate(err, "cannot read controllers")
}
validIds := set.NewStrings(controllerInfo.MachineIds...)
if !validIds.Contains(machineId) {
return nil, errors.Errorf("machine %q is not a controller", machineId)
}
return assertExpectedVersions(previousVersion, targetVersion), nil
}
示例5: Newest
// Newest returns the greatest version in src, and the tools with that version.
func (src List) Newest() (version.Number, List) {
var result List
var best version.Number
for _, tools := range src {
if best.Compare(tools.Version.Number) < 0 {
// Found new best number; reset result list.
best = tools.Version.Number
result = append(result[:0], tools)
} else if tools.Version.Number == best {
result = append(result, tools)
}
}
return best, result
}
示例6: UpdateLatestToolsVersion
// UpdateLatestToolsVersion looks up for the latest available version of
// juju tools and updates environementDoc with it.
func (m *Model) UpdateLatestToolsVersion(ver version.Number) error {
v := ver.String()
// TODO(perrito666): I need to assert here that there isn't a newer
// version in place.
ops := []txn.Op{{
C: modelsC,
Id: m.doc.UUID,
Update: bson.D{{"$set", bson.D{{"available-tools", v}}}},
}}
err := m.st.runTransaction(ops)
if err != nil {
return errors.Trace(err)
}
return m.Refresh()
}
示例7: setBootstrapToolsVersion
// setBootstrapToolsVersion updates the agent-version configuration attribute.
func setBootstrapToolsVersion(environ environs.Environ, toolsVersion version.Number) error {
cfg := environ.Config()
if agentVersion, _ := cfg.AgentVersion(); agentVersion != toolsVersion {
cfg, err := cfg.Apply(map[string]interface{}{
"agent-version": toolsVersion.String(),
})
if err == nil {
err = environ.SetConfig(cfg)
}
if err != nil {
return errors.Errorf("failed to update model configuration: %v", err)
}
}
return nil
}
示例8: GUISetVersion
// GUISetVersion sets the Juju GUI version that the controller must serve.
func (st *State) GUISetVersion(vers version.Number) error {
// Check that the provided version is actually present in the GUI storage.
storage, err := st.GUIStorage()
if err != nil {
return errors.Annotate(err, "cannot open GUI storage")
}
defer storage.Close()
if _, err = storage.Metadata(vers.String()); err != nil {
return errors.Annotatef(err, "cannot find %q GUI version in the storage", vers)
}
// Set the current version.
settings, closer := st.getCollection(guisettingsC)
defer closer()
if _, err = settings.Writeable().Upsert(nil, bson.D{{"current-version", vers}}); err != nil {
return errors.Annotate(err, "cannot set current GUI version")
}
return nil
}
示例9: uploadVersion
// uploadVersion returns a copy of the supplied version with a build number
// higher than any of the supplied tools that share its major, minor and patch.
func uploadVersion(vers version.Number, existing coretools.List) version.Number {
vers.Build++
for _, t := range existing {
if t.Version.Major != vers.Major || t.Version.Minor != vers.Minor || t.Version.Patch != vers.Patch {
continue
}
if t.Version.Build >= vers.Build {
vers.Build = t.Version.Build + 1
}
}
return vers
}
示例10: newOpsIterator
func newOpsIterator(from, to version.Number, ops []Operation) *opsIterator {
// If from is not known, it is 1.16.
if from == version.Zero {
from = version.MustParse("1.16.0")
}
// Clear the version tag of the target release to ensure that all
// upgrade steps for the release are run for alpha and beta
// releases.
// ...but only do this if the agent version has actually changed,
// lest we trigger upgrade mode unnecessarily for non-final
// versions.
if from.Compare(to) != 0 {
to.Tag = ""
}
return &opsIterator{
from: from,
to: to,
allOps: ops,
current: -1,
}
}
示例11: UploadGUIArchive
// UploadGUIArchive uploads a GUI archive to the controller over HTTPS, and
// reports about whether the upload updated the current GUI served by Juju.
func (c *Client) UploadGUIArchive(r io.ReadSeeker, hash string, size int64, vers version.Number) (current bool, err error) {
// Prepare the request.
v := url.Values{}
v.Set("version", vers.String())
v.Set("hash", hash)
req, err := http.NewRequest("POST", guiArchivePath+"?"+v.Encode(), nil)
if err != nil {
return false, errors.Annotate(err, "cannot create upload request")
}
req.Header.Set("Content-Type", "application/x-tar-bzip2")
req.ContentLength = size
// Retrieve a client and send the request.
httpClient, err := c.facade.RawAPICaller().HTTPClient()
if err != nil {
return false, errors.Annotate(err, "cannot retrieve HTTP client")
}
var resp params.GUIArchiveVersion
if err = httpClient.Do(req, r, &resp); err != nil {
return false, errors.Annotate(err, "cannot upload the GUI archive")
}
return resp.Current, nil
}
示例12: bundleTools
// BundleTools bundles all the current juju tools in gzipped tar
// format to the given writer.
// If forceVersion is not nil, a FORCE-VERSION file is included in
// the tools bundle so it will lie about its current version number.
func bundleTools(w io.Writer, forceVersion *version.Number) (tvers version.Binary, sha256Hash string, err error) {
dir, err := ioutil.TempDir("", "juju-tools")
if err != nil {
return version.Binary{}, "", err
}
defer os.RemoveAll(dir)
if err := copyExistingJujud(dir); err != nil {
logger.Debugf("copy existing failed: %v", err)
if err := buildJujud(dir); err != nil {
return version.Binary{}, "", err
}
}
if forceVersion != nil {
logger.Debugf("forcing version to %s", forceVersion)
if err := ioutil.WriteFile(filepath.Join(dir, "FORCE-VERSION"), []byte(forceVersion.String()), 0666); err != nil {
return version.Binary{}, "", err
}
}
cmd := exec.Command(filepath.Join(dir, names.Jujud), "version")
out, err := cmd.CombinedOutput()
if err != nil {
return version.Binary{}, "", fmt.Errorf("cannot get version from %q: %v; %s", cmd.Args[0], err, out)
}
tvs := strings.TrimSpace(string(out))
tvers, err = version.ParseBinary(tvs)
if err != nil {
return version.Binary{}, "", fmt.Errorf("invalid version %q printed by jujud", tvs)
}
sha256hash, err := archiveAndSHA256(w, dir)
if err != nil {
return version.Binary{}, "", err
}
return tvers, sha256hash, err
}
示例13: SetBootstrapEndpointAddress
// SetBootstrapEndpointAddress writes the API endpoint address of the
// bootstrap server, plus the agent version, into the connection information.
// This should only be run once directly after Bootstrap. It assumes that
// there is just one instance in the environment - the bootstrap instance.
func SetBootstrapEndpointAddress(
store jujuclient.ControllerStore,
controllerName string, agentVersion version.Number,
apiPort int, environ environs.Environ,
) error {
instances, err := allInstances(environ)
if err != nil {
return errors.Trace(err)
}
length := len(instances)
if length == 0 {
return errors.Errorf("found no instances, expected at least one")
}
if length > 1 {
return errors.Errorf("expected one instance, got %d", length)
}
bootstrapInstance := instances[0]
// Don't use c.ConnectionEndpoint as it attempts to contact the state
// server if no addresses are found in connection info.
netAddrs, err := bootstrapInstance.Addresses()
if err != nil {
return errors.Annotate(err, "failed to get bootstrap instance addresses")
}
apiHostPorts := network.AddressesWithPort(netAddrs, apiPort)
// At bootstrap we have 2 models, the controller model and the default.
two := 2
params := juju.UpdateControllerParams{
AgentVersion: agentVersion.String(),
AddrConnectedTo: apiHostPorts,
MachineCount: &length,
ControllerMachineCount: &length,
ModelCount: &two,
}
return juju.UpdateControllerDetailsFromLogin(store, controllerName, params)
}
示例14: IsDev
// IsDev returns whether the version represents a development version. A
// version with a tag or a nonzero build component is considered to be a
// development version. Versions older than or equal to 1.19.3 (the switch
// over time) check for odd minor versions.
func IsDev(v semversion.Number) bool {
if v.Compare(switchOverVersion) <= 0 {
return isOdd(v.Minor) || v.Build > 0
}
return v.Tag != "" || v.Build > 0
}