Filed under Computer
* In Ubuntu 20.04
Install packer
~$ wget -O- | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
~$ echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
~$ sudo apt update && sudo apt install packer
~$ packer --version
Install RHEL8 template dependencies
~$ sudo apt install qemu-utils
~$ sudo apt install qemu-system
Get packer templates
Change to centos8-stream template
~$ cd packer-maas/centos8-stream
if you want change KS filethen  modify http/centos8-stream.ks file.
packer-maas/centos8-stream$ ls http/
Build the CentOS 8 stream image from ISO file.
packer-maas/centos8-stream$ make ISO=/global/iso/CentOS-Stream-8-x86_64-20220728-dvd1.iso
created centos8-stream.tar.gz file.
packer-maas/centos8-stream$ ls
centos8-stream.json centos8-stream.tar.gz http Makefile output-qemu
Copy the image file to MAAS server.
packer-maas/ centos8-stream$ scp centos8-stream.tar.gz user@maas-server:
* In maas-server
~$ cat api-key-file
Login to admin in MAAS
~$  maas login admin http://maas-server:5240/MAAS
API key (leave empty for anonymous access):
You are now logged in to the MAAS server at
http://maas-server:5240/MAAS/api/2.0/ with the profile name 'admin'.
For help with the available commands, try:
  maas admin --help
check boot resource
~$ maas admin boot-resources read
Import the image to MAAS in maas-server
*Not support Rocky OS, CentOS 8.3
~$ maas admin boot-resources create name=centos/8-stream title='CentOS8-stream' architecture='amd64/generic' filetype='tgz' content@= centos8-stream.tar.gz
Verify custom image
~$ maas admin boot-resources read
"id": 13,
"type": "Uploaded",
"name": "centos/8-stream",
"architecture": "amd64/generic",
"resource_uri": "/MAAS/api/2.0/boot-resources/13/",
"subarches": "generic",
"title": "CentOS8-stream"
Deploy the CentOS Image
goto "Setting" and select "Deploy" under "Configuration".
Select Deployment OS to "CentOS" and release to "CentOS8-stream"

User image

and deploy a machine then the server will start with Ubuntu image. but at the last procedure, the deploy OS with my selected OS (CentOS8-stream).
Login to compute node:
maas-server$ ssh centos@
[centos@cent-test-host ~]$ cat /etc/redhat-release
CentOS Stream release 8
Default user without password:
CentOS -> centos
Ubuntu -> ubuntu
Setting Password-less SSH-key in MAAS
goto "admin" -> SSH keys -> "import SSH key"
then the default user will defined with this SSH key. So you can login to server with default username with imported SSH key.

Good works OS:
centos 7
centos 8-stream
2022/08/04 07:27 2022/08/04 07:27
Filed under Computer/package
Universial Package Manager snap testing

1. Install snap package
2. Install snapcraft (package builder)
$ sudo snap install snapcraft --classic

3. Simple Python script packaging
$ mkdir ~/work
- make a package(test-app) directory
$ mkdir ~/work/test-app

4. make a python script package
$ mkdir ~/work/test-app/myapp
$ mkdir ~/work/test-app/myapp/lib
$ vi ~/work/test-app/myapp/lib/
from datetime import datetime
def now():
$ touch ~/work/test-app/myapp/lib/
$ vi ~/work/test-app/myapp/test_run
#!/usr/bin/env python3
from lib import TM
def main():
    print('Hello, I am main()')
    input("now second is:{}".format(aa))
if __name__ == '__main__':

5. make a snap configuration
$ mkdir ~/work/test-app/snap
$ vi ~/work/test-app/snap/snapcraft.yaml
name:           test-app # package name
version:        '1.1'        # package version
summary:        Example python snap app
description: |
    Example python snap app description
base: core20      # Common Base OS ( 18: ubuntu 18.04, 20: ubuntu 20.04, 22: ubuntu 22.04 )
grade:          stable
confinement:    devmode
  test-app:  #Package name
    command:    myapp/test_run  #running command path and filename (/snap/bin/<package name> will running the command line path file)
    ## If need special path for shell script
    #command: sh $SNAP/opt/foo/bin/
    source: . #my local directory is source
    ## When copy a file(shell/python/built binary file) to somewhere
    plugin:     dump 
          src/myapp: .     # start with "src/" and my files are in the src directory. (copy the myapp directory)
    ## When use python to install application then use python plugin
    #plugin:     python
    #python-version: python3

6. build 
$ cd ~/work/test-app
$ snapcraft

7. Install
$ snap install test-app_1.1_amd64.snap --devmode

8. check 
$ snap list |grep test-app
test-app             1.1                         x1     -                -            devmode
$ df -h
/dev/loop3                 128K  128K     0 100% /snap/test-app/x1
$ ls -l /snap/bin/test-app 
lrwxrwxrwx 1 root root 13 Aug  1 14:18 /snap/bin/test-app -> /usr/bin/snap
$ /snap/bin/test-app 
Hello, I am main()
now second is:1659388777

ETC & Tools)
$ cat 
#!/bin/bash -x
## snapcraft-created multipass VMs
for vm in $(multipass list | awk '{print $1}' | grep "^snapcraft-"); do
    multipass delete $vm --purge
## snapcraft-created LXD containers
#for c in $(lxc list | awk '{print $2}' | grep "^snapcraft-" | grep -v "snapcraft-dev"); do
#    lxc delete $c --force

$ cat 
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"

Remove Package
$ snap remove <package name>
other commands:

Few other snap configuration files example:
a) automatically use bin directory in local directory (Some updated code)
    original :
$ ls                    
bin  LICENSE  myapp_module  mygreatapp_1.0_amd64.snap  requirements.txt  snap
$ cat requirements.txt 
$ cat bin/my_great_app 
#!/usr/bin/env python3
from myapp_module import my_great_app
    my application.
def main():
    """run the application"""
    print('I\'m inside main')
    input("Press enter to exit ;)")
if __name__ == '__main__':
$ ls myapp_module/
$ cat myapp_module/ 
#!/usr/bin/env python3
def tata():
    print ('you could do great stuff inside this function.')
def fun(x):
    return x + 1
$ cat snap/snapcraft.yaml 
name:           mygreatapp
version:        '1.0'
summary:        Example python snap app
description: |
    Example python snap app
base: core18
grade:          stable
confinement:    devmode
    command:    my_great_app
    plugin:     python
    python-version: python3
    source: .

b)  Automatically build and package from remote source file.
$ cat snap/snapcraft.yaml 
name: hello
base: core18
version: '2.10'
summary: GNU Hello, the "hello world" snap
description: |
  GNU hello prints a friendly greeting.
grade: devel
confinement: devmode
    plugin: autotools
2022/08/02 06:32 2022/08/02 06:32