FAQ | This is a LIVE service | Changelog

Commit 345340f3 authored by Monty Dawson's avatar Monty Dawson
Browse files

Merge branch 'optional-licensing' into 'master'

Make licensing update optional

See merge request !25
parents 72d39e65 cbea338a
Pipeline #218168 passed with stages
in 3 minutes and 17 seconds
......@@ -4,7 +4,7 @@ Synchronise users to GSuite
Usage:
gsuitesync (-h | --help)
gsuitesync [--configuration=FILE] [--quiet] [--group-settings] [--just-users]
[--really-do-this]
[--licensing] [--really-do-this]
Options:
-h, --help Show a brief usage summary.
......@@ -15,7 +15,9 @@ Options:
--group-settings Also update group settings on all groups
--just-users just compare users not groups and institutions
--just-users Just compare users not groups and institutions
--licensing Also update user licence allocations
--really-do-this Actually try to make the changes.
......@@ -50,4 +52,5 @@ def main():
sync.sync(configuration,
read_only=not opts['--really-do-this'],
group_settings=opts['--group-settings'],
just_users=opts['--just-users'])
just_users=opts['--just-users'],
licensing=opts['--licensing'])
......@@ -304,7 +304,7 @@ class Comparator(ConfigurationStateConsumer):
'gids_to_update_group_settings': gids_to_update_group_settings,
})
def enforce_limits(self, just_users):
def enforce_limits(self, just_users, licensing):
# --------------------------------------------------------------------------------------------
# Enforce limits on how much data to change in Google.
# --------------------------------------------------------------------------------------------
......@@ -319,10 +319,10 @@ class Comparator(ConfigurationStateConsumer):
)
LOG.info('Configuration will modify %.2f%% of users', user_change_percentage)
if self.licensing_config.product_id is not None:
if licensing and self.licensing_config.product_id is not None:
# Calculate percentage change in licence assignments.
licence_change_percentage = 100. * (
len(self.state.licences_to_add) + len(self.state.licences_to_remove)
len(self.state.licences_to_add | self.state.licences_to_remove)
/
max(1, len(self.state.google_licensed_uids))
)
......@@ -354,7 +354,7 @@ class Comparator(ConfigurationStateConsumer):
)
raise RuntimeError('Aborting due to large user change percentage')
if self.licensing_config.product_id is not None:
if licensing and self.licensing_config.product_id is not None:
if (
self.limits_config.abort_licence_change_percentage is not None and
licence_change_percentage > self.limits_config.abort_licence_change_percentage
......@@ -434,7 +434,7 @@ class Comparator(ConfigurationStateConsumer):
LOG.info('Capped number of users to update to %s', len(self.state.uids_to_update))
# Licences
if self.licensing_config.product_id is not None:
if licensing and self.licensing_config.product_id is not None:
if (self.limits_config.max_add_licence is not None and
len(self.state.licences_to_add) > self.limits_config.max_add_licence):
self.state.licences_to_add = _limit(
......
......@@ -14,7 +14,8 @@ from .update import GAPIUpdater
LOG = logging.getLogger(__name__)
def sync(configuration, *, read_only=True, group_settings=False, just_users=False):
def sync(configuration, *, read_only=True, group_settings=False, just_users=False,
licensing=False):
"""Perform sync given configuration dictionary."""
if read_only:
LOG.info('Performing synchronisation in READ ONLY mode.')
......@@ -38,6 +39,7 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals
gapi = GAPIRetriever(configuration, state)
gapi.connect(read_only)
gapi.retrieve_users()
if licensing:
gapi.retrieve_licenses()
if not just_users:
gapi.retrieve_groups()
......@@ -48,6 +50,7 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals
# Compare users and optionally groups between Lookup and Google
comparator = Comparator(configuration, state)
comparator.compare_users()
if licensing:
comparator.compare_licensing()
if not just_users:
comparator.compare_groups()
......@@ -55,11 +58,12 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals
if group_settings:
comparator.compare_groups_settings()
# Enforce creation/update limits
comparator.enforce_limits(just_users)
comparator.enforce_limits(just_users, licensing)
# Update Google with necessary updates found doing comparison
updater = GAPIUpdater(configuration, state, read_only)
updater.update_users()
if licensing:
updater.update_licensing()
if not just_users:
updater.update_groups()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment