Thursday, August 19, 2021

Set up KVM && Cockpit WEB Console on Debian Bullseye (11)

UPDATE 08/31/21
In case setting up Debian 11 with KDE you would have manually select "Remote Viewer'  from drop-down menu inside Cockpit Console. It won't be detected automatically like in Debian 11 with Gnome desktop




















END UPDATE
UPDATE as of 08/29/21
After kernel upgrade up to 5.13-trunk-amd64 . KVM Hypervisor seems to keep working stable. See How to Install Backports & Experimental Repository on Debian 11
END UPDATE

The presence of Web Cockpit Console is a nice way to manage KVM guest's deployment via clicking the button "Remote Virt-viewer"  built into Cockpit Web Console. Bridge attached to external network interface was also created pretty smoothly utilizing network management section inside Web Console. However, it doesn't look to me as a reason to deprecate virt-manager . Virt-manager still provides a way to edit guest definitions which can be very handy and  sometimes seems to be more flexible versus Cockpit Web console in my very personal opinion.

 Install KVM

 $ sudo apt install qemu-kvm  libvirt-daemon bridge-utils \
         virtinst libvirt-daemon-system -y
 $ sudo apt install  libguestfs-tools libosinfo-bin \
       qemu-system virt-manager -y
 $  sudo modprobe vhost_net 
 $  lsmod | grep vhost
 $  echo vhost_net | sudo tee -a /etc/modules
 $  sudo usermod -a -G libvirt  $(whoami)
 $  sudo reboot

 Install Web Cockpit Console
 $  sudo apt install install cockpit cockpit-machines
 $  sudo apt install cockpit cockpit-machines
 $  sudo systemctl start cockpit.socket
 $  sudo systemctl enable cockpit.socket

 Tuning firewall
 $  sudo apt install firewalld
 $  sudo firewall-cmd --add-service=cockpit --permanent
 $  sudo firewall-cmd --reload


























































































































Tuesday, August 17, 2021

Set up KVM && Cockpit WEB Console on Ubuntu DDE 21.04

First notice that we intend set up Ubuntu DDE on Ryzen 7 3700  box with board MSI X570 A-PRO in UEFI mode with "kvm" enabled. Enable SVM in the BIOS Setup due to it is disabled by default. This step might be the hardest to complete in the whole installation procedure. It requires scrolling down the screen to an area which is not visible on the original screen view. To make things clear I have to notice that the cheap board MSI B450M causes the same issues.  ASUS boards for Ryzen CPU Line have a really nice and understandable interface but are significantly more expensive. However, I cannot complain reliability of MSI hardware.














Right after bootup make sure"dmesg" report is OK















Start to install via Calamares installer Ubuntu DDE instance on Ryzen 7 3700 UEFI Box















Now proceed with KVM installation

$ sudo apt install -y qemu qemu-kvm libvirt-daemon \

libvirt-clients bridge-utils virt-manager 

$  sudo systemctl status libvirtd 
$  sudo systemctl enable --now libvirtd 
$   sudo apt install uvtool 

Load via modprobe vhost_net module

$ sudo modprobe vhost_net 
$ lsmod | grep  vhost_net 
$ echo vhost_net | sudo tee -a /etc/modules

Reboot System and proceed with cockpit.socket installation 

$ sudo apt install cockpit cockpit-machines
$ sudo systemctl start cockpit.socket  
$  sudo systemctl status cockpit.socket
$  sudo systemctl enable cockpit.socket

Open port 9090 via firewalld

 $  sudo apt install firewalld
 $  sudo firewall-cmd --add-service=cockpit --permanent
 $  sudo firewall-cmd --reload

Launch firefox to https://IP:9090

Configure KVM Guest via Cockpit console users interface



























 Now start the Guest and open Remote-viewer Console 

















Thursday, August 12, 2021

Setting up KDE Plasma on Rocky Linux 8.4 KVM/VBOX 6.1.26 Guest on Server F34

Following below is a brief set of instructions setting up KDE Plasma on RockyLinux along with Gnome Desktop Manager which is actually needed to support graphical login, otherwise system might be started via text login followed by "startx".

The core idea is to install and activate just GDM to make graphical login enabled on Rocky Linux 8.4

Perform guest deployment via Rocky-8.4-x86_64-minimal.iso

$ sudo dnf update -y

$ sudo reboot

$ sudo dnf install epel-release

$ sudo dnf config-manager --set-enabled powertools

$ sudo dnf --enablerepo=epel,powertools group -y install \

                      "KDE Plasma Workspaces" "base-x"

$ sudo dnf install gdm

$ sudo systemctl start gdm

$ sudo systemctl enable gdm

$ sudo systemctl set-default graphical.target

$ sudo reboot










































Virtual Box 6.1.26 KDE Guest might be setup with no issues as well























Monday, August 9, 2021

Install SQLITEBROWSER on RockyLinux 8.4

Following below is a brief set of instructions to install sqlitebrowser on RockyLinux 8.4 , which installs sqlite-devel before the building the most recent Python release via source tarball

$  sudo dnf groupinstall "Development Tools" -y

$ sudo dnf install openssl-devel libffi-devel bzip2-devel -y

$ sudo dnf install sqlite-devel

$ wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz

$ tar -xvf Python-3.9.6.tgz

$ cd ./Python-3.9.6

$ ./configure —enable-optimizations

$ sudo make altinstall

Prepare to build sqlitebrowser which wouldn't

have any issues with Qt vs the one provided via snap

$ sudo dnf install qt5-* 

$ git clone https://github.com/sqlitebrowser/sqlitebrowser

$ cd sqlitebrowser

$ cmake -Wno-dev .

$ make

$ sudo make install





































Thursday, August 5, 2021

Python Wrapper for C++ solving the recent YandexQ problem

In this post I follow approach suggested  in How to wrap a C++ object using pure Python Extension API  which differs from C++ coding technique been presented earlier.  Public Class Strike containing method "filter" is supposed to be declared. Later on in PyStrike_init( ) new instance of this class is been created. Structure PyStrike been declared right after "using abc::Strike", has a field PtrObject which is a pointer to Strike in PyStrike_init( ) following assignment is taken place  self->ptrObj=new Strike(fftSize). This assignment allows in PyStrike_filter( ) to invoke "filter" method and obtain the resulting number via call "retval = (self->ptrObj)->filter(freq,sqnc)" to return retval to Python as follows "return Py_BuildValue("l",retval)"

Same technique has been used in my recent blog entry Another version of Python to C++ Extension building Catalan Sequence

Problem itself

ABCDEF is a six-digit number. They are all different and are arranged from left to right in ascending order. The number is a complete square. Detect at least one six-digit ABCDEFs having this feature .

(.env) [boris@fedora33server VOICE]$ ll

total 20

drwxrwxr-x. 4 boris boris   63 Aug  5 19:13 build

drwxrwxr-x. 2 boris boris  120 Aug  5 17:41 CPP

-rw-rw-r--. 1 boris boris  164 Aug  5 17:36 setup.py

-rw-rw-r--. 1 boris boris  824 Aug  5 19:10 Strike.cpp

-rw-rw-r--. 1 boris boris  272 Aug  5 18:58 Strike.h

-rw-rw-r--. 1 boris boris 2104 Aug  5 19:09 strikeWrapper.cpp

-rw-rw-r--. 1 boris boris  130 Aug  5 19:01 test.py

(.env) [boris@fedora33server VOICE]$ cat Strike.h

#pragma once

#include <cstddef>

#include <cstdio>

namespace abc {

    class Strike {

    public:

        double *mem;

        long fftSize;

        Strike(long fftSize);

        ~Strike();

        long filter(long freq,long nqc);

        long CaughIt(int n);

    };

}

(.env) [boris@fedora33server VOICE]$ cat Strike.cpp

#include <cstdio>

#include <cstddef>

#include <string>

#include "Strike.h"

#pragma GCC diagnostic ignored "-Wsign-compare"

namespace abc

    Strike::Strike(long fftSize) {

        printf("c++ constructor of Strike\n");

        this->fftSize=fftSize;

        mem=new double[fftSize];

        } 

    Strike::~Strike() { delete [] mem; } 

    long Strike::filter(long freq,long sqc) {

        printf("c++ Strike filter method\n");

        return (CaughIt(sqc));

    }

    long Strike::CaughIt(int n) 

    { 

     for (int i=200; i < n; i++)

     {

     std::string ans = std::to_string(i*i);

      if ((int(ans[0])< int(ans[1])) && \ 

         (int(ans[1]) < int(ans[2])) && \

         (int(ans[2]) < int(ans[3])) && \

         (int(ans[3]) < int(ans[4])) && \

         (int(ans[4]) < int(ans[5])))    

              return (i*i);

     }

    }

}

(.env) [boris@fedora33server VOICE]$ cat strikeWrapper.cpp

#include <Python.h>

#include <cstdio>

#include <string.h>

#include "Strike.h"

#pragma GCC diagnostic ignored "-Wsign-compare"

using abc::Strike;

typedef struct {

    PyObject_HEAD

    Strike * ptrObj;

PyStrike;

static PyModuleDef blademodule = {

    PyModuleDef_HEAD_INIT,

    "blade",

    "Example module that wrapped a C++ object",

    -1,

    NULL, NULL, NULL, NULL, NULL

};

static int PyStrike_init(PyStrike *self, PyObject *args, PyObject *kwds)

// initialize PyStrike Object

{

    long fftSize;

    if (! PyArg_ParseTuple(args, "l", &fftSize))

        return -1;

    self->ptrObj=new Strike(fftSize);

    return 0;

}

static void PyStrike_dealloc(PyStrike * self)

// destruct the object

{

    delete self->ptrObj;

    Py_TYPE(self)->tp_free(self);

}

static PyObject * PyStrike_filter(PyStrike* self, PyObject* args)

{

    long freq;

    long retval;

    long sqnc ;

    if (! PyArg_ParseTuple(args, "ll", &freq,&sqnc))

        return Py_False;

    retval = (self->ptrObj)->filter(freq,sqnc);

    return Py_BuildValue("l",retval);

}

static PyMethodDef PyStrike_methods[] = {

    { "filter", (PyCFunction)PyStrike_filter,METH_VARARGS,"filter the mem blade" },

    {NULL}  /* Sentinel */

};

static PyTypeObject PyStrikeType = { PyVarObject_HEAD_INIT(NULL, 0)

           "blade.Strike"   /* tp_name */

                                };

PyMODINIT_FUNC PyInit_blade(void)

// create the module

{

    PyObject* m;

    PyStrikeType.tp_new = PyType_GenericNew;

    PyStrikeType.tp_basicsize=sizeof(PyStrike);

    PyStrikeType.tp_dealloc=(destructor) PyStrike_dealloc;

    PyStrikeType.tp_flags=Py_TPFLAGS_DEFAULT;

    PyStrikeType.tp_doc="Strike objects";

    PyStrikeType.tp_methods=PyStrike_methods;

    PyStrikeType.tp_init=(initproc)PyStrike_init;

    if (PyType_Ready(&PyStrikeType) < 0)

        return NULL;

    m = PyModule_Create(&blademodule);

    if (m == NULL)

        return NULL;

    Py_INCREF(&PyStrikeType);

    PyModule_AddObject(m, "Strike", (PyObject *)&PyStrikeType); 

    return m;

}

(.env) [boris@fedora33server VOICE]$ cat setup.py

from distutils.core import setup, Extension

setup(name='bladePkg', version='1.0',  \

      ext_modules=[Extension('blade', ['strikeWrapper.cpp','Strike.cpp'])])

(.env) [boris@fedora33server VOICE]$ python setup.py install

running install

running build

running build_ext

building 'volume' extension

creating build

creating build/temp.linux-x86_64-3.9

gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/boris/VOICE/.env/include -I/usr/include/python3.9 -c Strike.cpp -o build/temp.linux-x86_64-3.9/Strike.o

gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/boris/VOICE/.env/include -I/usr/include/python3.9 -c strikeWrapper.cpp -o build/temp.linux-x86_64-3.9/strikeWrapper.o

creating build/lib.linux-x86_64-3.9

g++ -pthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -g -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -g build/temp.linux-x86_64-3.9/Strike.o build/temp.linux-x86_64-3.9/strikeWrapper.o -L/usr/lib64 -o build/lib.linux-x86_64-3.9/volume.cpython-39-x86_64-linux-gnu.so

running install_lib

copying build/lib.linux-x86_64-3.9/volume.cpython-39-x86_64-linux-gnu.so -> /home/boris/VOICE/.env/lib64/python3.9/site-packages

running install_egg_info

Removing /home/boris/VOICE/.env/lib64/python3.9/site-packages/volumePkg-1.0-py3.9.egg-info

Writing /home/boris/VOICE/.env/lib64/python3.9/site-packages/volumePkg-1.0-py3.9.egg-info

===================================

Python Wrapper itself

===================================

(.env) [boris@fedora33server VOICE]$ cat test.py

import blade

n = int(input("Input upper scan limit : " ))

v=blade.Strike(512)

result=v.filter(5,n)

print('result='+str(result))

===============

Runtime

===============

(.env) [boris@fedora33server VOICE]$ python test.py

Input upper scan limit : 1000

c++ constructor of Strike

c++ Strike filter method

result=134689

(.env) [boris@fedora33server VOICE]$ python test.py

Input upper scan limit : 500

c++ constructor of Strike

c++ Strike filter method

result=134689




















Now consider the different initial task

ABCDEF is a six-digit number. They are all different and are arranged from left to right in ascending order. The number is a complete square. Detect "all" six-digit ABCDEFs having this feature .

(.env) [boris@fedora33server ABCDFE]$ cat Strike.h
#pragma once
#include <cstddef>
#include <cstdio>
#include <vector>

namespace abc {

    class Strike {
    public:
        double *mem;
        long fftSize;
        Strike(long fftSize);
        ~Strike();
        std::vector<long> filter(long freq,long nqc);
        std::vector<long> CaughIt(int n);
    };
}
(.env) [boris@fedora33server ABCDFE]$ cat Strike.cpp
#include <cstdio>
#include <cstddef>
#include <string>
#include <vector>
#include "Strike.h"
#pragma GCC diagnostic ignored "-Wsign-compare"

namespace abc
    Strike::Strike(long fftSize) {
        printf("c++ constructor of Strike\n");
        this->fftSize=fftSize;
        mem=new double[fftSize];
        } 

    Strike::~Strike() { delete [] mem; } 

    std::vector<long> Strike::filter(long freq,long sqc) {
        printf("c++ Strike filter method\n");
        return (CaughIt(sqc));
    }
    std::vector<long> Strike::CaughIt(int n) 
    {
    std::vector<long>  vect; 
     for (int i=200; i < n; i++)
     {
     std::string ans = std::to_string(i*i);
      if ((int(ans[0])< int(ans[1])) && \ 
         (int(ans[1]) < int(ans[2])) && \
         (int(ans[2]) < int(ans[3])) && \
         (int(ans[3]) < int(ans[4])) && \
         (int(ans[4]) < int(ans[5])))    
              vect.push_back(i*i);
         
     }
     return(vect);
    }
} //namespace abc

(.env) [boris@fedora33server ABCDFE]$ cat strikeWrapper.cpp
#include <Python.h>
#include <cstdio>
#include <string.h>
#include <vector>
#include "Strike.h"
#pragma GCC diagnostic ignored "-Wsign-compare"
using abc::Strike;
typedef struct {
    PyObject_HEAD
    Strike * ptrObj;
} PyStrike;

static PyModuleDef blademodule = {
    PyModuleDef_HEAD_INIT,
    "blade",
    "Example module that wrapped a C++ object",
    -1,
    NULL, NULL, NULL, NULL, NULL
};
static int PyStrike_init(PyStrike *self, PyObject *args, PyObject *kwds)
// initialize PyStrike Object
{
    long fftSize;
    if (! PyArg_ParseTuple(args, "l", &fftSize))
        return -1;
    self->ptrObj=new Strike(fftSize);
    return 0;
}
static void PyStrike_dealloc(PyStrike * self)
// destruct the object
{
    delete self->ptrObj;
    Py_TYPE(self)->tp_free(self);
}
static PyObject * PyStrike_filter(PyStrike* self, PyObject* args)
{
    long freq;
    long sqnc ;
    if (! PyArg_ParseTuple(args, "ll", &freq,&sqnc))
        return Py_False;
    std::vector<long> retval = (self->ptrObj)->filter(freq,sqnc);
    PyObject* result = PyList_New(retval.size());
    for(int i = 0; i < retval.size(); i++) {
        PyList_SetItem(result, i, PyLong_FromLong(retval[i]));
    }
    return result;
}
static PyMethodDef PyStrike_methods[] = {
    { "filter", (PyCFunction)PyStrike_filter,METH_VARARGS,"filter the mem blade" },
    {NULL}  /* Sentinel */
};

static PyTypeObject PyStrikeType = { PyVarObject_HEAD_INIT(NULL, 0)
            "blade.Strike"   /* tp_name */
                                };

PyMODINIT_FUNC PyInit_blade(void)
// create the module
{
    PyObject* m;

    PyStrikeType.tp_new = PyType_GenericNew;
    PyStrikeType.tp_basicsize=sizeof(PyStrike);
    PyStrikeType.tp_dealloc=(destructor) PyStrike_dealloc;
    PyStrikeType.tp_flags=Py_TPFLAGS_DEFAULT;
    PyStrikeType.tp_doc="Strike objects";
    PyStrikeType.tp_methods=PyStrike_methods;
    PyStrikeType.tp_init=(initproc)PyStrike_init;

    if (PyType_Ready(&PyStrikeType) < 0)
        return NULL;

    m = PyModule_Create(&blademodule);
    if (m == NULL)
        return NULL;

    Py_INCREF(&PyStrikeType);
    PyModule_AddObject(m, "Strike", (PyObject *)&PyStrikeType); 
    return m;
}

(.env) [boris@fedora33server ABCDFE]$ python setup.py install