Ejemplo n.º 1
0
def add_res_node(resource, parent, idata, rid=None, discard_disabled=False):
    if discard_disabled and resource.get("disable", False):
        return
    ers = get_ers(idata)
    rid = resource["rid"]
    node_res = parent.add_node()
    node_res.add_column(rid)
    node_res.add_column(fmt_flags(resource, idata))
    node_res.add_column(resource["status"], STATUS_COLOR[resource["status"]])
    col = node_res.add_column(resource["label"])
    if rid in ers and resource["status"] in ("up", "stdby up", "n/a"):
        edata = Storage(idata["encap"].get(rid))
        encap_notice = instance_notice(
            overall=edata.overall,
            frozen=edata.frozen,
            constraints=edata.get("constraints", True),
            provisioned=edata.provisioned,
            monitor={},
        )
        col.add_text(encap_notice, color.LIGHTBLUE)
    for line in resource.get("log", []):
        if line.startswith("warn:"):
            scolor = STATUS_COLOR["warn"]
        elif line.startswith("error:"):
            scolor = STATUS_COLOR["err"]
        else:
            scolor = None
        col.add_text(line, scolor)

    if rid not in ers or resource["status"] not in ("up", "stdby up", "n/a"):
        return

    add_subsets(ers[rid], node_res, idata, discard_disabled=discard_disabled)
Ejemplo n.º 2
0
 def test_storage():
     """
     Storage
     """
     store = Storage({"foo": "bar"})
     assert store.foo == "bar"
     assert store.bar is None
     assert store["bar"] is None
     del store.foo
     assert store.foo is None
     store.foo = "bar"
     assert store.foo == "bar"
Ejemplo n.º 3
0
 def socket_parms_ux_raw(self, server):
     data = Storage()
     data.scheme = "raw"
     data.af = socket.AF_UNIX
     data.to = Env.paths.lsnruxsock
     data.to_s = Env.paths.lsnruxsock
     data.encrypted = False
     data.server = server
     data.context = None
     return data
Ejemplo n.º 4
0
 def socket_parms_inet_raw(self, server):
     data = Storage()
     data.server = server
     addr, port = self.get_listener_info(server)
     data.scheme = "raw"
     data.af = socket.AF_INET
     data.to = (addr, port)
     data.to_s = "%s:%d" % (addr, port)
     data.encrypted = True
     data.tls = False
     return data
Ejemplo n.º 5
0
 def reset_stats(self):
     self.stats = Storage({
         "since": time.time(),
         "beats": 0,
         "bytes": 0,
         "errors": 0,
     })
Ejemplo n.º 6
0
 def set_beating(self, nodename="*"):
     now = time.time()
     if nodename not in self.peers:
         self.peers[nodename] = Storage({
             "last": 0,
             "beating": False,
             "success": True,
         })
     if now > self.peers[nodename].last + self.timeout:
         beating = False
     else:
         beating = True
     change = False
     if self.peers[nodename].beating != beating:
         change = True
         if beating:
             self.event("hb_beating", data={
                 "nodename": nodename,
                 "hb": {"name": self.name, "id": self.id},
             })
         else:
             self.event("hb_stale", data={
                 "nodename": nodename,
                 "hb": {"name": self.name, "id": self.id,
                        "timeout": self.timeout,
                        "last": self.peers[nodename].last},
             }, level="warning")
     self.peers[nodename].beating = beating
     if not beating and self.peers[nodename].last > 0:
         self.forget_peer_data(nodename, change)
Ejemplo n.º 7
0
 def socket_parms_from_context(self, server):
     if not has_ssl:
         raise ex.Error("tls1.2 capable ssl module is required but not available")
     data = Storage()
     context = get_context()
     addr = context["cluster"]["addr"]
     port = context["cluster"]["port"]
     data.context = context
     data.scheme = "h2"
     data.af = socket.AF_INET
     data.to = (addr, port)
     data.to_s = "%s:%d" % (addr, port)
     data.encrypted = False
     data.tls = True
     data.server = server
     return data
Ejemplo n.º 8
0
 def __init__(self,
              config_defaults=None,
              node=None,
              options=None,
              scheduler_actions=None,
              log=None,
              svc=None,
              configure_method=None):
     self.config_defaults = config_defaults
     self.configured = False
     self.configure_method = configure_method
     self.scheduler_actions = scheduler_actions or {}
     self.options = Storage(options or {})
     self.svc = svc
     self.node = node
     if svc:
         self.obj = svc
         self.log = svc.log
         if node is None:
             self.node = svc.node
     else:
         self.obj = node
         self.log = node.log
         if node is None:
             self.node = node
Ejemplo n.º 9
0
 def get_last(self, nodename="*"):
     if nodename in self.peers:
         return self.peers[nodename]
     return Storage({
         "last": 0,
         "beating": False,
         "success": True,
     })
Ejemplo n.º 10
0
 def __init__(self, options=None, node=None, path=None):
     if isinstance(options, dict):
         self.options = Storage(options)
     else:
         self.options = options
     self.node = node
     self.collector = node.collector
     self.path = path
Ejemplo n.º 11
0
 def os_release(self):
     os_release_f = os.path.join(os.sep, "etc", "os-release")
     data = Storage()
     if not os.path.exists(os_release_f):
         return data
     with open(os_release_f, "r") as filep:
         for line in filep.readlines():
             line = line.strip("\n")
             try:
                 var, val = line.split("=", 1)
             except:
                 continue
             data[var.lower()] = val.strip('"')
     return data
Ejemplo n.º 12
0
 def _func(self, action, options=None):
     if options is None:
         options = Storage()
     self.sched.configure(action=action)
     if action in self.sched.actions:
         self.sched.action_timestamps(action, options.rid)
     try:
         ret = func(self, action, options)
     except ex.AbortAction:
         # finer-grained locking can raise that to cancel the task
         return 0
     if ret == 0 and action in self.sched.actions:
         self.sched.action_timestamps(action, options.rid, success=True)
     return ret
Ejemplo n.º 13
0
 def set_last(self, nodename="*", success=True):
     if nodename not in self.peers:
         self.peers[nodename] = Storage({
             "last": 0,
             "beating": False,
             "success": True,
         })
     if success:
         self.peers[nodename].last = time.time()
         if not self.peers[nodename].beating:
             self.event("hb_beating", data={
                 "nodename": nodename,
                 "hb": {"name": self.name, "id": self.id},
             })
         self.peers[nodename].beating = True
     self.peers[nodename].success = success
Ejemplo n.º 14
0
 def status(self, **kwargs):
     data = shared.OsvcThread.status(self, **kwargs)
     running = data.get("state") == "running"
     data["peers"] = {}
     for nodename in self.hb_nodes:
         if nodename == Env.nodename:
             data["peers"][nodename] = {}
             continue
         if "*" in self.peers:
             _data = self.peers["*"]
         else:
             _data = self.peers.get(nodename, Storage({
                 "last": 0,
                 "beating": False,
                 "success": True,
             }))
         data["peers"][nodename] = {
             "last": _data.last,
             "beating": _data.beating if running else False,
         }
     return data
Ejemplo n.º 15
0
def pid_to_ids(pid):
    with open("/proc/%d/environ" % pid) as fp:
        buff = fp.read()
    data = Storage()
    for line in buff.split('\0'):
        line = line.replace("\n", "")
        try:
            key, val = line.split("=", 1)
        except ValueError:
            continue
        if key == "OPENSVC_SVC_ID":
            data["svc_id"] = val
        elif key == "OPENSVC_SVCNAME":
            data["svcname"] = val
        elif key == "OPENSVC_SVCPATH":
            data["path"] = val
        elif key == "OPENSVC_RID":
            data["rid"] = val
        elif key == "OPENSVC_CHK_INSTANCE":
            data["instance"] = val
    return data
Ejemplo n.º 16
0
def add_instance(node, nodename, path, mon_data):
    node_child = node.add_node()
    node_child.add_column(nodename, color.BOLD)
    node_child.add_column()
    try:
        data = mon_data["nodes"][nodename]["services"]["status"][path]
        avail = data.get("avail", "n/a")
        node_frozen = mon_data["nodes"][nodename].get("frozen")
    except (TypeError, KeyError) as exc:
        avail = "undef"
        node_frozen = False
        data = Storage()
    node_child.add_column(avail, STATUS_COLOR[avail])
    notice = instance_notice(overall=data.get("overall", "n/a"),
                             frozen=data.get("frozen"),
                             node_frozen=node_frozen,
                             constraints=data.get("constraints", True),
                             provisioned=data.get("provisioned"),
                             monitor=data.get("monitor"))
    node_child.add_column(notice, color.LIGHTBLUE)
Ejemplo n.º 17
0
 def cpuinfo(self):
     self.init()
     data = self.wmi.Win32_Processor()
     ret = Storage()
     ret.NumberOfCores = 0
     for p in data:
         try:
             ret.NumberOfCores += p.NumberOfCores,
         except Exception:
             ret.NumberOfCores += 1
         if ret.SocketDesignation is None:
             ret.SocketDesignation = p.SocketDesignation
         if ret.Name is None:
             ret.Name = p.Name
         if ret.MaxClockSpeed is None:
             ret.MaxClockSpeed = p.MaxClockSpeed
     return ret
Ejemplo n.º 18
0
 def prepare_options(self, options):
     """
     Prepare and return the options Storage() as expected by the Svc::action
     and Node::do_svcs_action methods.
     """
     opts = Storage()
     # preserve parm_svcs, as svcs will be expanded
     opts.parm_svcs = options.parm_svcs
     for key, val in options.__dict__.items():
         opts[key.replace("parm_", "")] = val
     try:
         namespace = options.namespace
     except AttributeError:
         namespace = None
     if namespace:
         opts.namespace = namespace
     elif "OSVC_NAMESPACE" in os.environ:
         opts.namespace = os.environ["OSVC_NAMESPACE"]
     if self.selector:
         opts.parm_svcs = self.selector
         opts.svcs = self.selector
     if opts.eval and not opts.format:
         opts.format = "json"
     return opts
Ejemplo n.º 19
0
    def parse_options(self, data):
        def options_path(options, required=True):
            for key in ("path", "svcpath", "svcname"):
                try:
                    return options[key]
                except KeyError:
                    pass
            if required:
                raise ex.HTTP(400, "required option path is not set")
            return None

        def get_option(data, opt):
            name = opt["name"]
            fmt = opt.get("format", "string")
            required = opt.get("required", False)
            if fmt != "object_path" and required and name not in data:
                raise ex.HTTP(400, "required option %s is not set" % name)
            value = data.get(name, opt.get("default"))
            if value is None:
                value = opt.get("default")
            try:
                value = getattr(utilities.converters, "convert_" + fmt)(value)
            except AttributeError:
                pass
            except Exception as exc:
                raise ex.HTTP(
                    400, "option %s format conversion to %s error: %s" %
                    (name, fmt, exc))
            if fmt == "object_path":
                value = options_path(data, required=required)
            return name, value

        options = Storage()
        request_options = data.get("options", {})
        for opt in self.prototype:
            name, value = get_option(request_options, opt)
            options[name] = value
        return options
Ejemplo n.º 20
0
 def do_check(self):
     data = []
     for pid in self.find_java():
         ids = pid_to_ids(pid)
         if ids.instance is not None:
             instance = ids.instance
         elif ids.rid is not None:
             instance = ids.rid
         else:
             # not handled
             continue
         path = ids.path if ids.path else ids.name if ids.name else ""
         jstat = get_executable(Storage(), pid)
         if not jstat:
             continue
         for stat in STATS:
             for key, val in get_stat_metrics(jstat, pid, stat).items():
                 data.append({
                     "instance": "%s.%s.%s" % (instance, stat, key),
                     "value": val,
                     "path": path,
                 })
     #print(json.dumps(data, indent=4))
     return data
Ejemplo n.º 21
0
OPT = Storage({
    "help": Option(
        "-h", "--help", action="store_true", dest="parm_help",
        help="show this help message and exit"),
    "array": Option(
        "-a", "--array", action="store", dest="array_name",
        help="The name of the array, as defined in the node or cluster configuration."),
    "name": Option(
        "--name", action="store", dest="name",
        help="The object name"),
    "size": Option(
        "--size", action="store", dest="size",
        help="The disk size, expressed as a size expression like 1g, 100mib, ..."),
    "tags": Option(
        "--tag", action="append", dest="tags",
        help="An object tag. Can be set multiple times."),
    "blocksize": Option(
        "--blocksize", type=int, action="store", dest="blocksize",
        help="The exported disk blocksize in B"),
    "alignment_offset": Option(
        "--alignment-offset", type=int, action="store", dest="alignment_offset",
        help="The alignment offset for Volumes of 512 LB size is between 0 and "
             "7. If omitted, the offset value is 0.  Volumes of logical block "
             "size 4096 must not be defined with an offset."),
    "small_io_alerts": Option(
        "--small-io-alerts", action="store", dest="small_io_alerts",
        choices=["enabled", "disabled"],
        help="Enable or disable small input/output Alerts"),
    "unaligned_io_alerts": Option(
        "--unaligned-io-alerts", action="store", dest="unaligned_io_alerts",
        choices=["enabled", "disabled"],
        help="Enable or disable unaligned input/output Alerts"),
    "vaai_tp_alerts": Option(
        "--vaai-tp-alerts", action="store", dest="vaai_tp_alerts",
        choices=["enabled", "disabled"],
        help="Enable or disable VAAI TP Alerts"),
    "access": Option(
        "--access", action="store", dest="access",
        choices=["no_access", "read_access", "write_access"],
        help="A Volume is created with write access rights."
             "Volumes can be modified after being created and"
             "have their access levels' changed."),
    "naa": Option(
        "--naa", action="store", dest="naa",
        help="The volume naa identifier"),
    "mappings": Option(
        "--mappings", action="append", dest="mappings",
        help="A <hba_id>:<tgt_id>,<tgt_id>,... mapping used in add map in replacement of --targetgroup and --initiatorgroup. Can be specified multiple times."),
    "initiators": Option(
        "--initiators", action="append", dest="initiators",
        help="An initiator id. Can be specified multiple times."),
    "initiator": Option(
            "--initiator", action="store", dest="initiator",
            help="An initiator id"),
    "targets": Option(
        "--targets", action="append", dest="targets",
        help="A target name to export the disk through. Can be set multiple times."),
    "target": Option(
        "--target", action="store", dest="target",
        help="A target name or id"),
    "targetgroup": Option(
        "--targetgroup", action="store", dest="targetgroup",
        help="A target group name or id"),
    "initiatorgroup": Option(
        "--initiatorgroup", action="store", dest="initiatorgroup",
        help="The initiator group id or name"),
    "volume": Option(
        "--volume", action="store", dest="volume",
        help="A volume name or id"),
    "lun": Option(
        "--lun", action="store", type=int, dest="lun",
        help="Unique LUN identification, exposing the Volume to"
             "the host"),
    "mapping": Option(
        "--mapping", action="store", type=int, dest="mapping",
        help="A lun mapping index"),
})
Ejemplo n.º 22
0
"""
The user management command actions and options
"""
import commands.mgr.parser as mp
from utilities.optparser import OptParser, Option
from utilities.storage import Storage
from core.objects.svc import ACTION_ASYNC

PROG = "om usr"

OPT = Storage()
OPT.update(mp.OPT)
OPT.update({
    "key":
    Option("--key",
           default=None,
           action="store",
           dest="key",
           help="The secret key name."),
    "value_from":
    Option(
        "--from",
        default=None,
        action="store",
        dest="value_from",
        help=
        "Read the secret value from a file or a directory. If set to '-' or '/dev/stdin', the value is read from stdin, and the --key is mandatory. If set to a file path, the key name is the file basename. If set to a directory, one key per file is added, and the keyname is the relative path, the --key value being used as the relative path prefix."
    ),
    "password":
    Option("--password",
           default=None,
Ejemplo n.º 23
0
OPT = Storage({
    "add": Option(
        "--add", default=None,
        action="store",
        help="A list member to add to the value pointed by :opt:`--param`. "
             "If :opt:`--index` is set, insert the new element at the "
             "specified position in the list."),
    "backlog": Option(
        "--backlog", default=None,
        action="store", dest="backlog",
        help="A size expression limiting the volume of data fetched "
             "from the log file tail. Default is 10k."),
    "color": Option(
        "--color", default="auto",
        action="store", dest="color",
        help="Colorize output. Possible values are:\n\n"
             "* auto: guess based on tty presence\n"
             "* always|yes: always colorize\n"
             "* never|no: never colorize"),
    "config": Option(
        "--config", default=None,
        action="store", dest="parm_config",
        help="The configuration to use as template when creating or "
             "installing a service. The value can be ``-`` or ``/dev/stdin`` "
             "to read the json-formatted configuration from stdin, or a file "
             "path, or uri pointing to a ini-formatted configuration, or a "
             "service selector expression (ATTENTION with cloning existing live "
             "services that include more than containers, volumes and backend "
             "ip addresses ... this could cause disruption on the cloned service)."),
    "cron": Option(
        "--cron", default=False,
        action="store_true", dest="cron",
        help="If set, the action is actually executed only if the scheduling"
             "constraints are satisfied."),
    "debug": Option(
        "--debug", default=False,
        action="store_true", dest="debug",
        help="Increase stream and file log verbosity up to the debug level."),
    "daemon": Option(
        "--daemon", default=False,
        action="store_true", dest="daemon",
        help="A flag inhibiting the command daemonization. Set by the "
             "daemonization routine."),
    "disable_rollback": Option(
        "--disable-rollback", default=False,
        action="store_true", dest="disable_rollback",
        help="If set, don't try to rollback resources activated before a "
             "start action interrupts on error."),
    "discard": Option(
        "--discard", default=False,
        action="store_true", dest="discard",
        help="Discard the stashed, invalid, configuration file."),
    "dry_run": Option(
        "--dry-run", default=False,
        action="store_true", dest="dry_run",
        help="Show the action execution plan."),
    "env": Option(
        "--env", default=[],
        action="append", dest="env",
        help="Export the uppercased variable in the os environment.\n\n"
             "With the create action only, set a env section parameter in "
             "the service configuration file. Multiple ``--env <key>=<val>`` "
             "can be specified. For all other actions."),
    "eval": Option(
        "--eval", default=False,
        action="store_true", dest="eval",
        help="If set with the :cmd:`get` action, the printed value of "
             ":opt:`--param` is evaluated, scoped and dereferenced. If set "
             "with the :cmd:`set` action, the current value is "
             "evaluated before mangling."),
    "filter": Option(
        "--filter", default="",
        action="store", dest="jsonpath_filter",
        help="A JSONPath expression to filter a JSON output."),
    "follow": Option(
        "--follow", default=False,
        action="store_true", dest="follow",
        help="Follow the logs as they come. Use crtl-c to interrupt."),
    "force": Option(
        "-f", "--force", default=False,
        action="store_true", dest="force",
        help="Force action, ignore sanity checks."),
    "format": Option(
        "--format", default=None,
        action="store", dest="format",
        help="Specify a data formatter. Possible values are json, flat_json, "
              "csv or table. csv and table formatters are available only for "
              "commands returning tabular data."),
    "help": Option(
        "-h", "--help", default=None,
        action="store_true", dest="parm_help",
        help="Show this help message and exit."),
    "hide_disabled": Option(
        "--hide-disabled", default=None,
        action="store_false", dest="show_disabled",
        help="Do not include the disabled resources. This option supersedes "
             "the :kw:`show_disabled` value in the service configuration."),
    "impersonate": Option(
        "--impersonate", default=None,
        action="store",
        help="Impersonate a peer node when evaluating keywords."),
    "index": Option(
        "--index", default=None,
        action="store", type="int",
        help="The position in the list pointed by --param where to add "
             "the new list element on a set action"),
    "interactive": Option(
        "-i", "--interactive", default=False,
        action="store_true", dest="interactive",
        help="Prompt the user for a choice instead of using defaults, "
             "or failing if no default is defined."),
    "interval": Option(
        "--interval", default=0, action="store",
        dest="interval", type="int",
        help="with --watch, set the refresh interval. defaults "
             "to 0, to refresh on event only."),
    "kw": Option(
        "--kw", action="append", dest="kw",
        help="An expression like ``[<section>.]<keyword>[@<scope>][[<index>]]<op><value>`` where\n\n"
             "* <section> can be:\n\n"
             "  * a resource id\n"
             "  * a resource driver group name (fs, ip, ...). For the set and unset actions only, set the keyword for all matching resources.\n"
             "* <op> can be:\n\n"
             "  * ``=``  set as new value\n"
             "  * ``-=`` remove value from the current list\n"
             "  * ``+=`` append value to the current list\n"
             "  * ``|=`` append value to the current list if not already included\n\n"
             "Multiple --kw can be set to apply multiple configuration change "
             "in a file with a single write.\n\n"
             "Examples:\n\n"
             "* app.start=false\n"
             "  Turn off app start for all app resources\n"
             "* app#1.start=true\n"
             "  Turn on app start for app#1\n"
             "* nodes+=node3\n"
             "  Append node3 to nodes\n"
             "* nodes[0]+=node3\n"
             "  Preprend node3 to nodes\n"),
    "leader": Option(
        "--leader", default=None,
        action="store_true", dest="leader",
        help="Switch the provision action behaviour to leader, ie provision shared resources that are not provisionned by default."),
    "local": Option(
        "--local", default=False,
        action="store_true", dest="local",
        help="Execute the service action on the local service "
             "instances only, ignoring cluster-wide considerations."),
    "master": Option(
        "--master", default=False,
        action="store_true", dest="master",
        help="Limit the action scope to the master service resources."),
    "namespace": Option(
        "--namespace",
        action="store", dest="namespace",
        help="The namespace to switch to for the action. Namespaces are cluster partitions. A default namespace can be set for the session setting the OSVC_NAMESPACE environment variable."),
    "node": Option(
        "--node", default="",
        action="store", dest="node",
        help="The node to send a request to. If not specified the local node is targeted."),
    "nolock": Option(
        "--nolock", default=False,
        action="store_true", dest="nolock",
        help="Don't acquire the action lock. Dangerous, but can be useful to set parameters from an action trigger."),
    "nopager": Option(
        "--no-pager", default=False,
        action="store_true", dest="nopager",
        help="Do not display the command result in a pager."),
    "parallel": Option(
        "-p", "--parallel", default=False,
        action="store_true", dest="parallel",
        help="Start actions on specified services in parallel. :kw:`max_parallel` "
             "in node.conf limits the number of parallel running subprocesses."),
    "param": Option(
        "--param", default=None,
        action="store", dest="param",
        help="An expression like ``[<section>.]<keyword>`` where\n\n"
             "* <section> can be:\n\n"
             "  * a resource id\n"
             "  * a resource driver group name (fs, ip, ...). For the set and unset actions only, set the keyword for all matching resources."),
    "provision": Option(
        "--provision", default=False,
        action="store_true", dest="provision",
        help="Provision the service resources after config file creation. "
             "Defaults to False."),
    "purge_collector": Option(
        "--purge-collector", default=False,
        action="store_true", dest="purge_collector",
        help="On service delete, also remove the service collector-side"),
    "recover": Option(
        "--recover", default=False,
        action="store_true", dest="recover",
        help="Recover the stashed erroneous configuration file "
             "in a :cmd:`edit config` command"),
    "refresh": Option(
        "-r", "--refresh", default=False,
        action="store_true", dest="refresh",
        help="Drop status caches and re-evaluate before printing."),
    "remove": Option(
        "--remove", default=None,
        action="store",
        help="A list member to drop from the value pointed by :kw:`--param`."),
    "resource": Option(
        "--resource", default=[],
        action="append",
        help="A resource definition in json dictionary format fed to create "
             "or update. The ``rtype`` key point the driver group name, and "
             "the ``type`` key the driver name (translated to type in the "
             "configuration file section)."),
    "restore": Option(
        "--restore", default=False,
        action="store_true", dest="restore",
        help="Keep the same service id as the template or config file referenced by the create action. The default behaviour is to generate a new id."),
    "rid": Option(
        "--rid", default=None,
        action="store", dest="parm_rid",
        help="A resource specifier expression like ``<spec>[,<spec>]``, where ``<spec>`` can be:\n\n"
             "* A resource id\n"
             "* A driver group name (app, fs, disk, ...)\n\n"
             "Examples:\n\n"
             "* ``app``\n"
             "  all app resources\n"
             "* ``container#1,ip#1``\n"
             "  only container#1 and ip#1\n"
        ),
    "sections": Option(
        "--sections",
        action="store", dest="sections",
        help="the comma-separated list of sections to display. "
             "if not set, all sections are displayed. sections "
             "names are: threads,arbitrators,nodes,services."),
    "service": Option(
        "-s", "--service", default=None,
        action="store", dest="parm_svcs",
        help="A service selector expression ``[!]<expr>[<sep>[!]<expr>]`` where:\n\n"
             "- ``!`` is the expression negation operator\n\n"
             "- ``<sep>`` can be:\n\n"
             "  - ``,`` OR expressions\n\n"
             "  - ``+`` AND expressions\n\n"
             "- ``<expr>`` can be:\n\n"
             "  - a shell glob on service names\n\n"
             "  - ``<param><op><value>`` where:\n\n"
             "    - ``<param>`` can be:\n\n"
             "      - ``<rid>:``\n\n"
             "      - ``<group>:``\n\n"
             "      - ``<rid>.<key>``\n\n"
             "      - ``<group>.<key>``\n\n"
             "      - ``<single value jsonpath expression on the $.monitor.services.<path> dictionary extended under the 'nodes' key by each instance 'status' and 'config' data>``\n\n"
             "    - ``<op>`` can be:\n\n"
             "      - ``<``  ``>``  ``<=``  ``>=``  ``=``\n\n"
             "      - ``~`` the string or any list element matches the regexp value\n\n"
             "      - ``~=`` the string matches regexp value or any list element is the value\n\n"
             "Examples:\n\n"
             "- ``*dns,ha*+app.timeout>1``\n\n"
             "- ``ip:+task:``\n\n"
             "- ``!*excluded``\n\n"
             "- ``$.avail=warn``\n\n"
             "- ``$.nodes.*.status.avail=warn``\n\n"
             "Note:\n\n"
             "- ``!`` usage requires single quoting the expression to prevent "
             "shell history expansion"),
    "show_disabled": Option(
        "--show-disabled", default=None,
        action="store_true", dest="show_disabled",
        help="Include the disabled resources. This option supersedes "
             "the :kw:`show_disabled` value in the service configuration."),
    "slave": Option(
        "--slave", default=None, action="store", dest="slave",
        help="Limit the action to the service resources in the specified, comma-"
             "separated, slaves."),
    "slaves": Option(
        "--slaves", default=False,
        action="store_true", dest="slaves",
        help="Limit the action scope to service resources in all slaves."),
    "status": Option(
        "--status", default=None,
        action="store", dest="parm_status",
        help="Operate only on service with a local instance in the specified availability status "
             "(up, down, warn, ...)."),
    "subsets": Option(
        "--subsets", default=None,
        action="store", dest="parm_subsets",
        help="Limit the action to the resources in the specified, comma-separated, list of subsets."),
    "stats": Option(
        "--stats", default=False,
        action="store_true", dest="stats",
        help="Show system resources usage metrics and refresh the information every --interval."),
    "tags": Option(
        "--tags", default=None,
        action="store", dest="parm_tags",
        help="A comma-separated list of resource tags to limit "
             "action to. The ``+`` separator can be used to impose "
             "multiple tag conditions. For example, ``tag1+tag2,tag3`` "
             "limits the action to resources with both tag1 and"
             " tag2, or tag3."),
    "template": Option(
        "--template", default=None,
        action="store", dest="parm_template",
        help="The configuration file template name or id, "
             "served by the collector, to use when creating or "
             "installing a service."),
    "time": Option(
        "--time", default="300",
        action="store", dest="time",
        help="A duration expression like ``1m5s``. The maximum wait time for an "
             "async action to finish. Default is 300 seconds."),
    "unprovision": Option(
        "--unprovision", default=False,
        action="store_true", dest="unprovision",
        help="Unprovision the service resources before config files file deletion. "
             "Defaults to False."),
    "value": Option(
        "--value", default=None,
        action="store", dest="value",
        help="The value to set for the keyword pointed by :opt:`--param`"),
    "wait": Option(
        "--wait", default=False,
        action="store_true", dest="wait",
        help="Wait for asynchronous action termination."),
    "waitlock": Option(
        "--waitlock", default="-1",
        action="store", dest="parm_waitlock",
        help="A duration expression like ``5s``. The maximum wait time when acquiring "
             "the service action lock."),
    "watch": Option(
        "-w", "--watch", default=False,
        action="store_true", dest="watch",
        help="refresh the information every --interval."),
})
Ejemplo n.º 24
0
OPT = Storage({
    "help":
    Option("-h",
           "--help",
           action="store_true",
           dest="parm_help",
           help="show this help message and exit"),
    "array":
    Option(
        "-a",
        "--array",
        action="store",
        dest="array_name",
        help=
        "The name of the array, as defined in the node or cluster configuration."
    ),
    "pool":
    Option("--pool",
           action="store",
           dest="pool",
           help="The name of the DP pool"),
    "size":
    Option(
        "--size",
        action="store",
        dest="size",
        help=
        "The disk size, expressed as a size expression like 1g, 100mib, ..."),
    "lun":
    Option("--lun",
           action="store",
           dest="lun",
           help="The LUN ID to assign on LU mapping"),
    "mappings":
    Option(
        "--mappings",
        action="append",
        dest="mappings",
        help=
        "A <hba_id>:<tgt_id>,<tgt_id>,... mapping used in add map in replacement of --targetgroup and --initiatorgroup. Can be specified multiple times."
    ),
    "name":
    Option("--name", action="store", dest="name", help="A logical unit label"),
    "devnum":
    Option("--devnum",
           action="store",
           dest="devnum",
           help="A XX:CU:LDEV logical unit name"),
})
Ejemplo n.º 25
0
    def socket_parms_parser(self, server):
        data = Storage()

        # defaults
        port = Env.listener_tls_port
        data.scheme = "h2"
        data.tls = True
        data.encrypted = False
        data.server = server

        if server.startswith("https://"):
            host = server[8:]
            data.context = self.get_cluster_context()
        elif server.startswith("raw://"):
            data.tls = False
            data.scheme = "raw"
            data.encrypted = True
            port = Env.listener_port
            host = server[6:]
        elif "://" in server:
            scheme = server.split("://", 1)[0]
            raise ex.Error("unknown scheme '%s'. use 'raw' or 'https'" % scheme)

        try:
            addr, port = host.split(":", 1)
            port = int(port)
        except:
            addr = host
        data.af = socket.AF_INET
        data.to = (addr, port)
        data.to_s = "%s:%d" % data.to
        return data
Ejemplo n.º 26
0
OPT = Storage({
    "help":
    Option("-h",
           "--help",
           default=None,
           action="store_true",
           dest="parm_help",
           help="show this help message and exit"),
    "array":
    Option(
        "-a",
        "--array",
        default=None,
        action="store",
        dest="array_name",
        help=
        "The name of the array, as defined in node or cluster configuration."),
    "name":
    Option("--name",
           default=None,
           action="store",
           dest="name",
           help="The object name"),
    "volume":
    Option("--volume",
           default=None,
           action="store",
           dest="volume",
           help="The volume to create the disk into"),
    "size":
    Option(
        "--size",
        default="0",
        action="store",
        dest="size",
        help=
        "The disk size, expressed as a size expression like 1g, 100mib, ..."),
    "target":
    Option(
        "--target",
        action="append",
        dest="targets",
        help=
        "A target name to export the disk through. Can be set multiple times."
    ),
    "blocksize":
    Option("--blocksize",
           default=512,
           type=int,
           action="store",
           dest="blocksize",
           help="The exported disk blocksize in B"),
    "secure_tpc":
    Option("--secure-tpc",
           default=True,
           action="store_false",
           dest="insecure_tpc",
           help="Set the insecure_tpc flag to False"),
    "compression":
    Option("--compression",
           default="inherit",
           action="store",
           dest="compression",
           choices=["off", "inherit", "lzjb", "lz4", "gzip", "gzip-9", "zle"],
           help="Toggle compression"),
    "sparse":
    Option("--sparse",
           default=False,
           action="store_true",
           dest="sparse",
           help="Toggle zvol sparse mode."),
    "dedup":
    Option("--dedup",
           default="off",
           action="store",
           dest="dedup",
           choices=["on", "off"],
           help="Toggle dedup"),
    "naa":
    Option("--naa",
           default=None,
           action="store",
           dest="naa",
           help="The disk naa identifier"),
    "initiator":
    Option("--initiator",
           action="append",
           dest="initiators",
           help="An initiator iqn. Can be specified multiple times."),
    "auth_network":
    Option(
        "--auth-network",
        default="ALL",
        action="store",
        dest="auth_network",
        help=
        "Network authorized to access to the iSCSI target. ip or cidr addresses or 'ALL' for any ips"
    ),
    "comment":
    Option("--comment",
           action="store",
           dest="comment",
           help="Description for your reference"),
    "lun":
    Option(
        "--lun",
        action="store",
        type=int,
        dest="lun",
        help=
        "The logical unit number to assign to the extent on attach to a target. If not specified, a free lun is automatically assigned."
    ),
    "id":
    Option("--id",
           action="store",
           type=int,
           dest="id",
           help="An object id, as reported by a list action"),
    "alias":
    Option("--alias",
           action="store",
           dest="alias",
           help="An object name alias"),
    "target":
    Option("--target",
           action="append",
           dest="target",
           help="The target object iqn"),
    "target_id":
    Option("--target-id",
           action="store",
           type=int,
           dest="target_id",
           help="The target object id"),
    "authgroup_id":
    Option("--auth-group-id",
           action="store",
           type=int,
           dest="authgroup_id",
           help="The auth group object id"),
    "authtype":
    Option("--auth-type",
           action="store",
           default="None",
           dest="authtype",
           choices=["None", "CHAP", "CHAP Mutual"],
           help="None, CHAP, CHAP Mutual"),
    "portal_id":
    Option("--portal-id",
           action="store",
           type=int,
           dest="portal_id",
           help="The portal object id"),
    "initiatorgroup":
    Option("--initiatorgroup",
           action="append",
           dest="initiatorgroup",
           help="The initiator group object id"),
    "initiatorgroup_id":
    Option("--initiatorgroup-id",
           action="store",
           type=int,
           dest="initiatorgroup_id",
           help="The initiator group object id"),
    "mappings":
    Option(
        "--mappings",
        action="append",
        dest="mappings",
        help=
        "A <hba_id>:<tgt_id>,<tgt_id>,... mapping used in add map in replacement of --targetgroup and --initiatorgroup. Can be specified multiple times."
    ),
})
Ejemplo n.º 27
0
 def decrypt(self, message, cluster_name=None, secret=None, sender_id=None, structured=True):
     """
     Validate the message meta, decrypt and return the data.
     """
     if cluster_name is None:
         cluster_names = self.cluster_names
     else:
         cluster_names = [cluster_name]
     message = bdecode(message).rstrip("\0\x00")
     try:
         message = json.loads(message)
     except ValueError:
         message_len = len(message)
         if message_len > 40:
             self.log.error("misformatted encrypted message from %s: %s",
                            sender_id, message[:30]+"..."+message[-10:])
         elif message_len > 0:
             self.log.error("misformatted encrypted message from %s",
                            sender_id)
         return None, None, None
     msg_clustername = message.get("clustername")
     msg_nodename = message.get("nodename")
     if secret is None:
         if msg_nodename in self.cluster_drpnodes:
             cluster_key = self.get_secret(Storage(server=msg_nodename), None)
         else:
             cluster_key = self.cluster_key
     else:
         cluster_key = secret
     if cluster_name != "join" and \
        msg_clustername not in set(["join"]) | self.cluster_names:
         self.log.warning("discard message from cluster %s, sender %s",
                          msg_clustername, sender_id)
         return None, None, None
     if cluster_key is None:
         return None, None, None
     if msg_nodename is None:
         return None, None, None
     iv = message.get("iv")
     if iv is None:
         return None, None, None
     if self.blacklisted(sender_id):
         return None, None, None
     iv = base64.urlsafe_b64decode(to_bytes(iv))
     data = base64.urlsafe_b64decode(to_bytes(message["data"]))
     try:
         data = self._decrypt(data, cluster_key, iv)
     except Exception as exc:
         self.log.error("decrypt message from %s: %s", msg_nodename, str(exc))
         self.blacklist(sender_id)
         return None, None, None
     if sender_id:
         self.blacklist_clear(sender_id)
     if not structured:
         try:
             loaded = json.loads(bdecode(data))
         except ValueError as exc:
             loaded = data
         if not isinstance(loaded, foreign.six.text_type):
             loaded = data
         return msg_clustername, msg_nodename, loaded
     try:
         return msg_clustername, msg_nodename, json.loads(bdecode(data))
     except ValueError as exc:
         return msg_clustername, msg_nodename, data
Ejemplo n.º 28
0
 def get_node(self):
     """
     To be redefined by Crypt child classes
     """
     return Storage()
Ejemplo n.º 29
0
def add_resource(svc, driver_group, s):
    if s == "sync#i0":
        return
    if driver_group == "pool":
        driver_group = "zpool"
        match = "[z]{0,1}pool#"
    else:
        match = driver_group + "#"

    if driver_group in ("disk", "vg", "zpool") and re.match(
            match + ".+pr$", s, re.I) is not None:
        # persistent reserv resource are declared by their peer resource:
        # don't add them from here
        return

    try:
        driver_basename = svc.oget(s, "type")
    except Exception:
        driver_basename = ""

    try:
        mod = svc.load_driver(driver_group, driver_basename)
    except Exception:
        return

    tags = get_tags(svc, s)
    encap = get_encap(svc, s)

    if svc.encap and "encap" not in tags and not encap:
        return

    if not svc.encap and (encap or "encap" in tags):
        svc.has_encap_resources = True
        try:
            enode = list(svc.encapnodes)[0]
        except IndexError:
            return
        svc.encap_resources[s] = Storage({
            "rid":
            s,
            "tags":
            tags,
            "encap":
            encap,
            "subset":
            svc.oget(s, "subset", impersonate=enode),
            "nb_restart":
            get_restart(svc, s, impersonate=enode),
            "monitor":
            get_monitor(svc, s, impersonate=enode),
            "disabled":
            get_disabled(svc, s, impersonate=enode),
        })
        svc.encap_resources[s].is_disabled = lambda: svc.encap_resources[
            s].disabled
        return

    if s in svc.resources_by_id:
        return

    kwargs = svc.section_kwargs(s)
    kwargs.update(svc.section_kwargs(s, rtype=mod.DRIVER_BASENAME))
    kwargs["rid"] = s
    try:
        del kwargs["type"]
    except KeyError:
        pass
    svc += driver_class(mod)(**kwargs)
Ejemplo n.º 30
0
OPT = Storage({
    "access":
    Option("--access",
           default="rwo",
           action="store",
           dest="access",
           help="The access mode of the volume. rwo, roo, rwx, rox."),
    "blk":
    Option("--blk",
           default=False,
           action="store_true",
           dest="blk",
           help="Create a block volume instead of a formatted volume."),
    "name":
    Option("--name",
           action="store",
           dest="name",
           help="The name of the object."),
    "namespace":
    Option(
        "--namespace",
        action="store",
        dest="namespace",
        help=
        "The namespace to switch to for the action. Namespaces are cluster partitions. A default namespace can be set for the session setting the OSVC_NAMESPACE environment variable."
    ),
    "nodes":
    Option(
        "--nodes",
        default="",
        action="store",
        dest="nodes",
        help="A node selector expression. Used as the created volume nodes."),
    "pool":
    Option("--pool",
           default=None,
           action="store",
           dest="pool",
           help="The name of the storage pool."),
    "shared":
    Option("--shared",
           default=False,
           action="store_true",
           dest="shared",
           help="Create a volume service for a shared volume resource."),
    "size":
    Option("--size",
           default="rwo",
           action="store",
           dest="size",
           help="The size mode of the volume. ex: 10gi, 10g."),
    "verbose":
    Option("--verbose",
           default=False,
           action="store_true",
           dest="verbose",
           help="Include more information to some print commands output. "
           "For example, add the ``next run`` column in the output of "
           ":cmd:`om node print schedule`."),
})