Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 10, 2023
1 parent b3e7090 commit 7e1739b
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 286 deletions.
85 changes: 33 additions & 52 deletions doc/dbus_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ Service for managing storage devices.
.DInstaller.Storage1.ISCSI.Initiator
/DInstaller/Storage1/Proposal
.DInstaller.Storage1.Proposal
/DInstaller/Storage1/iscsi/node[0-9]+
/DInstaller/Storage1/iscsi_nodes/[0-9]+
.DInstaller.Storage1.ISCSI.Node
/DInstaller/Storage1/iscsi/session[0-9]+
.DInstaller.Storage1.ISCSI.Session
~~~

### D-Bus Objects
Expand Down Expand Up @@ -164,23 +162,14 @@ Moreover, it implements interfaces to manipulate the global state (perform insta

This object is exported only if a proposal was already calculated (successful or not). It can be used to inspect the result of the calculated proposal.

#### `/org/opensuse/DInstaller/Storage1/iscsi/node[0-9]+` Objects
#### `/org/opensuse/DInstaller/Storage1/iscsi_nodes/[0-9]+` Objects

~~~
/DInstaller/Storage1/iscsi/node[0-9]+
/DInstaller/Storage1/iscsi_nodes/[0-9]+
.DInstaller.Storage1.ISCSI.Node
~~~

Objects representing an iSCSI node are dynamically exported when a successful iSCSI discovery is performed, see `.org.opensuse.DInstaller.Storage1.ISCSI.Initiator` interface.

#### `/org/opensuse/DInstaller/Storage1/iscsi/session[0-9]+` Objects

~~~
/DInstaller/Storage1/iscsi/session[0-9]+
.DInstaller.Storage1.ISCSI.Session
~~~

Objects representing an active iSCSI session are dynamically exported when a iSCSI login is performed, see `.org.opensuse.DInstaller.Storage1.ISCSI.Node` interface.
Objects representing iSCSI nodes are dynamically exported when a successful iSCSI discovery is performed, see `.org.opensuse.DInstaller.Storage1.ISCSI.Initiator` interface.

### D-Bus Interfaces

Expand Down Expand Up @@ -337,10 +326,12 @@ Provides methods for configuring iSCSI initiator and for discovering nodes.
##### Methods

~~~
Discover( in s address,
in u port,
in a{sv} options,
out u result)
Discover(in s address,
in u port,
in a{sv} options,
out u result)
Delete(in o iscsi_node_path,
out u result)
~~~

##### Properties
Expand All @@ -354,10 +345,10 @@ IniciatorName readable,writable s
###### `Discover` Method

~~~
Discover( in s address,
in u port,
in a{sv} options,
out u result)
Discover(in s address,
in u port,
in a{sv} options,
out u result)
~~~

Performs nodes discovery. Discovered nodes are exported with the path `/org/opensuse/DInstaller/iscsi/node[0-9]+`.
Expand All @@ -373,15 +364,30 @@ Arguments:
* `TargetPassword s`: Password for outgoing authentication.
* `out u result`: `0` on success and `1` on failure.

##### `Delete` Method

~~~
Delete(in o iscsi_node_path,
out u result)
~~~

Deletes a discovered iSCSI node. The iSCSI node object is unexported. Note that connected nodes cannot be deleted.

Arguments:

* `in o iscsi_node_path`: Path of the iSCSI node to delete.
* `out u result`: `0` on success and `1` on failure.

#### `org.opensuse.DInstaller.Storage1.ISCSI.Node` Interface

This interface is implemented by objects exported at `/org/opensuse/DInstaller/Storage1/iscsi/node[0-9]+` path. It provides information about a discovered iSCSI node and allows creating a new session.
This interface is implemented by objects exported at `/org/opensuse/DInstaller/Storage1/iscsi_nodes/[0-9]+` path. It provides information about an iSCSI node and allows to perform login and logout.

##### Methods

~~~
Login(in a{sv} options,
out u result)
Logout(out u result)
~~~

##### Properties
Expand All @@ -391,6 +397,7 @@ Target readable s
Address readable s
Port readable u
Interface readable s
Startup readable s
~~~

##### Details
Expand All @@ -414,42 +421,16 @@ Arguments:
* `Startup s`: startup mode (`manual`, `onboot`, `automatic`).
* `out u result`: `0` on success and `1` on failure.

#### `org.opensuse.DInstaller.Storage1.ISCSI.Session` Interface

This interface is implemented by objects exported at `/org/opensuse/DInstaller/Storage1/iscsi/session[0-9]+` path. It allows inspecting and closing an active iSCSI session.

##### Methods

~~~
Logout(in a{sv} options,
out u result)
~~~

##### Properties

~~~
Node readable o
Startup readable s
~~~

##### Details

###### `Logout` Method

~~~
Logout(in a{sv} options,
out u result)
Logout(out u result)
~~~

Closes an iSCSI session. If the session is correctly logged out, then the iSCSI session object is unexported.
Closes an iSCSI session.

Arguments:

* `in a{sv} options`:
* `InitiatorUsername s`: Username for incoming authentication.
* `InitiatorPassword s`: Password for incoming authentication.
* `TargetUsername s`: Username for outgoing authentication.
* `TargetPassword s`: Password for outgoing authentication.
* `out u result`: `0` on success and `1` on failure.


Expand Down
33 changes: 12 additions & 21 deletions service/lib/dinstaller/dbus/storage/iscsi_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

require "dbus"
require "dinstaller/dbus/base_object"
require "y2iscsi_client/authentication"
require "dinstaller/dbus/storage/with_iscsi_auth"

module DInstaller
module DBus
module Storage
class ISCSINode < BaseObject
extend Forwardable
include WithISCSIAuth

attr_reader :iscsi_manager

Expand Down Expand Up @@ -55,23 +56,17 @@ def initialize(iscsi_manager, iscsi_node, path, logger: nil)
dbus_reader(:connected, "b")
dbus_reader(:startup, "s")
dbus_method(:Login, "in options:a{sv}, out result:u") { |o| login(o) }
dbus_method(:Logout, "in options:a{sv}, out result:u") { |o| logout(o) }
dbus_method(:Delete, "in options:a{sv}, out result:u") { |o| delete(o) }
dbus_method(:Logout, "out result:u") { logout }
end

def_delegator :@iscsi_node, :target_name, :target
def_delegator :@iscsi_node, :portal_address, :address
def_delegator :@iscsi_node, :portal_port, :port
def_delegator :@iscsi_node, :interface
def_delegator :@iscsi_node, :connected

def port
@iscsi_node.portal_port.to_i
end

def startup
return "" unless @iscsi_node.connected

@iscsi_node.startup || ""
iscsi_node.startup.to_s
end

def iscsi_node=(value)
Expand All @@ -84,20 +79,16 @@ def iscsi_node=(value)
end

def login(options)
# TODO
auth = Y2IscsiClient::Authetication.new

iscsi_manager.login(iscsi_node, auth)
0
end
auth = iscsi_auth(options)
startup = options["Startup"]

def logout(options)
iscsi_manager.logout(iscsi_node)
0
success = iscsi_manager.login(iscsi_node, auth, startup: startup)
success ? 0 : 1
end

def delete(options)
iscsi_manager.delete(iscsi_node)
def logout
success = iscsi_manager.logout(iscsi_node)
success ? 0 : 1
end
end
end
Expand Down
71 changes: 42 additions & 29 deletions service/lib/dinstaller/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
require "dinstaller/dbus/storage/proposal_settings_converter"
require "dinstaller/dbus/storage/volume_converter"
require "dinstaller/dbus/storage/iscsi_node"
require "y2iscsi_client/authentication"
require "dinstaller/dbus/with_path_generator"
require "dinstaller/dbus/storage/with_iscsi_auth"

module DInstaller
module DBus
module Storage
# D-Bus object to manage storage installation
class Manager < BaseObject
include WithISCSIAuth
include WithServiceStatus
include ::DBus::ObjectManager
include DBus::Interfaces::Progress
Expand Down Expand Up @@ -146,26 +147,28 @@ def initiator_name=(value)
backend.iscsi.initiator.name = value
end

def iscsi_discovery(address, port, options)
initiator_username = options["InitiatorUsername"]
initiator_password = options["InitiatorPasswor"]
target_username = options["TargetUsername"]
target_password = options["TargetPassword"]
def iscsi_discover(address, port, options)
success = backend.iscsi.discover_send_targets(address, port, iscsi_auth(options))
success ? 0 : 1
end

def iscsi_delete(path)
dbus_node = iscsi_nodes_tree.find(path)
return 1 unless dbus_node

# TODO
auth = Y2IscsiClient::Authentication.new
backend.iscsi.discover_send_targets(address, port, auth)
success = backend.iscsi.delete(dbus_node.iscsi_node)
success ? 0 : 1
end

dbus_interface ISCSI_INITIATOR_INTERFACE do
dbus_accessor :initiator_name, "s"

# result: 0 success; 1 error
dbus_method :Discover,
"in address:s, in port:u, in options:a{sv}, out result:u" do |address, port, options|
busy_while { iscsi_discovery(address, port, options) }
0
busy_while { iscsi_discover(address, port, options) }
end

dbus_method(:Delete, "in node:o, out result:u") { |n| iscsi_delete(n) }
end

private
Expand All @@ -190,7 +193,9 @@ def register_proposal_callbacks
end

def register_iscsi_callbacks
backend.iscsi.on_refresh do
backend.iscsi.activate

backend.iscsi.on_probe do
refresh_iscsi_nodes
end
end
Expand All @@ -207,16 +212,18 @@ def export_proposal
end

def refresh_iscsi_nodes
@iscsi_nodes_refresher ||= ISCSINodesRefresher.new(service, backend.iscsi, logger: logger)
nodes = backend.iscsi.discovered
iscsi_nodes_tree.update(nodes)
end

refresher.refresh(nodes)
def iscsi_nodes_tree
@iscsi_nodes_tree ||= ISCSINodesTree.new(@service, backend.iscsi, logger: logger)
end

class ISCSINodesRefresher
class ISCSINodesTree
include WithPathGenerator

ROOT_PATH = "/org/opensuse/DInstaller/Storage1/ISCSI/nodes".freeze
ROOT_PATH = "/org/opensuse/DInstaller/Storage1/iscsi_nodes".freeze
path_generator ROOT_PATH

def initialize(service, iscsi_manager, logger: nil)
Expand All @@ -225,7 +232,11 @@ def initialize(service, iscsi_manager, logger: nil)
@logger = logger
end

def refresh(iscsi_nodes)
def find(path)
dbus_nodes.find { |n| n.path == path }
end

def update(iscsi_nodes)
add_new_nodes(iscsi_nodes)
update_existing_nodes(iscsi_nodes)
delete_old_nodes(iscsi_nodes)
Expand All @@ -240,13 +251,13 @@ def refresh(iscsi_nodes)
attr_reader :logger

def add_new_nodes(iscsi_nodes)
new_iscsi_nodes = iscsi_nodes.select { |n| find(n).nil? }
new_iscsi_nodes.each { |n| add(n) }
new_iscsi_nodes = iscsi_nodes.select { |n| find_node(n).nil? }
new_iscsi_nodes.each { |n| add_node(n) }
end

def update_existing_nodes(iscsi_nodes)
existing_iscsi_nodes = iscsi_nodes.reject { |n| find(n).nil? }
existing_iscsi_nodes.each { |n| update(n) }
existing_iscsi_nodes = iscsi_nodes.reject { |n| find_node(n).nil? }
existing_iscsi_nodes.each { |n| update_node(n) }
end

def delete_old_nodes(iscsi_nodes)
Expand All @@ -255,32 +266,34 @@ def delete_old_nodes(iscsi_nodes)
iscsi_nodes.none? { |n| same_iscsi_node?(n, current_node) }
end

deleted_iscsi_nodes.each { |n| delete(n) }
deleted_iscsi_nodes.each { |n| delete_node(n) }
end

def add(iscsi_node)
def add_node(iscsi_node)
dbus_node = DBus::Storage::ISCSINode.new(
iscsi_manager, iscsi_node, next_path, logger: logger)
service.export(dbus_node)
dbus_node.path
end

def update(iscsi_node)
dbus_node = find(iscsi_node)
def update_node(iscsi_node)
dbus_node = find_node(iscsi_node)
dbus_node.iscsi_node = iscsi_node
end

def delete(iscsi_node)
dbus_node = find(iscsi_node)
def delete_node(iscsi_node)
dbus_node = find_node(iscsi_node)
service.unexport(dbus_node)
end

def find(iscsi_node)
def find_node(iscsi_node)
dbus_nodes.find { |n| same_iscsi_node?(n.iscsi_node, iscsi_node) }
end

def dbus_nodes
root = service.get_node(ROOT_PATH, create: false)
return [] unless root

root.descendant_objects
end

Expand Down
Loading

0 comments on commit 7e1739b

Please sign in to comment.