def connect(args = {})
      begin
        disconnect if @connected
      rescue Mysql::ClientError::ServerGoneError
        @connected = false
      end

      # server might come frome several places
      # if not given in the args, use #hostname to figure out
      # which
      @server = args[:server] ? args[:server] : hostname

      # settings from config if they aren't in the args
      args[:port] ||= JSS::CONFIG.db_server_port ? JSS::CONFIG.db_server_port : Mysql::MYSQL_TCP_PORT
      args[:socket] ||= JSS::CONFIG.db_server_socket ? JSS::CONFIG.db_server_socket : DFT_SOCKET
      args[:db_name] ||= JSS::CONFIG.db_name ? JSS::CONFIG.db_name : DEFAULT_DB_NAME
      args[:user] ||= JSS::CONFIG.db_username
      args[:connect_timeout] ||= JSS::CONFIG.db_connect_timeout
      args[:read_timeout] ||= JSS::CONFIG.db_read_timeout
      args[:write_timeout] ||= JSS::CONFIG.db_write_timeout
      args[:charset] ||= DFT_CHARSET

      ### if one timeout was given, use it for all three
      args[:connect_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT
      args[:read_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT
      args[:write_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT



      @port = args[:port]
      @socket = args[:socket]
      @mysql_name = args[:db_name]
      @user = args[:user]
      @connect_timeout = args[:connect_timeout]
      @read_timeout = args[:read_timeout]
      @write_timeout = args[:write_timeout]

      # make sure we have a user, pw, server
      raise JSS::MissingDataError, 'No MySQL user specified, or listed in configuration.' unless args[:user]
      raise JSS::MissingDataError, "Missing :pw (or :prompt/:stdin) for user '#{@user}'" unless args[:pw]
      raise JSS::MissingDataError, 'No MySQL Server hostname specified, or listed in configuration.' unless @server

      @pw = if args[:pw] == :prompt
              JSS.prompt_for_password "Enter the password for the MySQL user #{@user}@#{@server}:"
            elsif args[:pw].is_a?(Symbol) && args[:pw].to_s.start_with?('stdin')
              args[:pw].to_s =~ /^stdin(\d+)$/
              line = Regexp.last_match(1)
              line ||= 2
              JSS.stdin line
            else
              args[:pw]
            end

      @mysql = Mysql.init

      @mysql.options Mysql::OPT_CONNECT_TIMEOUT, @connect_timeout
      @mysql.options Mysql::OPT_READ_TIMEOUT, @read_timeout
      @mysql.options Mysql::OPT_WRITE_TIMEOUT, @write_timeout
      @mysql.charset = args[:charset]
      @mysql.connect @server, @user, @pw, @mysql_name, @port, @socket

      @connected = true

      @server
    end
def connect(args = {})
      begin
        disconnect if @connected
      rescue Mysql::ClientError::ServerGoneError
        @connected = false
      end

      # server might come frome several places
      # if not given in the args, use #hostname to figure out
      # which
      @server = args[:server] ? args[:server] : hostname

      # settings from config if they aren't in the args
      args[:port] ||= JSS::CONFIG.db_server_port ? JSS::CONFIG.db_server_port : Mysql::MYSQL_TCP_PORT
      args[:socket] ||= JSS::CONFIG.db_server_socket ? JSS::CONFIG.db_server_socket : DFT_SOCKET
      args[:db_name] ||= JSS::CONFIG.db_name ? JSS::CONFIG.db_name : DEFAULT_DB_NAME
      args[:user] ||= JSS::CONFIG.db_username
      args[:connect_timeout] ||= JSS::CONFIG.db_connect_timeout
      args[:read_timeout] ||= JSS::CONFIG.db_read_timeout
      args[:write_timeout] ||= JSS::CONFIG.db_write_timeout
      args[:charset] ||= DFT_CHARSET

      ### if one timeout was given, use it for all three
      args[:connect_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT
      args[:read_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT
      args[:write_timeout] ||= args[:timeout] ? args[:timeout] : DFT_TIMEOUT



      @port = args[:port]
      @socket = args[:socket]
      @mysql_name = args[:db_name]
      @user = args[:user]
      @connect_timeout = args[:connect_timeout]
      @read_timeout = args[:read_timeout]
      @write_timeout = args[:write_timeout]

      # make sure we have a user, pw, server
      raise JSS::MissingDataError, 'No MySQL user specified, or listed in configuration.' unless args[:user]
      raise JSS::MissingDataError, "Missing :pw (or :prompt/:stdin) for user '#{@user}'" unless args[:pw]
      raise JSS::MissingDataError, 'No MySQL Server hostname specified, or listed in configuration.' unless @server

      @pw = if args[:pw] == :prompt
              JSS.prompt_for_password "Enter the password for the MySQL user #{@user}@#{@server}:"
            elsif args[:pw].is_a?(Symbol) && args[:pw].to_s.start_with?('stdin')
              args[:pw].to_s =~ /^stdin(\d+)$/
              line = Regexp.last_match(1)
              line ||= 2
              JSS.stdin line
            else
              args[:pw]
            end

      @mysql = Mysql.init

      @mysql.options Mysql::OPT_CONNECT_TIMEOUT, @connect_timeout
      @mysql.options Mysql::OPT_READ_TIMEOUT, @read_timeout
      @mysql.options Mysql::OPT_WRITE_TIMEOUT, @write_timeout
      @mysql.charset = args[:charset]
      @mysql.connect @server, @user, @pw, @mysql_name, @port, @socket

      @connected = true

      @server
    end
init

 Connect to the JSS MySQL database.

 @param args[Hash] the keyed arguments for connection.

 @option args :server[String] Required, the hostname of the JSS API server

 @option args :port[Integer] the port number to connect with, defaults to the default Mysql TCP port

 @option args :socket[String,Pathname] when the server is 'localhost', the path to the connection socket.

 @option args :db_name[String] the name of the database to use, defaults to 'jamfsoftware'

 @option args :user[String] Required, the mysql user to connect as

 @option args :pw[String,Symbol] Required, the password for that user, or :prompt, or :stdin
   If :prompt, the user is promted on the commandline to enter the password for the :user.
   If :stdin#, the password is read from a line of std in represented by the digit at #,
   so :stdin3 reads the passwd from the third line of standard input. defaults to line 2,
   if no digit is supplied. see {JSS.stdin}

 @option args :connect_timeout[Integer] the number of seconds to wait for an initial response, defaults to 120

 @option args :read_timeout[Integer] the number of seconds before read-request times out, defaults to 120

 @option args :write_timeout[Integer] the number of seconds before write-request times out, defaults to 120

 @option args :timeout[Integer] used for any of the timeouts that aren't explicitly set.

 @return [true] the connection was successfully made.