Пример #1
0
def validate_config():
    try:
        """
        If the ssh credentials are available, we'll act as a proxy charm.
        Otherwise, we execute against the unit we're deployed on to.
        """
        if all(k in cfg for k in ['pass', 'vpe-router', 'user']):
            routerip = cfg['vpe-router']
            user = cfg['user']
            passwd = cfg['pass']

            if routerip and user and passwd:
                # Assumption: this will be a root user
                out, err = router.ssh(['whoami'], routerip,
                                      user, passwd)
                if out.strip() != user:
                    raise Exception('invalid credentials')

                # Set the router's hostname
                try:
                    if user == 'root' and 'hostname' in cfg:
                        hostname = cfg['hostname']
                        out, err = router.ssh(['hostname', hostname],
                                              routerip,
                                              user, passwd)
                        out, err = router.ssh(['sed',
                                              '-i',
                                               '"s/hostname.*$/hostname %s/"'
                                               % hostname,
                                               '/usr/admin/global/hostname.sh'
                                               ],
                                              routerip,
                                              user, passwd)

                except subprocess.CalledProcessError as e:
                    log('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
                    raise

        set_state('vpe.configured')
        status_set('active', 'ready!')

    except Exception as e:
        log(repr(e))
        remove_state('vpe.configured')
        status_set('blocked', 'validation failed: %s' % e)
Пример #2
0
def validate_config():
    try:
        """
        If the ssh credentials are available, we'll act as a proxy charm.
        Otherwise, we execute against the unit we're deployed on to.
        """
        if all(k in cfg for k in ['pass', 'vpe-router', 'user']):
            routerip = cfg['vpe-router']
            user = cfg['user']
            passwd = cfg['pass']

            if routerip and user and passwd:
                # Assumption: this will be a root user
                out, err = router.ssh(['whoami'], routerip, user, passwd)
                if out.strip() != user:
                    raise Exception('invalid credentials')

                # Set the router's hostname
                try:
                    if user == 'root' and 'hostname' in cfg:
                        hostname = cfg['hostname']
                        out, err = router.ssh(['hostname', hostname], routerip,
                                              user, passwd)
                        out, err = router.ssh([
                            'sed', '-i',
                            '"s/hostname.*$/hostname %s/"' % hostname,
                            '/usr/admin/global/hostname.sh'
                        ], routerip, user, passwd)

                except subprocess.CalledProcessError as e:
                    log('Command failed: %s (%s)' %
                        (' '.join(e.cmd), str(e.output)))
                    raise

        set_state('vpe.configured')
        status_set('active', 'ready!')

    except Exception as e:
        log(repr(e))
        remove_state('vpe.configured')
        status_set('blocked', 'validation failed: %s' % e)
Пример #3
0
def validate_config():
    try:
        if not all(k in cfg for k in ['pass', 'vpe-router', 'user']):
            raise Exception('vpe-router, user, and pass need to be set')

        out, err = router.ssh(['whoami'], cfg.get('vpe-router'),
                              cfg.get('user'), cfg.get('pass'))
        if out.strip() != cfg.get('user'):
            raise Exception('invalid credentials')

        set_state('vpe.configured')
        status_set('active', 'ready!')

    except Exception as e:
        remove_state('vpe.configured')
        status_set('blocked', 'validation failed: %s' % e)