Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
truenas-rk3588
truenas
Commits
18872250
Commit
18872250
authored
5 years ago
by
themylogin
Committed by
William Grzybowski
5 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Don't offer to restart disabled and stopped services on pool unlock
parent
a9bffd96
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/middlewared/middlewared/plugins/pool.py
+49
-26
src/middlewared/middlewared/plugins/pool.py
src/middlewared/middlewared/plugins/vm.py
+1
-1
src/middlewared/middlewared/plugins/vm.py
with
50 additions
and
27 deletions
+50
-27
src/middlewared/middlewared/plugins/pool.py
View file @
18872250
...
...
@@ -1514,23 +1514,62 @@ class PoolService(CRUDService):
return
True
@
accepts
()
async
def
unlock_services_restart_choices
(
self
):
@
accepts
(
Int
(
'id'
)
)
async
def
unlock_services_restart_choices
(
self
,
oid
):
"""
Get a mapping of services identifiers and labels that can be restart
on volume unlock.
"""
svcs
=
{
pool
=
await
self
.
_get_instance
(
oid
)
services
=
{
'afp'
:
'AFP'
,
'cifs'
:
'SMB'
,
'ftp'
:
'FTP'
,
'iscsitarget'
:
'iSCSI'
,
'nfs'
:
'NFS'
,
'webdav'
:
'WebDAV'
,
'jails'
:
'Jails/Plugins'
,
'vms'
:
'Virtual Machines'
,
}
return
svcs
result
=
{}
for
k
,
v
in
services
.
items
():
service
=
await
self
.
middleware
.
call
(
'service.query'
,
[[
'service'
,
'='
,
k
]],
{
'get'
:
True
})
if
service
[
'enable'
]
or
service
[
'state'
]
==
'RUNNING'
:
result
[
k
]
=
v
try
:
activated_pool
=
await
self
.
middleware
.
call
(
'jail.get_activated_pool'
)
except
Exception
:
activated_pool
=
None
# If iocage is not activated yet, there is a chance that this pool might have it activated there
if
activated_pool
is
None
:
result
[
'jails'
]
=
'Jails/Plugins'
if
await
self
.
_unlock_restarted_vms
(
pool
[
'name'
]):
result
[
'vms'
]
=
'Virtual Machines'
return
result
async
def
_unlock_restarted_vms
(
self
,
pool_name
):
result
=
[]
vms
=
(
await
self
.
middleware
.
call
(
'vm.query'
,
[(
'autostart'
,
'='
,
True
)])
)
for
vm
in
vms
:
for
device
in
vm
[
'devices'
]:
if
device
[
'dtype'
]
not
in
(
'DISK'
,
'RAW'
):
continue
path
=
device
[
'attributes'
].
get
(
'path'
)
if
not
path
:
continue
if
path
.
startswith
(
f
'/dev/zvol/
{
pool_name
}
/'
)
or
path
.
startswith
(
f
'/mnt/
{
pool_name
}
/'
):
result
.
append
(
vm
)
break
return
result
@
item_method
@
accepts
(
Int
(
'id'
),
Dict
(
...
...
@@ -1585,14 +1624,6 @@ class PoolService(CRUDService):
'options.passphrase'
,
'Provide a passphrase or a recovery key.'
)
services_restart_choices
=
set
((
await
self
.
unlock_services_restart_choices
()).
keys
())
options_services_restart
=
set
(
options
[
'services_restart'
])
invalid_choices
=
options_services_restart
-
services_restart_choices
if
invalid_choices
:
verrors
.
add
(
'options.services_restart'
,
f
'Invalid choices:
{
", "
.
join
(
invalid_choices
)
}
'
)
if
verrors
:
raise
verrors
...
...
@@ -1631,22 +1662,14 @@ class PoolService(CRUDService):
await
self
.
middleware
.
call
(
'pool.sync_encrypted'
,
oid
)
await
self
.
middleware
.
call
(
'core.bulk'
,
'service.restart'
,
[
[
i
]
for
i
in
options
[
'services_restart'
]
+
[
'system_datasets'
,
'disk'
]
[
i
]
for
i
in
set
(
options
[
'services_restart'
]
)
|
{
'system_datasets'
,
'disk'
}
-
{
'jails'
,
'vms'
}
])
if
'jails'
in
options
[
'services_restart'
]:
await
self
.
middleware
.
call
(
'core.bulk'
,
'jail.rc_action'
,
[[
'RESTART'
]])
if
'vms'
in
options
[
'services_restart'
]:
vms
=
(
await
self
.
middleware
.
call
(
'vm.query'
,
[(
'autostart'
,
'='
,
True
)])
)
pool_name
=
pool
[
'name'
]
for
vm
in
vms
:
for
device
in
vm
[
'devices'
]:
path
=
device
[
'attributes'
].
get
(
'path'
,
''
)
if
f
'/dev/zvol/
{
pool_name
}
/'
in
path
or
\
f
'/mnt/
{
pool_name
}
/'
in
path
:
await
self
.
middleware
.
call
(
'vm.stop'
,
vm
[
'id'
])
await
self
.
middleware
.
call
(
'vm.start'
,
vm
[
'id'
])
for
vm
in
await
self
.
_unlock_restarted_vms
(
pool
[
'name'
]):
await
self
.
middleware
.
call
(
'vm.stop'
,
vm
[
'id'
])
await
self
.
middleware
.
call
(
'vm.start'
,
vm
[
'id'
])
await
self
.
middleware
.
call_hook
(
'pool.post_unlock'
,
pool
=
pool
)
...
...
This diff is collapsed.
Click to expand it.
src/middlewared/middlewared/plugins/vm.py
View file @
18872250
...
...
@@ -1679,7 +1679,7 @@ class VMFSAttachmentDelegate(FSAttachmentDelegate):
if
device
[
'dtype'
]
not
in
(
'DISK'
,
'RAW'
):
continue
disk
=
device
[
'attributes'
].
get
(
'path'
,
None
)
disk
=
device
[
'attributes'
].
get
(
'path'
)
if
not
disk
:
continue
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment