• Register
    • Login
    • Search
    • Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Solved How to delete a MAC address from a Host

    FOG Problems
    fogapi-psmodule
    4
    7
    48
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      ajm2358 last edited by JJ Fullmer

      I have a pending MAC address associated with the Host that uses/deploys our image. I need to delete the pending MAC address from it so I can register the computer as a new host. How do I go about doing that?

      JJ Fullmer 1 Reply Last reply Reply Quote 0
      • Topic has been marked as solved  S Sebastian Roth 
      • JJ Fullmer
        JJ Fullmer Testers @ajm2358 last edited by JJ Fullmer

        @ajm2358 Is this a usb mac (or macs) that you use on devices that don’t have built-in lan?

        I have a powershell method for doing this via the api, but the full solution requires some infrastructure work to store the defined macs used for imaging somewhere you can get them. I embed them in an internal powershell module I use for provisioning. You may really just need one or 2 functions from this example and I also haven’t tested it working just copy paste. You would for sure need to install the module and connect to the api first. I took this from my module but I believe it should work once you have the module installed, imported, and connected.

        After a computer finishes imaging and provisioning, my last step is uses the powershell fogapi module (see the links in my signature for info on the module) to run

        $usbmacs = [pscustomobject]@{
          mac = "00:00:00:00:00";
          description = "mac description, I have these defined in a json, this is an inline example";
        }
        
        $result = Remove-UsbMac -usbMacs.mac  -hostname ($ENV:COMPUTERNAME);
        

        Then I make sure all the macs that are valid are present

        $physicalMacs = (get-netadapter | select-object -expand macaddress).replace("-",":")
                            $fogHost = (Get-FogHost -hostName $ENV:COMPUTERNAME) 
                            $hostID = ($fogHost.id);
                            $pendingFogmacs = Get-FogHostPendingMacs -hostID $hostID;
                            $pendingFogmacs | ForEach-Object {
                                $pendingMac = $_;
                                if ($usbMacs.mac -notcontains $pendingMac.mac) {
                                    "Mac $pendingMac is pending and is not usbmac" | Out-Host;
                                    if ($physicalMacs -contains $pendingMac) {
                                        "Mac $($pendingMac.mac) is attached to this device, approving" | Out-Host;
                                        Approve-FogPendingMac -macObject $pendingMac;
                                    } else {
                                        if ($pendingMac.hostID -eq $hostID) {
                                            "Mac $($pendingMac.mac) is not attached to this device, removing it from Fog" | Out-Host
                                            Deny-FogPendingMac -macObject $pendingMac;
                                        }
                                    }
                                } else {
                                    "Mac $($pendingMac.mac) is a usbmac, removing it from Fog" | Out-Host
                                    Deny-FogPendingMac -macObject $pendingMac;
                                }
                            }
                            $fogMacs = Get-FogMacAddresses;
                            $physicalMacs | ForEach-Object {
                                $mac = $_;
                                $fogMac = $fogmacs | Where-Object mac -eq $mac;
                                if ($null -eq $fogMac) {
                                    if ($mac -notin $usbMacs.mac) {
                                        "$mac doesn't exist in fog, adding it for the host" | Out-Host;
                                        try {
                                            Add-FogHostMac -hostID $hostID -macAddress $_ -forceUpdate;
                                        } catch {
                                            Write-Warning "secondary mac address $($_) failed to add to host"
                                        }
                                    } else {
                                        "Usb mac $mac is attached, remove usb mac after provisioning!" | out-host;
                                    }
                                } else {
                                    $otherHost = Get-FogHost -hostid $fogmac.hostId
                                    "Mac address $mac is already assigned to or pending for a different host, $($otherhost.name)" | out-host;
                                }
                            }
        

        Then I make sure I didn’t break the host on accident during that by unintentionally deleting all the macs

        try {
                                $hostObj = (Get-FogHost -hostName $ENV:COMPUTERNAME)
                                if (!$hostObj) {
                                    throw "host not found by name, trying by active mac instead"
                                }
                            } catch {
                                $mac = get-activeMacAddress;
                                $hostObj = Get-FogHost -macAddr $mac;
                            }
        
                            if ($hostObj.pending -ne '0') {
                                Write-Verbose "The host is pending or not explicitly set to not pending in fog, adjust host to be approved be setting pending to '0'";
                                try {
                                    Reset-HostEncryption -fogHost $hostObj;
                                    $hostObj.pending = "0";
                                    $jsonData = $hostObj | Select-Object id,pending | ConvertTo-Json;
                                    Update-FogObject -type object -coreObject host -IDofObject $hostObj.id -jsonData $jsonData;
                                    Restart-Service FOGService;
                                } catch {
                                    Write-Verbose "There was an issue resetting host encryption or when running set-fogou -force. Host id is $($hostObj.id)"
                                }
                            }
        

        TL;DR

        Take a look at the Fog API Powershell Module especially the Remove-USBMac function and the Deny-FogPendingMac function. You can also use the above example for a more robust solution. The above solution also assumes its being run from the host in question, you can also manage any host remotely through the api.

        Have you tried the FogApi powershell module? It's pretty cool IMHO
        https://github.com/darksidemilk/FogApi
        https://fogapi.readthedocs.io/en/latest/
        https://www.powershellgallery.com/packages/FogApi
        https://forums.fogproject.org/topic/12026/powershell-api-module

        1 Reply Last reply Reply Quote 0
        • S
          Sebastian Roth Moderator last edited by

          @ajm2358 said in How to delete a MAC address from a Host:

          essentially I want to remove a pending Mac(s) from our host that deploys our image from the Fog server without deleting or removing that host or primary Mac.

          Now that I think about it again, can’t you just click the check mark symbol on the right of that MAC address to approve it and make it appear in the list of secondary MACs for this host and then there should be a button to delete that MAC straight away.

          If that doesn’t work you need to connect to the FOG server database and take a look at the hostMAC table. You should find the MAC(s) mentioned and can delete those rows.

          Make sure you have a backup of the whole DB before messing with it and also I suggest you pay attention when deleting rows to match not just the MAC address field but also the host ID to make sure it’s the right entry you are going to delete.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          1 Reply Last reply Reply Quote 0
          • A
            ajm2358 @ajm2358 last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • Tom Elliott
              Tom Elliott @ajm2358 last edited by

              @ajm2358 This is just the thing that tells you it’s Apple, or Realtek. This doesn’t delete the mac addresses at all. Just the “reference” of who mad a specific device.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

              Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

              Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

              1 Reply Last reply Reply Quote 0
              • A
                ajm2358 @Sebastian Roth last edited by ajm2358

                @Sebastian-Roth Thank you for the response, essentially I want to remove a pending Mac(s) from our host that deploys our image from the Fog server without deleting or removing that host or primary Mac. I highlighted the specific Mac that I want to remove but if I can remove all of them, that would great.
                Fog server.PNG

                I’m also curious what this does as well, does this delete all Mac address’s including the primary?
                Delete Fog.PNG

                Thank you!

                Tom Elliott A 2 Replies Last reply Reply Quote 0
                • S
                  Sebastian Roth Moderator last edited by

                  @ajm2358 You can delete entries from the DB manually though I am not sure this is what you ask.

                  Can you explain in more detail which host this MAC is associated to and why you want to remove it?

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  A 1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post

                  61
                  Online

                  10.4k
                  Users

                  16.4k
                  Topics

                  150.7k
                  Posts

                  Copyright © 2012-2023 FOG Project