ipv4-address-assigned

Example:

# Add a floating IP to a Hetzner cloud VM
- ipv4-address-assigned:
    iface: eth0:1
    ip: 195.201.251.122

Description

Add an IP address to an interface.

This is often relevant for cloud services that offer so-called 'floating' IP addresses. Those are a useful, because you can point a dns record to them, and then easily switch the underlaying virtual machine. Otherwise you'd have to change the dns record, which would mean you'd have to wait for that change to propagate through all the dns layers. That usually takes a few hours, or even a day in some cases.

This frecklet does not check whether the interface was already added at a different location than the value of iface_file_name. Also, this only adds a very basic interface, in the form of:

auto <interface>
iface <interface> inet static
  address <ip>
  netmask 32

Currently this task also restarts the 'networking' service, independent of whether the interface was changed or not.

Variables

Name Type Default Description

ip

string --

The ip to assign. Required

iface

string eth0:1

The name of the network interface.

iface_file_name

string 60-floating-ip.cfg

The name of the interface file under /etc/network/interfaces.d.

Examples

Example 1

Add a floating IP to a Hetzner cloud VM

Code
- ipv4-address-assigned:
    iface: eth0:1
    ip: 195.201.251.122
Description

In our example, we assume we use the Hetzner cloud as they don't add a floating IP to a network interface automatically (like, for example, DigitalOcean does). We create a floating IP address on their web-interface, and a server. Then we assign the floating IP address to our new server, and boot it up. For details on how to do this manually check the Hetzner documentation.

Once this frecklet has run, you should be able to login to your server via the secondary IP address.

Code

doc:
  short_help: Make sure an IPv4 address is assigned to an interface.
  help: |
    Add an IP address to an interface.

    This is often relevant for cloud services that offer so-called 'floating' IP addresses. Those are a useful, because you can point a dns record to them, and then easily switch the underlaying virtual machine. Otherwise you'd have to change the dns record, which would mean you'd have to wait for that change to propagate through all the dns layers. That usually takes a few hours, or even a day in some cases.

    This frecklet does not check whether the interface was already added at a different location than the value of ``iface_file_name``.
    Also, this only adds a very basic interface, in the form of:

    ```
    auto <interface>
    iface <interface> inet static
      address <ip>
      netmask 32
    ```

    Currently this task also restarts the 'networking' service, independent of whether the interface was changed or not.

  examples:
  - title: Add a floating IP to a Hetzner cloud VM
    desc: |
      In our example, we assume we use the [Hetzner cloud](https://hetzner.cloud) as they don't add a floating IP to a network interface automatically (like, for example, DigitalOcean does). We create a floating IP address on their web-interface, and a server. Then we assign the floating IP address to our new server, and boot it up. For details on how to do this manually check the Hetzner documentation.

      Once this frecklet has run, you should be able to login to your server via the secondary IP address.
    vars:
      iface: eth0:1
      ip: 195.201.251.122


args:
  ip:
    doc:
      short_help: The ip to assign.
    type: string
    required: true
  iface:
    doc:
      short_help: The name of the network interface.
    type: string
    default: eth0:1
    required: false
    cli:
      show_default: true
  iface_file_name:
    doc:
      short_help: The name of the interface file under /etc/network/interfaces.d.
    type: string
    default: 60-floating-ip.cfg
    required: false
    cli:
#      enabled: false
      show_default: true

meta:
  tags:
  - networking
  - ip-address
  - cloud
  - floating-ip

frecklets:
- file-with-content:
    path: '/etc/network/interfaces.d/{{:: iface_file_name ::}}'
    owner: root
    group: root
    mode: '0644'
    content: |
      auto {{:: iface ::}}
      iface {{:: iface ::}} inet static
        address {{:: ip ::}}
        netmask 32

- init-service-restarted:
    name: networking
frecklecute ipv4-address-assigned --help

Usage: frecklecute ipv4-address-assigned [OPTIONS]

  Add an IP address to an interface.

  This is often relevant for cloud services that offer so-called 'floating'
  IP addresses. Those are a useful, because you can point a dns record to
  them, and then easily switch the underlaying virtual machine. Otherwise
  you'd have to change the dns record, which would mean you'd have to wait
  for that change to propagate through all the dns layers. That usually
  takes a few hours, or even a day in some cases.

  This frecklet does not check whether the interface was already added at a
  different location than the value of ``iface_file_name``. Also, this only
  adds a very basic interface, in the form of:

  ``` auto <interface> iface <interface> inet static   address <ip>
  netmask 32 ```

  Currently this task also restarts the 'networking' service, independent of
  whether the interface was changed or not.

Options:
  --ip IP                         The ip to assign.  [required]
  --iface IFACE                   The name of the network interface.
  --iface-file-name IFACE_FILE_NAME
                                  The name of the interface file under
                                  /etc/network/interfaces.d.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.ipv4_address_assigned.Ipv4AddressAssigned
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class Ipv4AddressAssigned(AutoPycklet):
    """Add an IP address to an interface.

     This is often relevant for cloud services that offer so-called 'floating' IP addresses. Those are a useful, because you can point a dns record to them, and then easily switch the underlaying virtual machine. Otherwise you'd have to change the dns record, which would mean you'd have to wait for that change to propagate through all the dns layers. That usually takes a few hours, or even a day in some cases.

     This frecklet does not check whether the interface was already added at a different location than the value of ``iface_file_name``.
     Also, this only adds a very basic interface, in the form of:

     ```
     auto <interface>
     iface <interface> inet static
       address <ip>
       netmask 32
     ```

     Currently this task also restarts the 'networking' service, independent of whether the interface was changed or not.

       Args:
         iface: The name of the network interface.
         iface_file_name: The name of the interface file under /etc/network/interfaces.d.
         ip: The ip to assign.

    """

    FRECKLET_ID = "ipv4-address-assigned"

    iface: str = None
    iface_file_name: str = None
    ip: str = None


    def __post_init__(self):
        super(Ipv4AddressAssigned, self).__init__(var_names=["iface", "iface_file_name", "ip"])


frecklet_class = Ipv4AddressAssigned
# -*- coding: utf-8 -*-


#
# module path: pycklets.ipv4_address_assigned.Ipv4AddressAssigned
#


from pyckles import AutoPycklet

class Ipv4AddressAssigned(AutoPycklet):
    """Add an IP address to an interface.

     This is often relevant for cloud services that offer so-called 'floating' IP addresses. Those are a useful, because you can point a dns record to them, and then easily switch the underlaying virtual machine. Otherwise you'd have to change the dns record, which would mean you'd have to wait for that change to propagate through all the dns layers. That usually takes a few hours, or even a day in some cases.

     This frecklet does not check whether the interface was already added at a different location than the value of ``iface_file_name``.
     Also, this only adds a very basic interface, in the form of:

     ```
     auto <interface>
     iface <interface> inet static
       address <ip>
       netmask 32
     ```

     Currently this task also restarts the 'networking' service, independent of whether the interface was changed or not.

       Args:
         iface: The name of the network interface.
         iface_file_name: The name of the interface file under /etc/network/interfaces.d.
         ip: The ip to assign.

    """

    FRECKLET_ID = "ipv4-address-assigned"

    def __init__(self, iface="eth0:1", iface_file_name="60-floating-ip.cfg", ip=None):

        super(Ipv4AddressAssigned, self).__init__(var_names=["iface", "iface_file_name", "ip"])
        self._iface = iface
        self._iface_file_name = iface_file_name
        self._ip = ip

    @property
    def iface(self):
        return self._iface

    @iface.setter
    def iface(self, iface):
        self._iface = iface

    @property
    def iface_file_name(self):
        return self._iface_file_name

    @iface_file_name.setter
    def iface_file_name(self, iface_file_name):
        self._iface_file_name = iface_file_name

    @property
    def ip(self):
        return self._ip

    @ip.setter
    def ip(self, ip):
        self._ip = ip



frecklet_class = Ipv4AddressAssigned