Class: XenAPI::Session

Inherits:
XMLRPC::Client
  • Object
show all
Defined in:
lib/xencap/xenapi.rb

Constant Summary collapse

LOGIN_METHODS =
%w(login_with_password slave_local_login_with_password)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, proxy_host = nil, proxy_port = nil) ⇒ Session

Returns a new instance of Session.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/xencap/xenapi.rb', line 71

def initialize(uri, proxy_host=nil, proxy_port=nil)
  # uri can be one of:
  #  * "http://server.name/path"
  #  * "https://server.name/path"
  #  * "socket:///var/xapi/xapi"
  # proxy_host and proxy_port can be used to specify an HTTP proxy
  @uri = URI.parse(uri)

  case @uri.scheme.downcase
  when 'http', 'https'
    super(
      @uri.host,
      @uri.path.empty? ? "/" : @uri.path,
      @uri.port,
      proxy_host,
      proxy_port,
      nil, # user
      nil, # password
      (@uri.scheme.downcase == "https")
    )
  when 'socket'
    raise NotImplementedError.new("Sockets are not supported yet. Sorry")
  else
    raise ArgumentError.new("Unknown scheme")
  end

  @api_version = API_VERSION_1_1
  @session = ""
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



144
145
146
# File 'lib/xencap/xenapi.rb', line 144

def method_missing(sym, *args)
  self.proxy(sym.to_s, *args)
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



101
102
103
# File 'lib/xencap/xenapi.rb', line 101

def api_version
  @api_version
end

#uriObject (readonly)

Returns the value of attribute uri.



101
102
103
# File 'lib/xencap/xenapi.rb', line 101

def uri
  @uri
end

Instance Method Details

#logoutObject



125
126
127
128
129
130
131
132
# File 'lib/xencap/xenapi.rb', line 125

def logout
  # preferred method to logout the session
  if @last_login_method.to_s.start_with?("slave_local")
    self.session.local_logout
  else
    self.session.logout
  end
end

#proxy(prefix = nil, *args) ⇒ Object



134
135
136
137
# File 'lib/xencap/xenapi.rb', line 134

def proxy(prefix=nil, *args)
  # Overrides base method to use our custom Proxy class
  XenAPIProxy.new(self, prefix, args, :call)
end

#proxy2(prefix = nil, *args) ⇒ Object



139
140
141
142
# File 'lib/xencap/xenapi.rb', line 139

def proxy2(prefix=nil, *args)
  # Overrides base method to use our custom Proxy class
  XenAPIProxy.new(self, prefix, args, :call2)
end

#session_idObject



102
103
104
# File 'lib/xencap/xenapi.rb', line 102

def session_id
  @session
end