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 ...@@ -4,7 +4,7 @@ Synchronise users to GSuite
Usage: Usage:
gsuitesync (-h | --help) gsuitesync (-h | --help)
gsuitesync [--configuration=FILE] [--quiet] [--group-settings] [--just-users] gsuitesync [--configuration=FILE] [--quiet] [--group-settings] [--just-users]
[--really-do-this] [--licensing] [--really-do-this]
Options: Options:
-h, --help Show a brief usage summary. -h, --help Show a brief usage summary.
...@@ -15,7 +15,9 @@ Options: ...@@ -15,7 +15,9 @@ Options:
--group-settings Also update group settings on all groups --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. --really-do-this Actually try to make the changes.
...@@ -50,4 +52,5 @@ def main(): ...@@ -50,4 +52,5 @@ def main():
sync.sync(configuration, sync.sync(configuration,
read_only=not opts['--really-do-this'], read_only=not opts['--really-do-this'],
group_settings=opts['--group-settings'], 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): ...@@ -304,7 +304,7 @@ class Comparator(ConfigurationStateConsumer):
'gids_to_update_group_settings': gids_to_update_group_settings, '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. # Enforce limits on how much data to change in Google.
# -------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------
...@@ -319,10 +319,10 @@ class Comparator(ConfigurationStateConsumer): ...@@ -319,10 +319,10 @@ class Comparator(ConfigurationStateConsumer):
) )
LOG.info('Configuration will modify %.2f%% of users', user_change_percentage) 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. # Calculate percentage change in licence assignments.
licence_change_percentage = 100. * ( 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)) max(1, len(self.state.google_licensed_uids))
) )
...@@ -354,7 +354,7 @@ class Comparator(ConfigurationStateConsumer): ...@@ -354,7 +354,7 @@ class Comparator(ConfigurationStateConsumer):
) )
raise RuntimeError('Aborting due to large user change percentage') 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 ( if (
self.limits_config.abort_licence_change_percentage is not None and self.limits_config.abort_licence_change_percentage is not None and
licence_change_percentage > self.limits_config.abort_licence_change_percentage licence_change_percentage > self.limits_config.abort_licence_change_percentage
...@@ -434,7 +434,7 @@ class Comparator(ConfigurationStateConsumer): ...@@ -434,7 +434,7 @@ class Comparator(ConfigurationStateConsumer):
LOG.info('Capped number of users to update to %s', len(self.state.uids_to_update)) LOG.info('Capped number of users to update to %s', len(self.state.uids_to_update))
# Licences # 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 if (self.limits_config.max_add_licence is not None and
len(self.state.licences_to_add) > self.limits_config.max_add_licence): len(self.state.licences_to_add) > self.limits_config.max_add_licence):
self.state.licences_to_add = _limit( self.state.licences_to_add = _limit(
......
...@@ -14,7 +14,8 @@ from .update import GAPIUpdater ...@@ -14,7 +14,8 @@ from .update import GAPIUpdater
LOG = logging.getLogger(__name__) 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.""" """Perform sync given configuration dictionary."""
if read_only: if read_only:
LOG.info('Performing synchronisation in READ ONLY mode.') LOG.info('Performing synchronisation in READ ONLY mode.')
...@@ -38,7 +39,8 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals ...@@ -38,7 +39,8 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals
gapi = GAPIRetriever(configuration, state) gapi = GAPIRetriever(configuration, state)
gapi.connect(read_only) gapi.connect(read_only)
gapi.retrieve_users() gapi.retrieve_users()
gapi.retrieve_licenses() if licensing:
gapi.retrieve_licenses()
if not just_users: if not just_users:
gapi.retrieve_groups() gapi.retrieve_groups()
# Optionally get group settings too # Optionally get group settings too
...@@ -48,18 +50,20 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals ...@@ -48,18 +50,20 @@ def sync(configuration, *, read_only=True, group_settings=False, just_users=Fals
# Compare users and optionally groups between Lookup and Google # Compare users and optionally groups between Lookup and Google
comparator = Comparator(configuration, state) comparator = Comparator(configuration, state)
comparator.compare_users() comparator.compare_users()
comparator.compare_licensing() if licensing:
comparator.compare_licensing()
if not just_users: if not just_users:
comparator.compare_groups() comparator.compare_groups()
# Optionally compare existing group settings too # Optionally compare existing group settings too
if group_settings: if group_settings:
comparator.compare_groups_settings() comparator.compare_groups_settings()
# Enforce creation/update limits # Enforce creation/update limits
comparator.enforce_limits(just_users) comparator.enforce_limits(just_users, licensing)
# Update Google with necessary updates found doing comparison # Update Google with necessary updates found doing comparison
updater = GAPIUpdater(configuration, state, read_only) updater = GAPIUpdater(configuration, state, read_only)
updater.update_users() updater.update_users()
updater.update_licensing() if licensing:
updater.update_licensing()
if not just_users: if not just_users:
updater.update_groups() 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