本文整理汇总了Golang中github.com/juju/utils/packaging/manager.NewPackageManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPackageManager函数的具体用法?Golang NewPackageManager怎么用?Golang NewPackageManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPackageManager函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetUpTest
func (s *prereqsSuite) SetUpTest(c *gc.C) {
s.BaseSuite.SetUpTest(c)
s.tmpdir = c.MkDir()
s.testMongodPath = filepath.Join(s.tmpdir, "mongod")
s.PatchEnvironment("PATH", s.tmpdir)
s.PatchValue(&mongo.JujuMongodPath, "/somewhere/that/wont/exist")
os.Setenv("JUJUTEST_LSB_RELEASE_ID", "Ubuntu")
err := ioutil.WriteFile(filepath.Join(s.tmpdir, "lsb_release"), []byte(lsbrelease), 0777)
c.Assert(err, jc.ErrorIsNil)
// symlink $temp/dpkg-query to /bin/true, to
// simulate package installation query responses.
pm, err := testing.GetPackageManager()
c.Assert(err, jc.ErrorIsNil)
err = symlink.New("/bin/true", filepath.Join(s.tmpdir, pm.PackageQuery))
c.Assert(err, jc.ErrorIsNil)
s.PatchValue(&isPackageInstalled, func(pack string) bool {
pacman, err := manager.NewPackageManager(series.HostSeries())
c.Assert(err, jc.ErrorIsNil)
return pacman.IsInstalled(pack)
})
}
示例2: satisfyPrerequisites
func satisfyPrerequisites(operatingsystem string) error {
// CentOS is not currently supported by our mongo package.
if operatingsystem == "centos7" {
return errors.New("centos7 is still not suported by this upgrade")
}
pacman, err := manager.NewPackageManager(operatingsystem)
if err != nil {
return errors.Annotatef(err, "cannot obtain package manager for %q", operatingsystem)
}
if err := pacman.InstallPrerequisite(); err != nil {
return err
}
if err := pacman.Install("juju-mongodb2.6"); err != nil {
return errors.Annotate(err, "cannot install juju-mongodb2.6")
}
// JujuMongoPackage represents a version of mongo > 3.1 .
if err := pacman.Install(mongo.JujuMongoPackage); err != nil {
return errors.Annotatef(err, "cannot install %v", mongo.JujuMongoPackage)
}
if err := pacman.Install(mongo.JujuMongoToolsPackage); err != nil {
return errors.Annotatef(err, "cannot install %v", mongo.JujuMongoToolsPackage)
}
return nil
}
示例3: getPackageManager
// getPackageManager is a helper function which returns the
// package manager implementation for the current system.
func getPackageManager() (manager.PackageManager, error) {
return manager.NewPackageManager(series.HostSeries())
}
示例4: getPackageManager
// getPackageManager is a helper function which returns the
// package manager implementation for the current system.
func getPackageManager() (manager.PackageManager, error) {
return manager.NewPackageManager(version.Current.Series)
}
示例5: getPackageManager
// getPackageManager is a helper function which returns the
// package manager implementation for the current system.
func getPackageManager(series string) (manager.PackageManager, error) {
return manager.NewPackageManager(series)
}
示例6: installMongod
func installMongod(operatingsystem string, numaCtl bool) error {
// fetch the packaging configuration manager for the current operating system.
pacconfer, err := config.NewPackagingConfigurer(operatingsystem)
if err != nil {
return err
}
// fetch the package manager implementation for the current operating system.
pacman, err := manager.NewPackageManager(operatingsystem)
if err != nil {
return err
}
// Only Quantal requires the PPA.
if operatingsystem == "quantal" {
// install python-software-properties:
if err := pacman.InstallPrerequisite(); err != nil {
return err
}
if err := pacman.AddRepository("ppa:juju/stable"); err != nil {
return err
}
}
// CentOS requires "epel-release" for the epel repo mongodb-server is in.
if operatingsystem == "centos7" {
// install epel-release
if err := pacman.Install("epel-release"); err != nil {
return err
}
}
mongoPkg := packageForSeries(operatingsystem)
pkgs := []string{mongoPkg}
if numaCtl {
pkgs = []string{mongoPkg, numaCtlPkg}
logger.Infof("installing %s and %s", mongoPkg, numaCtlPkg)
} else {
logger.Infof("installing %s", mongoPkg)
}
for i, _ := range pkgs {
// apply release targeting if needed.
if pacconfer.IsCloudArchivePackage(pkgs[i]) {
pkgs[i] = strings.Join(pacconfer.ApplyCloudArchiveTarget(pkgs[i]), " ")
}
if err := pacman.Install(pkgs[i]); err != nil {
return err
}
}
// Work around SELinux on centos7
if operatingsystem == "centos7" {
cmd := []string{"chcon", "-R", "-v", "-t", "mongod_var_lib_t", "/var/lib/juju/"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
logger.Errorf("chcon failed to change file security context error %s", err)
return err
}
cmd = []string{"semanage", "port", "-a", "-t", "mongod_port_t", "-p", "tcp", strconv.Itoa(environs.DefaultStatePort)}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
if !strings.Contains(err.Error(), "exit status 1") {
logger.Errorf("semanage failed to provide access on port %d error %s", environs.DefaultStatePort, err)
return err
}
}
}
return nil
}
示例7: installMongod
func installMongod(operatingsystem string, numaCtl bool) error {
// fetch the packaging configuration manager for the current operating system.
pacconfer, err := config.NewPackagingConfigurer(operatingsystem)
if err != nil {
return err
}
// fetch the package manager implementation for the current operating system.
pacman, err := manager.NewPackageManager(operatingsystem)
if err != nil {
return err
}
// CentOS requires "epel-release" for the epel repo mongodb-server is in.
if operatingsystem == "centos7" {
// install epel-release
if err := pacman.Install("epel-release"); err != nil {
return err
}
}
mongoPkgs, fallbackPkgs := packagesForSeries(operatingsystem)
if numaCtl {
logger.Infof("installing %v and %s", mongoPkgs, numaCtlPkg)
if err = installPackage(numaCtlPkg, pacconfer, pacman); err != nil {
return errors.Trace(err)
}
} else {
logger.Infof("installing %v", mongoPkgs)
}
for i := range mongoPkgs {
if err = installPackage(mongoPkgs[i], pacconfer, pacman); err != nil {
break
}
}
if err != nil && len(fallbackPkgs) == 0 {
return errors.Trace(err)
}
if err != nil {
logger.Errorf("installing mongo failed: %v", err)
logger.Infof("will try fallback packages %v", fallbackPkgs)
for i := range fallbackPkgs {
if err = installPackage(fallbackPkgs[i], pacconfer, pacman); err != nil {
return errors.Trace(err)
}
}
}
// Work around SELinux on centos7
if operatingsystem == "centos7" {
cmd := []string{"chcon", "-R", "-v", "-t", "mongod_var_lib_t", "/var/lib/juju/"}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
logger.Errorf("chcon failed to change file security context error %s", err)
return err
}
cmd = []string{"semanage", "port", "-a", "-t", "mongod_port_t", "-p", "tcp", strconv.Itoa(environs.DefaultStatePort)}
logger.Infof("running %s %v", cmd[0], cmd[1:])
_, err = utils.RunCommand(cmd[0], cmd[1:]...)
if err != nil {
if !strings.Contains(err.Error(), "exit status 1") {
logger.Errorf("semanage failed to provide access on port %d error %s", environs.DefaultStatePort, err)
return err
}
}
}
return nil
}
示例8:
// Licensed under the AGPLv3, see LICENCE file for details.
package local
import (
"github.com/juju/utils/packaging/manager"
"github.com/juju/utils/proxy"
"github.com/juju/utils/series"
)
// isPackageInstalled is a helper function which instantiates a new
// PackageManager for the current system and checks whether the given package is
// installed.
var isPackageInstalled = func(pack string) bool {
// We know that there exists a package manager for this OS as the agent has
// been bootstrapped.
pacman, _ := manager.NewPackageManager(series.HostSeries())
return pacman.IsInstalled(pack)
}
// detectPackageProxies is a helper function which instantiates a new
// PackageManager for the current system and checks for package manager proxy
// settings.
var detectPackageProxies = func() (proxy.Settings, error) {
pacman, err := manager.NewPackageManager(series.HostSeries())
if err != nil {
return proxy.Settings{}, err
}
return pacman.GetProxySettings()
}