Esempio n. 1
0
    def set_state(self, state):
        """
        Activate and put this conversation into the given state.

        The relation name will be interpolated in the state name, and it is
        recommended that it be included to avoid conflicts with states from
        other relations.  For example::

            conversation.set_state('{relation_name}.state')

        If called from a converation handling the relation "foo", this will
        activate the "foo.state" state, and will add this conversation to
        that state.

        Note: This uses :mod:`charmhelpers.core.unitdata` and requires that
        :meth:`~charmhelpers.core.unitdata.Storage.flush` be called.
        """
        state = state.format(relation_name=self.relation_name)
        value = get_state(state, {
            'relation': self.relation_name,
            'conversations': [],
        })
        if self.key not in value['conversations']:
            value['conversations'].append(self.key)
        set_state(state, value)
Esempio n. 2
0
    def remove_state(self, state):
        """
        Remove this conversation from the given state, and potentially
        deactivate the state if no more conversations are in it.

        The relation name will be interpolated in the state name, and it is
        recommended that it be included to avoid conflicts with states from
        other relations.  For example::

            conversation.remove_state('{relation_name}.state')

        If called from a converation handling the relation "foo", this will
        remove the conversation from the "foo.state" state, and, if no more
        conversations are in this the state, will deactivate it.
        """
        state = state.format(relation_name=self.relation_name)
        value = get_state(state)
        if not value:
            return
        if self.key in value['conversations']:
            value['conversations'].remove(self.key)
        if value['conversations']:
            set_state(state, value)
        else:
            remove_state(state)
Esempio n. 3
0
    def set_state(self, state):
        """
        Activate and put this conversation into the given state.

        The relation name will be interpolated in the state name, and it is
        recommended that it be included to avoid conflicts with states from
        other relations.  For example::

            conversation.set_state('{relation_name}.state')

        If called from a converation handling the relation "foo", this will
        activate the "foo.state" state, and will add this conversation to
        that state.

        Note: This uses :mod:`charmhelpers.core.unitdata` and requires that
        :meth:`~charmhelpers.core.unitdata.Storage.flush` be called.
        """
        state = state.format(relation_name=self.relation_name)
        value = get_state(state, {
            'relation': self.relation_name,
            'conversations': [],
        })
        if self.key not in value['conversations']:
            value['conversations'].append(self.key)
        set_state(state, value)
Esempio n. 4
0
    def remove_state(self, state):
        """
        Remove this conversation from the given state, and potentially
        deactivate the state if no more conversations are in it.

        The relation name will be interpolated in the state name, and it is
        recommended that it be included to avoid conflicts with states from
        other relations.  For example::

            conversation.remove_state('{relation_name}.state')

        If called from a converation handling the relation "foo", this will
        remove the conversation from the "foo.state" state, and, if no more
        conversations are in this the state, will deactivate it.
        """
        state = state.format(relation_name=self.relation_name)
        value = get_state(state)
        if not value:
            return
        if self.key in value['conversations']:
            value['conversations'].remove(self.key)
        if value['conversations']:
            set_state(state, value)
        else:
            remove_state(state)
Esempio n. 5
0
def configure_admin():
    remove_state("jenkins.configured.admin")
    api = Api()

    status_set("maintenance", "Configuring Jenkins public url")
    configuration = Configuration()
    needs_restart = configuration.set_url()
    if needs_restart:
        status_set("maintenance", "Restarting Jenkins")
        service_restart('jenkins')
        api.wait()

    status_set("maintenance", "Configuring proxy settings")
    configuration.configure_proxy()
    service_restart('jenkins')
    api.wait()

    status_set("maintenance", "Configuring admin user")
    users = Users()
    users.configure_admin()

    api.reload()
    api.wait()  # Wait for the service to be fully up
    # Inform any extension that the username/password changed
    if get_state("extension.connected"):
        extension_relation = (RelationBase.from_state("extension.connected"))
        extension_relation.joined()

    set_state("jenkins.configured.admin")
def setup_ports():

    cfg = config()
    status_set('maintenance', 'configuring ssh connection')
    if not cfg['ssh-hostname'] or not cfg['ssh-private-key']:
        status_set('blocked', 'need sshproxy configured')
        log('sshproxy not yet fully configured', 'DEBUG')
        return

    #hostname could contain a dual ip, one for floating and non-floating.
    #appears that the floating is always the first entry.
    host = cfg['ssh-hostname'].split(';')[0]

    sess_pci = sshdriver.ElementDriverSSH(
        host, private_key=cfg['ssh-private-key'].replace('\\n', '\n'))
    sess_port = sshdriver.ElementDriverSSH(
        host, private_key=cfg['ssh-private-key'].replace('\\n', '\n'))

    do_commit = False
    if get_state('config.changed.fastpath-service-ports', False) is None:
        for port in cfg['fastpath-service-ports'].split(','):
            do_commit = True
            configure_port(sess_pci, sess_port, port, 'service')

    if get_state('config.changed.fastpath-subscriber-ports', False) is None:
        for port in cfg['fastpath-subscriber-ports'].split(','):
            do_commit = True
            configure_port(sess_pci, sess_port, port, 'subscriber')

    if get_state('config.changed.fastpath-internet-ports', False) is None:
        for port in cfg['fastpath-internet-ports'].split(','):
            do_commit = True
            configure_port(sess_pci, sess_port, port, 'internet')

    if do_commit:
        status_set('maintenance', 'configuring ports')
        try:
            sess_pci.configuration_commit()
            sess_port.configuration_commit()
        except:
            status_set('blocked', 'failed to commit')
            return

    status_set('active', 'ready')
    set_state('sandvine-pts-proxy.configured')
Esempio n. 7
0
 def is_state(self, state):
     """
     Test if this conversation is in the given state.
     """
     state = state.format(relation_name=self.relation_name)
     value = get_state(state)
     if not value:
         return False
     return self.key in value['conversations']
Esempio n. 8
0
 def is_state(self, state):
     """
     Test if this conversation is in the given state.
     """
     state = state.format(relation_name=self.relation_name)
     value = get_state(state)
     if not value:
         return False
     return self.key in value['conversations']
Esempio n. 9
0
 def from_state(cls, state):
     """
     Find relation implementation in the current charm, based on the
     name of an active state.
     """
     value = get_state(state)
     if value is None:
         return None
     relation_name = value['relation']
     conversations = Conversation.load(value['conversations'])
     return cls.from_name(relation_name, conversations)
Esempio n. 10
0
 def from_state(cls, state):
     """
     Find relation implementation in the current charm, based on the
     name of an active state.
     """
     value = get_state(state)
     if value is None:
         return None
     relation_name = value['relation']
     conversations = Conversation.load(value['conversations'])
     return cls.from_name(relation_name, conversations)
Esempio n. 11
0
def configure_plugins():
    if get_state("extension.connected"):
        # We've been driven by an extension, let it take control over
        # plugin.
        log("External relation detected - skip configuring plugins")
        return
    status_set("maintenance", "Configuring plugins")
    remove_state("jenkins.configured.plugins")
    plugins = Plugins()
    plugins.install(config("plugins"))
    api = Api()
    api.wait()  # Wait for the service to be fully up
    set_state("jenkins.configured.plugins")
Esempio n. 12
0
def configure_plugins():
    if get_state("extension.connected"):
        # We've been driven by an extension, let it take control over
        # plugin.
        log("External relation detected - skip configuring plugins")
        return
    status_set("maintenance", "Configuring plugins")
    remove_state("jenkins.configured.plugins")
    plugins = Plugins()
    plugins.install(config("plugins"))
    api = Api()
    api.wait()  # Wait for the service to be fully up
    set_state("jenkins.configured.plugins")
Esempio n. 13
0
def configure_admin():
    remove_state("jenkins.configured.admin")
    status_set("maintenance", "Configuring admin user")
    users = Users()
    users.configure_admin()
    api = Api()
    api.reload()
    api.wait()  # Wait for the service to be fully up
    # Inform any extension that the username/password changed
    if get_state("extension.connected"):
        extension_relation = (RelationBase.from_state("extension.connected"))
        extension_relation.joined()

    set_state("jenkins.configured.admin")
Esempio n. 14
0
def set_jenkins_dir(storage_dir=paths.HOME):
    status_set("maintenance", "Configuring Jenkins storage")
    jenkins_installed = get_state("apt.installed.jenkins")
    if jenkins_installed:
        service_stop('jenkins')

    if storage_dir is paths.HOME:
        log("Setting Jenkins to use local storage")
        Storage().unlink_home()
    else:
        log("Setting Jenkins to use storage at {}".format(storage_dir))
        Storage().link_home(storage_dir)

    if jenkins_installed:
        status_set("maintenance", "Restarting Jenkins")
        service_start('jenkins')
        Service().check_ready()

    if get_state('jenkins.bootstrapped'):
        # JENKINS_HOME just changed trigger bootstrap again
        remove_state("jenkins.bootstrapped")
        bootstrap_jenkins()
    else:
        status_set('active', 'Ready')