Skip to content

Commit

Permalink
Merge branch 'better-local-name'
Browse files Browse the repository at this point in the history
* better-local-name:
  Get local name from qubesdb
  • Loading branch information
marmarek committed May 13, 2024
2 parents 626f183 + ba9cbf6 commit e743712
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Architecture: any
Depends:
python3-docutils,
python3-lxml,
python3-qubesdb,
python3-rpm,
python3-tqdm,
${python3:Depends},
Expand Down
19 changes: 18 additions & 1 deletion qubesadmin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
import qubesadmin.config
import qubesadmin.devices

try:
import qubesdb
has_qubesdb = True
except ImportError:
has_qubesdb = False


class VMCollection(object):
"""Collection of VMs objects"""
Expand Down Expand Up @@ -257,7 +263,18 @@ def remove_pool(self, name):
def local_name(self):
""" Get localhost name """
if not self._local_name:
self._local_name = os.uname()[1]
local_name = None
if has_qubesdb:
try:
local_qdb = qubesdb.QubesDB()
local_name_b = local_qdb.read('/name')
if local_name_b:
local_name = local_name_b.decode()
except qubesdb.Error:
pass
if local_name is None:
local_name = os.uname()[1]
self._local_name = local_name

return self._local_name

Expand Down
1 change: 1 addition & 0 deletions rpm_spec/qubes-core-admin-client.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Requires: python%{python3_pkgversion}-daemon
Requires: python%{python3_pkgversion}-docutils
Requires: python%{python3_pkgversion}-lxml
Requires: python%{python3_pkgversion}-xcffib
Requires: python%{python3_pkgversion}-qubesdb
Requires: python%{python3_pkgversion}-rpm
Requires: python%{python3_pkgversion}-tqdm
Requires: python%{python3_pkgversion}-pyxdg
Expand Down
6 changes: 6 additions & 0 deletions test-packages/qubesdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class QubesDB:
def read(self, key):
return b'testvm'

class Error(Exception):
pass

0 comments on commit e743712

Please sign in to comment.