diff --git a/nix/packet.nix b/nix/packet.nix index 9992d58..3f3bb24 100644 --- a/nix/packet.nix +++ b/nix/packet.nix @@ -14,15 +14,15 @@ in accessKeyId = mkOption { example = "YOURAPIKEY"; type = types.str; - # FIXME: describe this correctly description = '' + packet.net access key ID ''; }; facility = mkOption { - example = "something"; + example = "any"; type = types.str; - # FIXME: describe this correctly description = '' + packet.net facility ''; }; keyPair = mkOption { @@ -35,20 +35,22 @@ in ''; }; plan = mkOption { - example = "something"; + example = "c1.small.x86"; type = types.str; description = '' + the instance type to launch ''; }; project = mkOption { example = "something"; type = types.str; description = '' + the project the instance will be launched under ''; }; nixosVersion = mkOption { - example = "nixos_19_03"; - default = "nixos_19_03"; + example = "nixos_19_09"; + default = "nixos_19_09"; type = types.str; description = '' NixOS version to install @@ -96,6 +98,13 @@ in characters. There can be at most 10 tags. ''; }; + customData = mkOption { + default = null; + type = types.nullOr types.attrs; + description = '' + customData passed to packet API (e.g. CPR partitioning instructions) + ''; + }; }; }; diff --git a/nixopspacket/backends/device.py b/nixopspacket/backends/device.py index ff0c477..49d7b5f 100644 --- a/nixopspacket/backends/device.py +++ b/nixopspacket/backends/device.py @@ -35,7 +35,7 @@ def __init__(self, xml, config): self.project = config["packet"]["project"] self.nixosVersion = config["packet"]["nixosVersion"] self.ipxe_script_url = config["packet"]["ipxeScriptUrl"]; - #self.customdata = config["packet"]["customdata"]; + self.customData = config["packet"]["customData"]; self.always_pxe = config["packet"]["alwaysPxe"]; self.spotInstance = config["packet"]["spotInstance"] self.spotPriceMax = config["packet"]["spotPriceMax"] @@ -132,246 +132,10 @@ def sos_console(self): allow_ssh_args=True, user=user)) def get_physical_spec_from_plan(self, public_key): - if self.plan == "c1.small.x86": - return { - 'config': { ('users', 'extraUsers', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key] }, - 'imports': [ nix2py(self.provSystem) ], - } - - #return Function("{ ... }", { - # ('config', 'boot', 'initrd', 'availableKernelModules'): [ "ata_piix", "uhci_hcd", "virtio_pci", "sr_mod", "virtio_blk" ], - # ('config', 'boot', 'loader', 'grub', 'devices'): [ '/dev/sda', '/dev/sdb' ], - # ('config', 'fileSystems', '/'): { 'label': 'nixos', 'fsType': 'ext4'}, - # ('config', 'users', 'users', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key], - # ('config', 'networking', 'bonds', 'bond0', 'interfaces'): json.loads(self.iflist), - # ('config', 'networking', 'interfaces', 'bond0', 'macAddress'): self.ifmac, - # ('config', 'boot', 'kernelParams'): [ "console=ttyS1,115200n8" ], - # ('config', 'boot', 'loader', 'grub', 'extraConfig'): """ - # serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 - # terminal_output serial console - # terminal_input serial console - # """, - # ('config', 'networking', 'bonds', 'bond0', 'driverOptions'): { - # "mode": "802.3ad", - # "xmit_hash_policy": "layer3+4", - # "lacp_rate": "fast", - # "downdelay": "200", - # "miimon": "100", - # "updelay": "200", - # }, - # ('config', 'networking', 'nameservers'): [ "8.8.8.8", "8.8.4.4" ], # TODO - # ('config', 'networking', 'defaultGateway'): { - # "address": self.default_gateway, - # "interface": "bond0", - # }, - # ('config', 'networking', 'defaultGateway6'): { - # "address": self.default_gatewayv6, - # "interface": "bond0", - # }, - # ('config', 'networking', 'dhcpcd', 'enable'): False, - # ('config', 'networking', 'interfaces', 'bond0'): { - # "useDHCP": False, - # "ipv4": { - # "addresses": [ - # { "address": self.public_ipv4, "prefixLength": self.public_cidr }, - # { "address": self.private_ipv4, "prefixLength": self.private_cidr }, - # ], - # "routes": [ - # { - # "address": "10.0.0.0", - # "prefixLength": 8, - # "via": self.private_gateway, - # }, - # ], - # }, - # "ipv6": { - # "addresses": [ - # { "address": self.public_ipv6, "prefixLength": self.public_cidrv6 }, - # ], - # }, - # }, - #}) - elif self.plan == "t1.small.x86": - return Function("{ ... }", { - ('config', 'boot', 'initrd', 'availableKernelModules'): [ "ehci_pci", "ahci", "usbhid", "sd_mod" ], - ('config', 'boot', 'loader', 'grub', 'devices'): [ '/dev/sda' ], - ('config', 'fileSystems', '/'): { 'label': 'nixos', 'fsType': 'ext4'}, - ('config', 'users', 'users', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key], - ('config', 'networking', 'bonds', 'bond0', 'interfaces'): json.loads(self.iflist), - ('config', 'boot', 'kernelParams'): [ "console=ttyS1,115200n8" ], - ('config', 'boot', 'loader', 'grub', 'extraConfig'): """ - serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 - terminal_output serial console - terminal_input serial console - """, - ('config', 'networking', 'bonds', 'bond0', 'driverOptions'): { - "mode": "balance-tlb", - "xmit_hash_policy": "layer3+4", - "miimon": "100", - "downdelay": "200", - "updelay": "200", - }, - ('config', 'networking', 'nameservers'): [ "8.8.8.8", "8.8.4.4" ], # TODO - ('config', 'networking', 'defaultGateway'): { - "address": self.default_gateway, - "interface": "bond0", - }, - ('config', 'networking', 'defaultGateway6'): { - "address": self.default_gatewayv6, - "interface": "bond0", - }, - ('config', 'networking', 'dhcpcd', 'enable'): False, - ('config', 'networking', 'interfaces', 'bond0'): { - "useDHCP": False, - "ipv4": { - "addresses": [ - { "address": self.public_ipv4, "prefixLength": self.public_cidr }, - { "address": self.private_ipv4, "prefixLength": self.private_cidr }, - ], - "routes": [ - { - "address": "10.0.0.0", - "prefixLength": 8, - "via": self.private_gateway, - }, - ], - - }, - "ipv6": { - "addresses": [ - { "address": self.public_ipv6, "prefixLength": self.public_cidrv6 }, - ], - }, - }, - - }) - elif self.plan == "c2.medium.x86": - return Function("{ ... }", { - ('config', 'boot', 'initrd', 'availableKernelModules'): [ "xhci_pci", "ahci", "mpt3sas", "sd_mod" ], - ('config', 'boot', 'kernelModules'): [ "kvm-amd", "dm_multipath", "dm_round_robin", "ipmi_watchdog" ], - ('config', 'boot', 'kernelParams'): [ "console=ttyS1,115200n8" ], - ('config', 'boot', 'loader', 'efi', 'efiSysMountPoint'): "/boot/efi", - ('config', 'boot', 'loader', 'efi', 'canTouchEfiVariables'): False, - ('config', 'boot', 'loader', 'grub', 'enable'): True, - ('config', 'boot', 'loader', 'grub', 'version'): 2, - ('config', 'boot', 'loader', 'grub', 'efiSupport'): True, - ('config', 'boot', 'loader', 'grub', 'device'): "nodev", - ('config', 'boot', 'loader', 'grub', 'efiInstallAsRemovable'): True, - ('config', 'boot', 'loader', 'grub', 'extraConfig'): """ - serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 - terminal_output serial console - terminal_input serial console - """, - ('config', 'boot', 'loader', 'systemd-boot', 'enable'): False, - ('config', 'fileSystems', '/'): { "label": "nixos", "fsType": "ext4" }, - ('config', 'fileSystems', '/boot/efi'): { "device": "{}".format(self.efiBootDev), "fsType": "vfat" }, - ('config', 'hardware', 'enableAllFirmware'): True, - ('config', 'networking', 'bonds', 'bond0', 'interfaces'): json.loads(self.iflist), - ('config', 'networking', 'bonds', 'bond0', 'driverOptions'): { - "mode": "802.3ad", - "xmit_hash_policy": "layer3+4", - "lacp_rate": "fast", - "downdelay": "200", - "miimon": "100", - "updelay": "200", - }, - ('config', 'networking', 'defaultGateway'): { - "address": self.default_gateway, - "interface": "bond0", - }, - ('config', 'networking', 'defaultGateway6'): { - "address": self.default_gatewayv6, - "interface": "bond0", - }, - ('config', 'networking', 'dhcpcd', 'enable'): False, - ('config', 'networking', 'interfaces', 'bond0'): { - "useDHCP": False, - "ipv4": { - "addresses": [ - { "address": self.public_ipv4, "prefixLength": self.public_cidr }, - { "address": self.private_ipv4, "prefixLength": self.private_cidr }, - ], - "routes": [ - { - "address": "10.0.0.0", - "prefixLength": 8, - "via": self.private_gateway, - }, - ], - - }, - "ipv6": { - "addresses": [ - { "address": self.public_ipv6, "prefixLength": self.public_cidrv6 }, - ], - }, - }, - ('config', 'networking', 'nameservers'): [ "8.8.8.8", "8.8.4.4" ], # TODO - ('config', 'nixpkgs', 'config', 'allowUnfree'): True, - ('config', 'swapDevices'): [ { "label": "swap" } ], - ('config', 'users', 'users', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key], - }) - elif self.plan == "g2.large.x86": - return Function("{ ... }", { - ('config', 'boot', 'initrd', 'availableKernelModules'): [ "ata_piix", "uhci_hcd", "virtio_pci", "sr_mod", "virtio_blk" ], - ('config', 'boot', 'loader', 'grub', 'devices'): [ '/dev/sda' ], - ('config', 'fileSystems', '/'): { 'label': 'nixos', 'fsType': 'ext4'}, - ('config', 'users', 'users', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key], - ('config', 'networking', 'bonds', 'bond0', 'interfaces'): json.loads(self.iflist), - ('config', 'boot', 'kernelParams'): [ "console=ttyS1,115200n8" ], - ('config', 'boot', 'kernelModules'): [ 'kvm-intel' ], - ('config', 'boot', 'loader', 'grub', 'extraConfig'): """ - serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 - terminal_output serial console - terminal_input serial console - """, - ('config', 'networking', 'bonds', 'bond0', 'driverOptions'): { - "mode": "802.3ad", - "xmit_hash_policy": "layer3+4", - "lacp_rate": "fast", - "downdelay": "200", - "miimon": "100", - "updelay": "200", - }, - ('config', 'networking', 'nameservers'): [ "8.8.8.8", "8.8.4.4" ], # TODO - ('config', 'networking', 'defaultGateway'): { - "address": self.default_gateway, - "interface": "bond0", - }, - ('config', 'networking', 'defaultGateway6'): { - "address": self.default_gatewayv6, - "interface": "bond0", - }, - ('config', 'networking', 'dhcpcd', 'enable'): False, - ('config', 'networking', 'interfaces', 'bond0'): { - "useDHCP": False, - "ipv4": { - "addresses": [ - { "address": self.public_ipv4, "prefixLength": self.public_cidr }, - { "address": self.private_ipv4, "prefixLength": self.private_cidr }, - ], - "routes": [ - { - "address": "10.0.0.0", - "prefixLength": 8, - "via": self.private_gateway, - }, - ], - - }, - "ipv6": { - "addresses": [ - { "address": self.public_ipv6, "prefixLength": self.public_cidrv6 }, - ], - }, - }, - - }) - elif self.plan == None: - return Function("{ ... }", { - ('config', 'boot', 'loader', 'grub', 'devices'): [ 'nodev' ], - ('config', 'fileSystems', '/'): { 'label': 'nixos', 'fsType': 'ext4'}, - }) + return { + 'config': { ('users', 'extraUsers', 'root', 'openssh', 'authorizedKeys', 'keys'): [public_key] }, + 'imports': [ nix2py(self.provSystem) ], + } def get_physical_spec(self): if self.key_pair == None and self.plan != None: @@ -562,6 +326,7 @@ def create_device(self, defn, check, allow_reboot, allow_recreate): project_ssh_keys = [ kp.keypair_id ], hardware_reservation_id = defn.reservationId, spot_instance = defn.spotInstance, + customdata = defn.customData, spot_price_max = defn.spotPriceMax, tags = packet_utils.dict2tags(tags), ipxe_script_url = defn.ipxe_script_url, diff --git a/release.nix b/release.nix index 48c619c..e48ca04 100644 --- a/release.nix +++ b/release.nix @@ -10,10 +10,8 @@ let src = pkgs.fetchFromGitHub { owner = "input-output-hk"; repo = "packet-python"; - rev = "4d351e2bb61d4f39cacb108952fec70a903ef7e1"; - sha256 = "1f0wswmqcv4lqgprdh801jn50fybqvizpd3302saixl24alz067d"; - #rev = "67eebaed55a1a199fdb64e6cd9bb75a70de6e745"; - #sha256 = "1l6cs6hp94by6ajc72sg5b2fyv62frdjn0g106656jd87ympxraz"; + rev = "0aa7e7e9a7009b89d09f2dfa8d32a222d89bb829"; + sha256 = "15z869idd3h399grq61ssn0xhs24zhy7x4i63yg8xlhvar7mgvls"; }; patches = []; buildInputs = old.buildInputs ++ [ pkgs.python2Packages.pytestrunner ];