Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python2.7
# Copyright 2013 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Upload files to MAAS.
Pipe or redirect the file to upload to stdin.
This is a workaround while file uploads don't work via maas-cli; see
https://bugs.launchpad.net/maas/+bug/1187826 for details.
@allenap
allenap / gcd.sh
Last active December 30, 2016 07:11
# Bash function to cd to a package on GOPATH (inspiration for that
# from... elsewhere; I can't remember now unfortunately), and bash
# completion for the aforementioned (my own work). Have at it.
# -- Gavin Panella, 2013
gcd() {
local package="$1"
local pdir="$(go list -e -f '{{.Dir}}' "${package}")"
if [ -z "${pdir}" ]
then
@allenap
allenap / gist:8229970
Created January 3, 2014 00:15
Example of aptdaemon not updating dependencies on Saucy. Is this broken behaviour, or are my expectations to blame?
import aptdaemon.client
def printcall(*args, **kwargs):
print("call(*%r, **%r)" % (args, kwargs))
client = aptdaemon.client.AptClient()
# I have make installed, but not abiword.
txn = client.install_packages(["make", "abiword"])
txn.connect("dependencies-changed", printcall)
txn.simulate()
echo 'Defaults !tty_tickets' | sudo tee -a /etc/sudoers.d/no_tty_tickets

How MAAS passes mount options to curtin

In the storage configuration that MAAS passes to curtin it includes stanzas like:

- id: sda-part5_mount
  type: mount
  path: /srv
  options: rw,nosuid,nodev,noexec,relatime

How MAAS describes swap to curtin

Swap is a bit special, and must be special-cased in both MAAS and curtin:

  1. Swap can exist:

    • on a whole disk,
    • on a partition with the type 0x82 ("Linux swap / Solaris"),
  • in a file without holes (created with fallocate or dd for example).
from contextlib import contextmanager
import time
import dns.resolver
from provisioningserver.utils.twisted import retries
def query_soa(zone):
for rdata in dns.resolver.query(zone, "SOA"):
return rdata # Return the first SOA found.
@allenap
allenap / maas-backup-and-restore.md
Last active November 7, 2024 13:31
MAAS: Backup & Restore

Dumping

Use the directory output format because it works better with incremental backups and is most flexible when restoring.

Do not compress because the overwhelming majority of the contents of the MAAS database is already compressed images. For a MAAS installation with one image the saving due to compression was only 1.7% but the dump took noticeably longer. With more images the ratio of already-compressed to not-compressed data goes up, and the savings will likely drop.

import string
import requests
maas_url = "http://maas.server:5240/MAAS/"
api_desc = requests.get(maas_url + "api/2.0/describe/").json()
uri_templates = {h["uri"] for h in api_desc["handlers"]}
@allenap
allenap / bzr-repos-for-fun.md
Last active December 7, 2016 16:03
Bazaar repositories for fun/profit/shenanigans

Bazaar repositories for fun/profit/shenanigans

Starting from scratch

Create a new repository and create a branch within it:

$ bzr init-repo maas
Shared repository with trees (format: 2a)
Location: