本文整理汇总了Golang中github.com/juju/juju/api.Client.ServiceGetCharmURL方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.ServiceGetCharmURL方法的具体用法?Golang Client.ServiceGetCharmURL怎么用?Golang Client.ServiceGetCharmURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api.Client
的用法示例。
在下文中一共展示了Client.ServiceGetCharmURL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upgradeCharm
// upgradeCharm upgrades the charm for the given service to the given charm id.
// If the service is already deployed using the given charm id, do nothing.
// This function returns an error if the existing charm and the target one are
// incompatible, meaning an upgrade from one to the other is not allowed.
func upgradeCharm(client *api.Client, log deploymentLogger, service, id string) error {
existing, err := client.ServiceGetCharmURL(service)
if err != nil {
return errors.Annotatef(err, "cannot retrieve info for service %q", service)
}
if existing.String() == id {
log.Infof("reusing service %s (charm: %s)", service, id)
return nil
}
url, err := charm.ParseURL(id)
if err != nil {
return errors.Annotatef(err, "cannot parse charm URL %q", id)
}
if url.WithRevision(-1).Path() != existing.WithRevision(-1).Path() {
return errors.Errorf("bundle charm %q is incompatible with existing charm %q", id, existing)
}
if err := client.ServiceSetCharm(service, id, false); err != nil {
return errors.Annotatef(err, "cannot upgrade charm to %q", id)
}
log.Infof("upgraded charm for existing service %s (from %s to %s)", service, existing, id)
return nil
}