def clear_waiting_unit_series_upgrade(): """Clear the unit from a waiting upgrade state in the local kv() store. """ log("Setting waiting-unit-series-upgrade=false in local kv", DEBUG) with unitdata.HookData()() as t: kv = t[0] kv.set('waiting-unit-series-upgrade', False)
def set_unit_paused(): """Set the unit to a paused state in the local kv() store. This does NOT actually pause the unit """ with unitdata.HookData()() as t: kv = t[0] kv.set('unit-paused', True)
def set_waiting_unit_series_upgrade(): """Set the unit to a waiting upgrade state in the local kv() store. """ log("Setting waiting-unit-series-upgrade=true in local kv", DEBUG) with unitdata.HookData()() as t: kv = t[0] kv.set('waiting-unit-series-upgrade', True)
def clear_unit_paused(): """Clear the unit from a paused state in the local kv() store This does NOT actually restart any services - it only clears the local state. """ with unitdata.HookData()() as t: kv = t[0] kv.set('unit-paused', False)
def set_db_value(option, value): """ Determine if config value changed since last call to this function. """ hook_data = unitdata.HookData() with hook_data(): db = unitdata.kv() db.set(option, value)
def get_deferred_hooks(): """Get a list of deferred hooks. :returns: List of hook names. :rtype: List[str] """ with unitdata.HookData()() as t: kv = t[0] return kv.get('deferred-hooks', [])
def __init__(self): self.db = unitdata.kv() self.public_address = unit_get('public-address') self.private_address = unit_get('private-address') self.hook_data = unitdata.HookData() self.unit_name = getenv('JUJU_UNIT_NAME').replace('/', '') self.port = config('port') self.management_port = config('management_port') self.init_cluster_cache()
def is_waiting_unit_series_upgrade_set(): """Return the state of the kv().get('waiting-unit-series-upgrade'). To help with units that don't have HookData() (testing) if it excepts, return False """ with unitdata.HookData()() as t: kv = t[0] if not kv.get('waiting-unit-series-upgrade'): return False return kv.get('waiting-unit-series-upgrade')
def has_db_value(option): """ Determine if config value changed since last call to this function. """ hook_data = unitdata.HookData() with hook_data(): db = unitdata.kv() saved = db.get(option) if saved is not None: return True return False
def clear_deferred_hook(hookname): """Clear a specific deferred hooks. :param hookname: Name of hook to remove. :type hookname: str """ with unitdata.HookData()() as t: kv = t[0] deferred_hooks = kv.get('deferred-hooks', []) if hookname in deferred_hooks: deferred_hooks.remove(hookname) kv.set('deferred-hooks', deferred_hooks)
def set_deferred_hook(hookname): """Record that a hook has been deferred. :param hookname: Name of hook that was deferred. :type hookname: str """ with unitdata.HookData()() as t: kv = t[0] deferred_hooks = kv.get('deferred-hooks', []) if hookname not in deferred_hooks: deferred_hooks.append(hookname) kv.set('deferred-hooks', sorted(list(set(deferred_hooks))))
def config_value_changed(option): """ Determine if config value changed since last call to this function. """ hook_data = unitdata.HookData() with hook_data(): db = unitdata.kv() current = config(option) saved = db.get(option) db.set(option, current) if saved is None: return False return current != saved
def is_unit_paused_set(): """Return the state of the kv().get('unit-paused'). This does NOT verify that the unit really is paused. To help with units that don't have HookData() (testing) if it excepts, return False """ try: with unitdata.HookData()() as t: kv = t[0] # transform something truth-y into a Boolean. return not(not(kv.get('unit-paused'))) except: return False
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from charms.reactive import when, when_not, set_state from charmhelpers.core.hookenv import status_set, log from charmhelpers.core import hookenv, unitdata import jujuresources from charmhelpers.core.host import adduser, chownr, mkdir import urllib.request hook_data = unitdata.HookData() db = unitdata.kv() hooks = hookenv.Hooks() resources = {'sparkler-0.1': 'sparkler-0.1'} @when_not('sparkler.installed') def install_sparkler(): mkdir('/opt/sparkler/') urllib.request.urlretrieve( "https://www.dropbox.com/s/1wewnm080a3240u/sparkler-app-0.1-SNAPSHOT.jar?dl=0", "/opt/sparkler/sparkler.jar") #jujuresources.install('sparkler',
def clear_deferred_hooks(): """Clear any deferred hooks.""" with unitdata.HookData()() as t: kv = t[0] kv.set('deferred-hooks', [])