Actifio/Actifio.py
def run_uds_command(self, cmdType,
    cmdUDS,
    cmdArgs={}):
    """
    Wrapper function to convert CLI commands to the rest API.

    Args:

      :cmdType: info / task
      :cmdUDS: Command to use (eg. lsuser, lshost, mkapplication... etc.)
      :cmdArgs: Dictionary with arguments to the command

    Returns:

      Returns a dictionary of API response.

    Example:

      vmdiscovery -discovercluster -host 1234

      { 'discovercluster': None, 'host': 1234 }

      lsapplication -filtervalues "appname=mydb&hostname=myhost"

      { 'filtervalues': { 'appname': 'mydb', 'hostname': 'myhost' } }

      lshost 123

      { 'argument': 123 }


    .. note:: RESTfulAPI_*.pdf would be good referecne point for the __SIMILARITY__ and __PATTERN__ of the cmdArgs.

    """

    _URI = self._infoURI if cmdType == "info" else self._taskURI

    # append the command to URI
    _URI += cmdUDS + '?'

    # provision for the non-equal opprations
    def __regex_args(key, value):
      import re
      not_equal = re.compile(r'^not\s+(.*)')
      greater_than = re.compile(r'^\>\s*(.*)')
      smaler_than = re.compile(r'^\<\s*(.*)')

      ne_match = not_equal.search(value)
      gt_match = greater_than.search(value)
      st_match = smaler_than.search(value)

      if ne_match is not None:
        return key + "!=" + ne_match.group(1)
      if st_match is not None:
        if key != "provisioningoptions":
          return key + "<" + st_match.group(1)
      if gt_match is not None:
        return key + ">" + gt_match.group(1)
      else:
        return key + "=" + value

    # append the argument
    for key in cmdArgs:
      if type(cmdArgs[key]) == dict:
        # Actifio API expects this to be urlencoded
        _URI += key + '=' + urlencode_str('&'.join([ __regex_args(filter_key, cmdArgs[key][filter_key]) for filter_key in cmdArgs[key]])) + '&'
      elif cmdArgs[key] == None:
        _URI += urlencode_str(key) + '&'
      else:
        _URI += urlencode_str(key) + '=' + urlencode_str(str(cmdArgs[key])) + '&'

    _URI += 'sessionid=' + Actifio._sessionid[self.appliance][self.username]["sessionid"]
    try:
      udsout = self._httppool.request (
        'GET' if cmdType == 'info' else 'POST',
        _URI
      )
      if self._verbose:
        print(_URI)
    except Exception as e:
      # print (e)
      raise ActConnectError("Failed to connect the appliance")
    else:
      response = json.loads(udsout.data)
      if udsout.status != 200:
        self._lastout = ''
        raise ActAPIError(response['errormessage'], response['errorcode'])
      else:
        self._lastout = response
        return self._lastout

    Wrapper function to convert CLI commands to the rest API.

    Args:

      :cmdType: info / task
      :cmdUDS: Command to use (eg. lsuser, lshost, mkapplication... etc.)
      :cmdArgs: Dictionary with arguments to the command

    Returns:

      Returns a dictionary of API response.

    Example:

      vmdiscovery -discovercluster -host 1234

      { 'discovercluster': None, 'host': 1234 }

      lsapplication -filtervalues "appname=mydb&hostname=myhost"

      { 'filtervalues': { 'appname': 'mydb', 'hostname': 'myhost' } }

      lshost 123

      { 'argument': 123 }


    .. note:: RESTfulAPI_*.pdf would be good referecne point for the __SIMILARITY__ and __PATTERN__ of the cmdArgs.

    
Wrapper function to convert CLI commands to the rest API.
Wrapper function to convert CLI commands to the rest API .
def run_uds_command(self, cmdType,
    cmdUDS,
    cmdArgs={}):
    _URI = self._infoURI if cmdType == "info" else self._taskURI
    _URI += cmdUDS + '?'
    def __regex_args(key, value):
      import re
      not_equal = re.compile(r'^not\s+(.*)')
      greater_than = re.compile(r'^\>\s*(.*)')
      smaler_than = re.compile(r'^\<\s*(.*)')
      ne_match = not_equal.search(value)
      gt_match = greater_than.search(value)
      st_match = smaler_than.search(value)
      if ne_match is not None:
        return key + "!=" + ne_match.group(1)
      if st_match is not None:
        if key != "provisioningoptions":
          return key + "<" + st_match.group(1)
      if gt_match is not None:
        return key + ">" + gt_match.group(1)
      else:
        return key + "=" + value
    for key in cmdArgs:
      if type(cmdArgs[key]) == dict:
        _URI += key + '=' + urlencode_str('&'.join([ __regex_args(filter_key, cmdArgs[key][filter_key]) for filter_key in cmdArgs[key]])) + '&'
      elif cmdArgs[key] == None:
        _URI += urlencode_str(key) + '&'
      else:
        _URI += urlencode_str(key) + '=' + urlencode_str(str(cmdArgs[key])) + '&'
    _URI += 'sessionid=' + Actifio._sessionid[self.appliance][self.username]["sessionid"]
    try:
      udsout = self._httppool.request (
        'GET' if cmdType == 'info' else 'POST',
        _URI
      )
      if self._verbose:
        print(_URI)
    except Exception as e:
      raise ActConnectError("Failed to connect the appliance")
    else:
      response = json.loads(udsout.data)
      if udsout.status != 200:
        self._lastout = ''
        raise ActAPIError(response['errormessage'], response['errorcode'])
      else:
        self._lastout = response
        return self._lastout
def run_uds_command ( self , cmdType , cmdUDS , cmdArgs = { } ) : _URI = self . _infoURI if cmdType == "info" else self . _taskURI _URI += cmdUDS + '?' def __regex_args ( key , value ) : import re not_equal = re . compile ( r'^not\s+(.*)' ) greater_than = re . compile ( r'^\>\s*(.*)' ) smaler_than = re . compile ( r'^\<\s*(.*)' ) ne_match = not_equal . search ( value ) gt_match = greater_than . search ( value ) st_match = smaler_than . search ( value ) if ne_match is not None : return key + "!=" + ne_match . group ( 1 ) if st_match is not None : if key != "provisioningoptions" : return key + "<" + st_match . group ( 1 ) if gt_match is not None : return key + ">" + gt_match . group ( 1 ) else : return key + "=" + value for key in cmdArgs : if type ( cmdArgs [ key ] ) == dict : _URI += key + '=' + urlencode_str ( '&' . join ( [ __regex_args ( filter_key , cmdArgs [ key ] [ filter_key ] ) for filter_key in cmdArgs [ key ] ] ) ) + '&' elif cmdArgs [ key ] == None : _URI += urlencode_str ( key ) + '&' else : _URI += urlencode_str ( key ) + '=' + urlencode_str ( str ( cmdArgs [ key ] ) ) + '&' _URI += 'sessionid=' + Actifio . _sessionid [ self . appliance ] [ self . username ] [ "sessionid" ] try : udsout = self . _httppool . request ( 'GET' if cmdType == 'info' else 'POST' , _URI ) if self . _verbose : print ( _URI ) except Exception as e : raise ActConnectError ( "Failed to connect the appliance" ) else : response = json . loads ( udsout . data ) if udsout . status != 200 : self . _lastout = '' raise ActAPIError ( response [ 'errormessage' ] , response [ 'errorcode' ] ) else : self . _lastout = response return self . _lastout
Wrapper function to convert CLI commands to the rest API.
Wrapper function to convert CLI commands to the rest API .
"""
    Wrapper function to convert CLI commands to the rest API.

    Args:

      :cmdType: info / task
      :cmdUDS: Command to use (eg. lsuser, lshost, mkapplication... etc.)
      :cmdArgs: Dictionary with arguments to the command

    Returns:

      Returns a dictionary of API response.

    Example:

      vmdiscovery -discovercluster -host 1234

      { 'discovercluster': None, 'host': 1234 }

      lsapplication -filtervalues "appname=mydb&hostname=myhost"

      { 'filtervalues': { 'appname': 'mydb', 'hostname': 'myhost' } }

      lshost 123

      { 'argument': 123 }


    .. note:: RESTfulAPI_*.pdf would be good referecne point for the __SIMILARITY__ and __PATTERN__ of the cmdArgs.

    """ # append the command to URI # provision for the non-equal opprations # append the argument # Actifio API expects this to be urlencoded # print (e)
Returns a dictionary of API response.
Returns a dictionary of API response .
self
cmdType
cmdUDS
cmdArgs
Dictionary with arguments to the command
Dictionary with arguments to the command
examples




filtervalues "appname=mydb&hostname=myhost"

{ 'filtervalues': { 'appname': 'mydb', 'hostname': 'myhost' } }

lshost 123


filtervalues " appname = mydb&hostname = myhost " { ' filtervalues ' : { ' appname ' : ' mydb ' ' hostname ' : ' myhost ' } } lshost 123