Beispiel #1
0
def _use_default_config_if_needed(arguments):
    '''Set default values from config in case the user didn't put them.
    In our case only pool '''
    config = config_get(silent=True)
    if not arguments['--pool']:
        arguments['--pool'] = config['PoolName']
    return arguments
Beispiel #2
0
def run_fs_detach(arguments, sdk):
    config = config_get(silent=True)
    from smb.cli.fs import fs_detach
    lib.approve_danger_op(
        "Detaching Filesystem {} from Cluster {}".format(
            arguments['--name'], config['Cluster']), arguments)
    fs_detach(arguments['--name'], sdk)
Beispiel #3
0
def run_config_set(arguments):
    from smb.cli.config import config_set, config_get
    config = config_get(silent=True)
    log(logger, "Current Config:", raw=True)
    if config is None:
        return
    key, value = arguments.get('<key=value>', "").split("=")
    config_case_sensitive = {item.lower(): item for item in config.keys()}
    if key.lower() not in config_case_sensitive.keys():
        log(logger,
            "{} is not valid for your config".format(key),
            color="red",
            raw=True)
        return
    config_set(config_case_sensitive[key.lower()], value)
    log(logger, "New Config:", level=INFO)
    config_get(skip_validation=True)
Beispiel #4
0
def run_fs_attach(arguments, sdk):
    from smb.cli.fs import fs_attach
    config = config_get(silent=True)
    lib.approve_danger_op(
        "Adding volume {} to Cluster {}".format(arguments['--name'],
                                                config['Cluster']), arguments)
    log(logger, "calling {}")
    fs_attach(arguments['--name'], sdk, arguments['--force'])
Beispiel #5
0
def am_I_master():
    from platform import node
    config = config_get(silent=True)
    cmd = execute_assert_success(['powershell', '-c', 'Get-ClusterGroup', '-name', config['FSRoleName'], '|', 'Select-Object',
                            '-ExpandProperty', 'OwnerNode', '|', 'Select-Object', '-ExpandProperty', 'name'])
    if cmd.get_stdout().strip() == node():
        return True
    else:
        log_n_raise(logger, "The Node you are running on is NOT the Active Cluster Node")
Beispiel #6
0
def arguments_to_functions(arguments):
    log(logger, "Arguments received from user:{}".format(arguments))
    try:
        if arguments['config']:
            if arguments['get']:
                run_config_get()
                return
            if arguments['set']:
                run_config_set(arguments)
                return
        try:
            config = config_get(silent=True)
        except SmbCliExited:
            return
        sdk = lib.prechecks()
        if arguments['fs']:
            arguments = _use_default_config_if_needed(arguments)
            if arguments['create']:
                run_fs_create(arguments, sdk)
            if arguments['delete']:
                run_fs_delete(arguments, sdk)
            if arguments['attach']:
                run_fs_attach(arguments, sdk)
            if arguments['detach']:
                run_fs_detach(arguments, sdk)
            if arguments['query']:
                run_fs_query(arguments, sdk)
        if arguments['share']:
            if arguments['create']:
                run_share_create(arguments, sdk)
            if arguments['query']:
                run_share_query(arguments, sdk)
            if arguments['resize']:
                run_share_resize(arguments, sdk)
            if arguments['delete']:
                run_share_delete(arguments)
    except KeyboardInterrupt:
        log(logger, "Keyboard break received, exiting")
        return
    except SmbCliExited:
        return 1
    except Exception as e:
        log(logger, traceback.format_exc())
        message = '''{} \n(This is Unusual)
Please collect the Logs from "{}" and open a ticket on github'''
        log(logger,
            message.format(e, logger.handlers[0].baseFilename),
            level=ERROR,
            color="red")
        return 1
Beispiel #7
0
 def authenticate(self, key, credentials):
     from infinisdk.core.exceptions import APICommandFailed
     if credentials is None:
         return False
     config = config_get(silent=True)
     validate_key_val('IboxAddress', config['IboxAddress'])
     try:
         ibox = infinisdk.InfiniBox(config['IboxAddress'],
                                    auth=(credentials.get_username(),
                                          credentials.get_password()))
         ibox.login()
         return True
     except APICommandFailed:
         return False
Beispiel #8
0
def run_config_get():
    config_get()
Beispiel #9
0
import sys
from capacity import *
from os import path, mkdir
from smb.cli import lib, ps_cmd
from infi.execute import execute
from smb.cli.config import config_get
from smb.cli.smb_log import get_logger, log, log_n_raise, SmbCliExited
from logging import DEBUG, INFO, WARNING, ERROR
from smb.cli.__version__ import __version__

logger = get_logger()
config = config_get(silent=True)

MAX_ATTACHED_VOLUMES = 100  # maximum amount of simultaneously attached volumes
MAX_VOL_NAME_LENGTH = 24


class Fs(object):
    def __init__(self, infinibox_vol, sdk, winid=None):
        self.ibox = sdk.get_ibox()
        self.cluster = sdk.get_cluster()
        self.ibox_vol = infinibox_vol
        self.name = infinibox_vol.get_name()
        self.mountpoint = _get_default_mountpoint(self.name)
        self.fs_sizes = lib.get_path_free_size(self.mountpoint)
        self.winid = ps_cmd._run_get_winid_by_serial(
            infinibox_vol.get_serial()) if winid is None else winid

    def get_name(self):
        return self.name
Beispiel #10
0
 def __init__(self):
     self.config = config_get(silent=True)
     validate_key_val('IboxAddress', self.config['IboxAddress'])
     self.ibox = self.ibox_login()
Beispiel #11
0
def is_cluster_online():
    config = config_get(silent=True)
    cmd = execute_assert_success(['powershell', '-c', 'Get-ClusterGroup', '-name', config['FSRoleName'], '|', 'Select-Object',
                            '-ExpandProperty', 'state'])
    if cmd.get_stdout().strip() != 'Online':
        log_n_raise(logger, "Cluster group {} NOT in Online state !! state is: {}".format(config['FSRoleName'], cmd.get_stdout().strip()))