Class: Session

Inherits:
Object
  • Object
show all
Defined in:
lib/rxen.rb

Overview

Handle a session with a given XenServer

Constant Summary collapse

RPC_METHODS =

Methods to respond to

{		
		# Login / Logout 
		:login => /^login/,					
		:logout => /^logout/,
		
		# Session
		:session_change_password => /^session_change_password/,	
		:session_get_all_subject_identifiers => /^session_get_all_subject_identifiers/,
		:session_logout_subject_identifier => /^session_logout_subject_identifier/,
		:session_get_uuid => /^session_get_uuid/,
		:session_get_this_user => /^session_get_this_user/,
		:session_get_this_host => /^session_get_this_host/,
		:session_get_last_active => /^session_get_last_active/,
		:session_get_pool => /^session_get_pool/,
		:session_get_other_config => /^session_get_other_config/,
		:session_set_other_config => /^session_set_other_config/,

		# Task
		:task_create => /^task_create/,
		:task_destroy => /^task_destroy/,
		:task_get_all => /^task_get_all/,

		# Event
		:event_register => /^event_register/,
		:event_unregister => /^event_unregister/,
		:event_next => /^event_next/,
		:event_get_current_id => /^event_get_current_id/,

		# VM
		:vm_snapshot => /^VM_snapshot/,
		:vm_clone => /^VM_clone/,
		:vm_copy => /^VM_copy/,
		:vm_start => /^VM_start/,
		:vm_start_on => /^VM_start_on/,
		:vm_pause => /^VM_pause/,
		:vm_unpause => /^VM_unpause/,
		:vm_suspend => /^VM_suspend/,
		:vm_resume => /^VM_resume/,
		:vm_clean_shutdown => /^VM_clean_shutdown/,
		:vm_clean_reboot => /^VM_clean_reboot/,
		:vm_hard_showdown => /^VM_hard_shutdown/,
		:vm_pool_migrate => /^VM_pool_migrate/,
		:vm_get_possible_hosts => /^VM_get_possible_hosts/,
		:vm_assert_agile => /^VM_assert_agile/,
		:vm_get_uuid => /^VM_get_uuid/,
		:vm_get_powerstate => /^VM_get_powerstate/,
		:vm_get_name_label => /^VM_name_label/,
		:vm_get_resident_on => /^VM_get_resident_on/,
		:vm_get_all => /^VM_get_all/
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Session

Initialize with Server URI



119
120
121
122
# File 'lib/rxen.rb', line 119

def initialize(uri)
	@uri = uri
	@xenserver = SELF_SSL::XMLRPC_Client.new2(@uri)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Since methods are just forwarded to the Server with params they don’t have to be implemented itself but via responding to method_missing in the correct form



147
148
149
150
151
152
153
154
155
# File 'lib/rxen.rb', line 147

def method_missing(method, *args, &block)
	RPC_METHODS.each do |m|
		if method.to_s =~ m.last
			return xenapi_request(method, *args)
		end
	end
	# Call super class method missing
	super
end

Instance Attribute Details

#passwordObject

Access and set session attributes



116
117
118
# File 'lib/rxen.rb', line 116

def password
  @password
end

#sessionObject (readonly)

Access the Session ID



113
114
115
# File 'lib/rxen.rb', line 113

def session
  @session
end

#uriObject

Access and set session attributes



116
117
118
# File 'lib/rxen.rb', line 116

def uri
  @uri
end

#userObject

Access and set session attributes



116
117
118
# File 'lib/rxen.rb', line 116

def user
  @user
end

#xenserverObject (readonly)

Access the Session ID



113
114
115
# File 'lib/rxen.rb', line 113

def xenserver
  @xenserver
end

Class Method Details

.new_with_config(config) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rxen.rb', line 126

def new_with_config(config)
	config = JSON.parse(File.read(config))["xenserver"]
	if config.nil?
		raise XenApiConfigError, "malformed config"
	end
	
	@password = config["password"]
	@user = config["user"]
	@uri = config["uri"]
	if @password.nil? || @user.nil? || @uri.nil?
		raise XenApiConfigError, "missing uri, user, or password"
	end

	s = self.new(@uri)
	s.(@user, @password)
	return s
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

If methods are only implemented via method_missing the responds to is not working correctly anymore therefor it needs to be updated with the correct methods to be called

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
# File 'lib/rxen.rb', line 160

def respond_to?(method)
	# Check if any RPC methods match the call
	RPC_METHODS.each do |m|
		return true if method.to_s =~ m.last 
	end
	# Call super class responds_to?
	super
end