-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-mode: T4038: Python rewrite of image tools
- Loading branch information
Showing
7 changed files
with
529 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0"?> | ||
<interfaceDefinition> | ||
<node name="show"> | ||
<children> | ||
<tagNode name="file"> | ||
<properties> | ||
<help>Show the contents of a file, a directory or an image</help> | ||
<completionHelp><imagePath/></completionHelp> | ||
</properties> | ||
<command>sudo ${vyos_op_scripts_dir}/file.py --show $3</command> | ||
</tagNode> | ||
</children> | ||
</node> | ||
<node name="copy"> | ||
<properties> | ||
<help>Copy an object</help> | ||
</properties> | ||
<children> | ||
<tagNode name="file"> | ||
<properties> | ||
<help>Copy a file or a directory</help> | ||
<completionHelp><imagePath/></completionHelp> | ||
</properties> | ||
<children> | ||
<tagNode name="to"> | ||
<properties> | ||
<help>Destination path</help> | ||
<completionHelp><imagePath/></completionHelp> | ||
</properties> | ||
<command>sudo ${vyos_op_scripts_dir}/file.py --copy $3 $5 | ||
</command> | ||
</tagNode> | ||
</children> | ||
</tagNode> | ||
</children> | ||
</node> | ||
<node name="delete"> | ||
<properties> | ||
<help>Delete an object</help> | ||
</properties> | ||
<children> | ||
<tagNode name="file"> | ||
<properties> | ||
<help>Delete a local file, possibly from an image</help> | ||
<completionHelp><imagePath/></completionHelp> | ||
</properties> | ||
<command>sudo ${vyos_op_scripts_dir}/file.py --delete $3</command> | ||
</tagNode> | ||
</children> | ||
</node> | ||
<node name="clone"> | ||
<properties> | ||
<help>Clone an object</help> | ||
</properties> | ||
<children> | ||
<node name="system"> | ||
<properties> | ||
<help>Clone a system object</help> | ||
</properties> | ||
<children> | ||
<tagNode name="config"> | ||
<properties> | ||
<help>Clone the current system configuration to an image</help> | ||
<completionHelp> | ||
<script>${vyos_completion_dir}/list_images.py --no-running</script> | ||
</completionHelp> | ||
</properties> | ||
<command>sudo ${vyos_op_scripts_dir}/file.py --clone $4</command> | ||
<children> | ||
<tagNode name="from"> | ||
<properties> | ||
<help>Clone system configuration from an image to another one</help> | ||
<completionHelp> | ||
<list>running</list> | ||
<script>${vyos_completion_dir}/list_images.py</script> | ||
</completionHelp> | ||
</properties> | ||
<command>sudo ${vyos_op_scripts_dir}/file.py --clone-from $6 $4</command> | ||
</tagNode> | ||
</children> | ||
</tagNode> | ||
</children> | ||
</node> | ||
</children> | ||
</node> | ||
</interfaceDefinition> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (C) 2023 VyOS maintainers and contributors | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 2 or later as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import argparse | ||
import os | ||
import re | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description='list available system images') | ||
parser.add_argument('--no-running', action='store_true', | ||
help='do not display the currently running image') | ||
|
||
def get_current_image() -> str: | ||
with open('/proc/cmdline', 'r') as f: | ||
return re.match(r'BOOT_IMAGE=/boot/([^/]+)/vmlinuz', f.readline()).group(1) | ||
|
||
def get_images(omit_running: bool = False) -> list[str]: | ||
images = os.listdir("/lib/live/mount/persistence/boot") | ||
# Check if we're running on a live disk | ||
if os.path.isdir("/lib/live/mount/persistence/config") and not omit_running: | ||
images += 'disk-install' | ||
elif omit_running: | ||
images.remove(get_current_image()) | ||
images.remove('grub') | ||
return sorted(images) | ||
|
||
if __name__ == '__main__': | ||
args = parser.parse_args() | ||
print("\n".join(get_images(omit_running=args.no_running))) | ||
sys.exit(0) |
Oops, something went wrong.