Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vyos.utils: T5195: import vyos.cpu to this package (backport #3606) #3624

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/vyos/configdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def get_accel_dict(config, base, chap_secrets, with_pki=False):
Return a dictionary with the necessary interface config keys.
"""
from vyos.cpu import get_core_count
from vyos.utils.cpu import get_core_count
from vyos.template import is_ipv4

dict = config.get_config_dict(base, key_mangling=('-', '_'),
Expand Down
3 changes: 2 additions & 1 deletion python/vyos/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 VyOS maintainers and contributors <[email protected]>
# Copyright 2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -18,6 +18,7 @@
from vyos.utils import boot
from vyos.utils import commit
from vyos.utils import convert
from vyos.utils import cpu
from vyos.utils import dict
from vyos.utils import file
from vyos.utils import io
Expand Down
1 change: 0 additions & 1 deletion python/vyos/cpu.py → python/vyos/utils/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import re


def _read_cpuinfo():
with open('/proc/cpuinfo', 'r') as f:
lines = f.read().strip()
Expand Down
2 changes: 1 addition & 1 deletion smoketest/scripts/cli/base_accel_ppp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from vyos.configsession import ConfigSessionError
from vyos.template import is_ipv4
from vyos.cpu import get_core_count
from vyos.utils.cpu import get_core_count
from vyos.utils.process import process_named_running
from vyos.utils.process import cmd

Expand Down
2 changes: 1 addition & 1 deletion src/conf_mode/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from vyos.configdict import is_node_changed
from vyos.configverify import verify_vrf
from vyos.ifconfig import Interface
from vyos.cpu import get_core_count
from vyos.utils.cpu import get_core_count
from vyos.utils.file import write_file
from vyos.utils.process import call
from vyos.utils.process import cmd
Expand Down
12 changes: 6 additions & 6 deletions src/op_mode/cpu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2016-2022 VyOS maintainers and contributors
# Copyright (C) 2016-2024 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
Expand All @@ -16,8 +16,9 @@

import sys

import vyos.cpu
import vyos.opmode
from vyos.utils.cpu import get_cpus
from vyos.utils.cpu import get_core_count

from jinja2 import Template

Expand All @@ -37,15 +38,15 @@
""")

def _get_raw_data():
return vyos.cpu.get_cpus()
return get_cpus()

def _format_cpus(cpu_data):
env = {'cpus': cpu_data}
return cpu_template.render(env).strip()

def _get_summary_data():
count = vyos.cpu.get_core_count()
cpu_data = vyos.cpu.get_cpus()
count = get_core_count()
cpu_data = get_cpus()
models = [c['model name'] for c in cpu_data]
env = {'count': count, "models": models}

Expand Down Expand Up @@ -79,4 +80,3 @@ def show_summary(raw: bool):
except (ValueError, vyos.opmode.Error) as e:
print(e)
sys.exit(1)

4 changes: 2 additions & 2 deletions src/op_mode/uptime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright (C) 2021-2023 VyOS maintainers and contributors
# Copyright (C) 2021-2024 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 as
Expand Down Expand Up @@ -29,8 +29,8 @@ def _get_uptime_seconds():

def _get_load_averages():
from re import search
from vyos.utils.cpu import get_core_count
from vyos.utils.process import cmd
from vyos.cpu import get_core_count

data = cmd("uptime")
matches = search(r"load average:\s*(?P<one>[0-9\.]+)\s*,\s*(?P<five>[0-9\.]+)\s*,\s*(?P<fifteen>[0-9\.]+)\s*", data)
Expand Down
Loading