libvirt_ffi 0.6.1 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class Network < Generic
6
+ # https://libvirt.org/formatnetwork.html
7
+
8
+ root_path './network'
9
+
10
+ # <network ipv6='yes' trustGuestRxFilters='no'>
11
+ # ...
12
+ attribute :ipv6, type: :attr, cast: :bool, default: false
13
+
14
+ attribute :trust_guest_rx_filters,
15
+ type: :attr,
16
+ name: 'trustGuestRxFilters',
17
+ cast: :bool,
18
+ default: false
19
+
20
+ # <name>default</name>
21
+ # <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid>
22
+ attribute :name
23
+ attribute :uuid
24
+
25
+ # <metadata>
26
+ # <app1:foo xmlns:app1="http://app1.org/app1/">..</app1:foo>
27
+ # <app2:bar xmlns:app2="http://app1.org/app2/">..</app2:bar>
28
+ # </metadata>
29
+ attribute :metadata, type: :raw
30
+
31
+ # <bridge name="virbr0" stp="on" delay="5" macTableManager="libvirt"/>
32
+ attribute :bridge_name,
33
+ type: :attr,
34
+ name: 'name',
35
+ path: './bridge'
36
+
37
+ attribute :bridge_stp,
38
+ type: :attr,
39
+ name: 'stp',
40
+ cast: :bool,
41
+ path: './bridge'
42
+
43
+ attribute :bridge_delay,
44
+ type: :attr,
45
+ name: 'delay',
46
+ cast: :int,
47
+ path: './bridge'
48
+
49
+ attribute :bridge_mac_table_manager,
50
+ type: :attr,
51
+ name: 'macTableManager',
52
+ path: './bridge'
53
+
54
+ # <mtu size="9000"/>
55
+ attribute :mtu_size, type: :attr, path: './mtu', name: 'size', cast: :int
56
+
57
+ # <domain name="example.com" localOnly="no"/>
58
+ attribute :domain_name, type: :attr, path: './domain', name: 'name'
59
+ attribute :domain_local_only, type: :attr, path: './domain', name: 'localOnly', cast: :bool
60
+
61
+ # <forward mode='nat' dev='eth0'>
62
+ # <nat>
63
+ # <address start='1.2.3.4' end='1.2.3.10'/>
64
+ # </nat>
65
+ # </forward>
66
+ attribute :forward_mode, type: :attr, path: './forward', name: 'mode'
67
+ attribute :forward_dev, type: :attr, path: './forward', name: 'dev'
68
+ attribute :forward_nat_address, type: :forward_nat, node_name: :address
69
+ attribute :forward_nat_port, type: :forward_nat, node_name: :port
70
+
71
+ # <forward mode='passthrough'>
72
+ # <interface dev='eth10'/>
73
+ # <interface dev='eth11'/>
74
+ # <interface dev='eth12'/>
75
+ # <interface dev='eth13'/>
76
+ # <interface dev='eth14'/>
77
+ # </forward>
78
+ attribute :forward_interfaces,
79
+ type: :attr,
80
+ path: './forward/interface',
81
+ name: 'dev',
82
+ array: true
83
+
84
+ # <forward mode='passthrough'>
85
+ # <pf dev='eth0'/>
86
+ # </forward>
87
+ attribute :forward_pf,
88
+ type: :attr,
89
+ path: './forward/pf',
90
+ name: 'dev',
91
+ array: true
92
+
93
+ # <forward mode='hostdev' managed='yes'>
94
+ # <driver name='vfio'/>
95
+ # <address type='pci' domain='0' bus='4' slot='0' function='1'/>
96
+ # <address type='pci' domain='0' bus='4' slot='0' function='2'/>
97
+ # <address type='pci' domain='0' bus='4' slot='0' function='3'/>
98
+ # </forward>
99
+ attribute :forward_manager,
100
+ type: :attr,
101
+ path: './forward',
102
+ name: 'managed',
103
+ cast: :bool,
104
+ default: false
105
+
106
+ attribute :forward_driver,
107
+ type: :attr,
108
+ path: './forward/driver',
109
+ name: 'name'
110
+
111
+ attribute :forward_addresses, type: :forward_hostdev_address
112
+
113
+ attribute :mac_address,
114
+ type: :attr,
115
+ path: './mac',
116
+ name: 'address'
117
+
118
+ # <dns>
119
+ # <txt name="example" value="example value"/>
120
+ # <forwarder addr="8.8.8.8"/>
121
+ # <forwarder domain='example.com' addr="8.8.4.4"/>
122
+ # <forwarder domain='www.example.com'/>
123
+ # <srv service='name' protocol='tcp' domain='test-domain-name' target='.'
124
+ # port='1024' priority='10' weight='10'/>
125
+ # <host ip='192.168.122.2'>
126
+ # <hostname>myhost</hostname>
127
+ # <hostname>myhostalias</hostname>
128
+ # </host>
129
+ # </dns>
130
+ attribute :dns_forwarder, type: :dns_forwarder
131
+ attribute :dns_txt, type: :dns_txt
132
+ attribute :dns_host_ip, type: :attr, path: './dns/host', name: 'ip'
133
+ attribute :dns_hostnames, path: './dns/host/hostname', array: true
134
+ attribute :dns_srv, type: :dns_txt
135
+
136
+ attribute :ip_addresses, type: :struct, path: './ip', class: IpAddress, array: true
137
+
138
+ # https://libvirt.org/formatnetwork.html#elementQoS
139
+ # TODO continue from <bandwidth>
140
+
141
+ private
142
+
143
+ def parse_node_forward_nat(_, opts)
144
+ nodes = find_nodes(nil, path: "./forward/nat/#{opts[:node_name]}")
145
+
146
+ nodes.map do |node|
147
+ [node['start'], node['stop']]
148
+ end
149
+ end
150
+
151
+ def parse_node_forward_hostdev_address(_, _opts)
152
+ nodes = find_nodes(nil, path: './forward/address')
153
+
154
+ nodes.map do |node|
155
+ {
156
+ type: node['type'],
157
+ domain: node['domain'],
158
+ bus: node['bus'],
159
+ slot: node['slot'],
160
+ function: node['function']
161
+ }
162
+ end
163
+ end
164
+
165
+ def parse_node_dns_forwarder(_, _opts)
166
+ nodes = find_nodes(nil, path: './dns/forwarder')
167
+
168
+ nodes.map do |node|
169
+ {
170
+ domain: node['domain'],
171
+ addr: node['addr']
172
+ }
173
+ end
174
+ end
175
+
176
+ def parse_node_dns_txt(_, _opts)
177
+ nodes = find_nodes(nil, path: './dns/txt')
178
+
179
+ nodes.map do |node|
180
+ {
181
+ name: node['name'],
182
+ value: node['value']
183
+ }
184
+ end
185
+ end
186
+
187
+ def parse_node_dns_srv(_, _opts)
188
+ nodes = find_nodes(nil, path: './dns/srv')
189
+
190
+ nodes.map do |node|
191
+ {
192
+ name: node['name'],
193
+ protocol: node['protocol'],
194
+ target: node['target'],
195
+ port: node['port'],
196
+ priority: node['priority'],
197
+ weight: node['weight'],
198
+ domain: node['domain']
199
+ }
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
data/lib/libvirt/xml.rb CHANGED
@@ -11,13 +11,17 @@ module Libvirt
11
11
  # requires nokogiri.
12
12
 
13
13
  require 'libvirt/xml/generic'
14
- require 'libvirt/xml/storage_pool'
15
- require 'libvirt/xml/storage_volume'
16
14
  require 'libvirt/xml/memory'
17
15
  require 'libvirt/xml/graphics'
18
16
  require 'libvirt/xml/disk'
19
17
  require 'libvirt/xml/max_vcpu'
20
18
  require 'libvirt/xml/vcpu'
19
+ require 'libvirt/xml/ip_address'
20
+ require 'libvirt/xml/device_address'
21
+ require 'libvirt/xml/storage_pool'
22
+ require 'libvirt/xml/storage_volume'
23
+ require 'libvirt/xml/network'
24
+ require 'libvirt/xml/interface'
21
25
  require 'libvirt/xml/domain'
22
26
  end
23
27
  end
data/lib/libvirt.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ffi'
4
- require 'objspace'
4
+ require 'libvirt/version'
5
+ require 'libvirt/loggable'
5
6
  require 'libvirt/host_callback_storage'
6
7
  require 'libvirt/util'
7
8
  require 'libvirt/errors'
@@ -16,7 +17,8 @@ require 'libvirt/domain'
16
17
  require 'libvirt/stream'
17
18
  require 'libvirt/storage_pool'
18
19
  require 'libvirt/storage_volume'
19
- require 'libvirt/version'
20
+ require 'libvirt/network'
21
+ require 'libvirt/interface'
20
22
 
21
23
  module Libvirt
22
24
  EVENT_HANDLE_READABLE = 1
@@ -24,22 +26,22 @@ module Libvirt
24
26
  EVENT_HANDLE_ERROR = 4
25
27
  EVENT_HANDLE_HANGUP = 8
26
28
 
27
- class << self
28
- def lib_version
29
- version_ptr = ::FFI::MemoryPointer.new(:ulong)
30
- code = FFI::Host.virGetVersion(version_ptr, nil, nil)
31
- raise Errors::LibError, 'failed to get version' if code.negative?
29
+ module_function
32
30
 
33
- version_number = version_ptr.get_ulong(0)
34
- Util.parse_version(version_number)
35
- end
31
+ def lib_version
32
+ version_ptr = ::FFI::MemoryPointer.new(:ulong)
33
+ code = FFI::Host.virGetVersion(version_ptr, nil, nil)
34
+ raise Errors::LibError, 'failed to get version' if code.negative?
36
35
 
37
- def logger
38
- Util.logger
39
- end
36
+ version_number = version_ptr.get_ulong(0)
37
+ Util.parse_version(version_number)
38
+ end
39
+
40
+ def logger
41
+ Util.logger
42
+ end
40
43
 
41
- def logger=(logger)
42
- Util.logger = logger
43
- end
44
+ def logger=(logger)
45
+ Util.logger = logger
44
46
  end
45
47
  end
data/libvirt.gemspec CHANGED
@@ -3,15 +3,15 @@
3
3
  require_relative 'lib/libvirt/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'libvirt_ffi'
7
- spec.version = Libvirt::VERSION
8
- spec.authors = ['Denis Talakevich']
9
- spec.email = ['senid231@gmail.com']
6
+ spec.name = 'libvirt_ffi'
7
+ spec.version = Libvirt::VERSION
8
+ spec.authors = ['Denis Talakevich']
9
+ spec.email = ['senid231@gmail.com']
10
10
 
11
- spec.summary = 'Libvirt FFI'
12
- spec.description = 'Libvirt FFI'
13
- spec.homepage = 'https://github.com/senid231/libvirt_ffi'
14
- spec.license = 'MIT'
11
+ spec.summary = 'Libvirt FFI'
12
+ spec.description = 'Libvirt FFI'
13
+ spec.homepage = 'https://github.com/senid231/libvirt_ffi'
14
+ spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
16
  spec.metadata['homepage_uri'] = spec.homepage
17
17
  spec.metadata['source_code_uri'] = spec.homepage
@@ -20,13 +20,11 @@ Gem::Specification.new do |spec|
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
22
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|examples)/}) }
24
24
  end
25
- spec.bindir = 'exe'
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  spec.add_dependency 'ffi', '>= 1.0'
30
-
31
- spec.add_development_dependency 'rubocop', '~> 0.80.1'
32
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libvirt_ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-30 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.80.1
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.80.1
41
27
  description: Libvirt FFI
42
28
  email:
43
29
  - senid231@gmail.com
@@ -46,9 +32,10 @@ executables:
46
32
  extensions: []
47
33
  extra_rdoc_files: []
48
34
  files:
35
+ - ".github/workflows/tests.yml"
49
36
  - ".gitignore"
37
+ - ".rspec"
50
38
  - ".rubocop.yml"
51
- - ".travis.yml"
52
39
  - CODE_OF_CONDUCT.md
53
40
  - Gemfile
54
41
  - LICENSE.txt
@@ -70,9 +57,15 @@ files:
70
57
  - lib/libvirt/ffi/event.rb
71
58
  - lib/libvirt/ffi/helpers.rb
72
59
  - lib/libvirt/ffi/host.rb
60
+ - lib/libvirt/ffi/interface.rb
61
+ - lib/libvirt/ffi/network.rb
73
62
  - lib/libvirt/ffi/storage.rb
74
63
  - lib/libvirt/ffi/stream.rb
75
64
  - lib/libvirt/host_callback_storage.rb
65
+ - lib/libvirt/interface.rb
66
+ - lib/libvirt/loggable.rb
67
+ - lib/libvirt/network.rb
68
+ - lib/libvirt/network_dhcp_lease.rb
76
69
  - lib/libvirt/node_info.rb
77
70
  - lib/libvirt/storage_pool.rb
78
71
  - lib/libvirt/storage_pool_info.rb
@@ -86,21 +79,16 @@ files:
86
79
  - lib/libvirt/xml/domain.rb
87
80
  - lib/libvirt/xml/generic.rb
88
81
  - lib/libvirt/xml/graphics.rb
82
+ - lib/libvirt/xml/interface.rb
83
+ - lib/libvirt/xml/ip_address.rb
89
84
  - lib/libvirt/xml/max_vcpu.rb
90
85
  - lib/libvirt/xml/memory.rb
86
+ - lib/libvirt/xml/network.rb
91
87
  - lib/libvirt/xml/storage_pool.rb
92
88
  - lib/libvirt/xml/storage_volume.rb
93
89
  - lib/libvirt/xml/vcpu.rb
94
90
  - lib/libvirt_ffi.rb
95
91
  - libvirt.gemspec
96
- - test_usage/support/libvirt_async.rb
97
- - test_usage/support/log_formatter.rb
98
- - test_usage/test_domain.rb
99
- - test_usage/test_event_loop.rb
100
- - test_usage/test_libvirtd_restart.rb
101
- - test_usage/test_metadata.rb
102
- - test_usage/test_screenshot.rb
103
- - test_usage/test_storage.rb
104
92
  homepage: https://github.com/senid231/libvirt_ffi
105
93
  licenses:
106
94
  - MIT
@@ -123,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
111
  - !ruby/object:Gem::Version
124
112
  version: '0'
125
113
  requirements: []
126
- rubygems_version: 3.1.2
114
+ rubygems_version: 3.2.32
127
115
  signing_key:
128
116
  specification_version: 4
129
117
  summary: Libvirt FFI
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.5.7
6
- before_install: gem install bundler -v 2.1.4 --no-doc