Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Add upgrade packages task
Browse files Browse the repository at this point in the history
This adds a simple upgrade packages task, meaning we can simultaneously
update packages, optionally to a specific version. For example,

fab upgrade_packages:'["package1", {"package2", "1.2.3"}]'
  - get the latest versions of package1, and version 1.2.3 of package2
  • Loading branch information
Niall Creech committed Feb 23, 2016
1 parent 8af470a commit b3f7314
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions bootstrap_salt/fab_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import gnupg
import base64
import shutil
logging.basicConfig(level=logging.INFO)

import bootstrap_cfn.config as config
from fabric.api import env, task, local, get, settings, sudo
from fabric.api import env, execute, parallel, task, local, get, settings, sudo
from fabric.contrib import files
import fabric.decorators
from bootstrap_cfn.fab_tasks import _validate_fabric_env, \
get_stack_name, get_config, cfn_create, cfn_delete

Expand All @@ -29,6 +29,9 @@

from .deploy_lib import github

# Setup logging
logging.basicConfig(level=logging.INFO)

# GLOBAL VARIABLES
env.aws = None
TIMEOUT = 3600
Expand Down Expand Up @@ -449,3 +452,36 @@ def check_admins_exist():
% (', '.join(admins_dict.keys()),
host_ip)))
return True


@task
def upgrade_packages(packages, fraction=None, restart=False):
"""
Upgrade the packages specified, optionally rebooting afterwards
Args:
packages(list): List of packages to update. These can be a simple list
or with package versions, for example
'["package1", "package2"]' - get the latest versions of package1 and package2
'["package1", {"package2", "1.2.3"}]' - get the latest versions of package1,
and version 1.2.3 of package2.
fraction(float): The decimal fraction of minions to deploy to None means
all in one batch
restart(bool): False to not reboot after installation, True to reboot the instance.
"""
for batch in get_ips_batch(fraction):
rup = fabric.decorators.hosts(batch)(run_upgrade_packages)
execute(rup, packages, fraction, restart)


@parallel
def run_upgrade_packages(packages, fraction=None, restart=False):
state = "pkg.install refresh=True only_upgrade=True pkgs='{}'".format(packages)
if fraction:
sudo('/usr/bin/salt-call {}'.format(state), shell=False)
if restart:
sudo('/usr/bin/salt-call system.reboot', shell=False)
else:
sudo('/usr/bin/salt-call {}'.format(state), shell=False)
if restart:
sudo('/usr/bin/salt-call system.reboot', shell=False)

0 comments on commit b3f7314

Please sign in to comment.