cmprovision icon indicating copy to clipboard operation
cmprovision copied to clipboard

Set Hostname after Image apply and print on Lable

Open maikschauer opened this issue 1 year ago • 1 comments

Hello, if I set the host name after writing the image via postscript, I would like to print the new host name on the label. is that possible?

maikschauer avatar Mar 01 '24 10:03 maikschauer

That would be something you would need to develop yourself. One way is patch our printing code directly. Another way, would be if you want your changes to survive our future updates, is to write your own custom print label code, that only listen to the CmProvisioningComplete event cmprovision generates, and consult your own database for additional information that should be printed on the label based on serial number or other properties of the CM.

As in create /var/lib/cmprovision/app/Listeners/CustomPrintCode.php

<?php
namespace App\Listeners;

use App\Events\CmProvisioningComplete;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Http;
use App\Models\Cm;
use App\Models\Setting;

class CustomPrintCode implements ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  App\Events\CmProvisioningComplete  $event
     * @return void
     */
    public function handle(CmProvisioningComplete $event)
    {
        $cm = $event->cm;

        /* $cm contains information about the compute module that just finished provisioning
           Do something useful with it here. */  
    }
}

This way you only need to ADD a single file to cmprovision, and do not have to modify existing code. Less work to merge changes on updates.

maxnet avatar Mar 01 '24 12:03 maxnet