working on it ...

Filters

Explore Public Snippets

Sort by

Found 104 snippets matching: linode

    public by azazqadir modified Dec 15, 2017  455  1  5  -1

    Installing PHP Website on Linode Server

    Here is how you can easily host a PHP based website easily and quickly on Linode using Cloudways PaaS: https://www.cloudways.com/blog/host-php-on-linode/
    <?php
    echo rand() . "\n";
    echo rand() . "\n";
    
    echo rand(5, 15);
    ?>

    external by ihashacks modified Feb 12, 2014  284  0  3  0

    switches a Linode guest to use Linode's repository mirrors

    switches a Linode guest to use Linode's repository mirrors: linode-mirror-switch
    #!/bin/bash
    
    ################################################################################
    #   License
    ################################################################################
    #
    #   Copyright (c) 2014 Brandon Pierce <brandon@ihashacks.com>
    #
    #   This program is free software: you can redistribute it and/or modify
    #   it under the terms of the GNU General Public License as published by
    #   the Free Software Foundation, either version 3 of the License, or
    #   (at your option) any later version.
    #
    #   This program is distributed in the hope that it will be useful,
    #   but WITHOUT ANY WARRANTY; without even the implied warranty of
    #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #   GNU General Public License for more details.
    #
    #   You should have received a copy of the GNU General Public License
    #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    
    ################################################################################
    #   Description
    ################################################################################
    #
    #	switches a Linode guest to use Linode's repository mirrors
    #
    
    PATHBKUP=/tmp
    MSGBKUP="backing up original repository files to $PATHBKUP"
    # test the distro and act accordingly
    if lsb_release -i | grep Ubuntu > /dev/null; then
    	# Ubuntu
    	echo $MSGBKUP
    	cp /etc/apt/sources.list $PATHBKUP
    	sed -i '/^deb/s/\(us.archive\|security\).ubuntu.com/mirrors.linode.com/g' /etc/apt/sources.list
    elif [ -e /etc/debian_version ]; then
    	# Debian
    	echo $MSGBKUP
    	cp /etc/apt/sources.list 
    	sed -i '/^deb/s/\(\(us\|security\|cdn\).debian.\(org\|net\)\)/mirrors.linode.com/g' /etc/apt/sources.list
    elif [ -e /etc/redhat-release ]; then
    	# CentOS
    	echo $MSGBKUP
    	cp /etc/yum/pluginconf.d/fastestmirror.conf $PATHBKUP
    	cp /etc/yum.repos.d/CentOS-Base.repo $PATHBKUP
    	sed -i '/^enabled/s/1/0/' /etc/yum/pluginconf.d/fastestmirror.conf
    	sed -i '/^mirrorlist/s/^/#/' /etc/yum.repos.d/CentOS-Base.repo
    	sed -i '/^#baseurl/s/#//' /etc/yum.repos.d/CentOS-Base.repo
    	sed -i '/^baseurl/s/mirror.centos.org/mirrors.linode.com/' /etc/yum.repos.d/CentOS-Base.repo
    else
    	# something else
    	echo "Unable to determine distribution or unsupported distribution"
    	exit 1
    fi
    
    
    

    external by Marco Damaceno modified Sep 4, 2015  93  0  1  0

    Linode script to register nginx after passenger install http://library.linode.com/assets/660-init-deb.sh

    Linode script to register nginx after passenger install http://library.linode.com/assets/660-init-deb.sh: 660-init-deb.sh
    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          nginx
    # Required-Start:    $all
    # Required-Stop:     $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the nginx web server
    # Description:       starts nginx using start-stop-daemon
    ### END INIT INFO
    
    PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/opt/nginx/sbin/nginx
    NAME=nginx
    DESC=nginx
    
    test -x $DAEMON || exit 0
    
    # Include nginx defaults if available
    if [ -f /etc/default/nginx ] ; then
            . /etc/default/nginx
    fi
    
    set -e
    
    case "$1" in
      start)
            echo -n "Starting $DESC: "
            start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                    --exec $DAEMON -- $DAEMON_OPTS
            echo "$NAME."
            ;;
      stop)
            echo -n "Stopping $DESC: "
            start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                    --exec $DAEMON
            echo "$NAME."
            ;;
      restart|force-reload)
            echo -n "Restarting $DESC: "
            start-stop-daemon --stop --quiet --pidfile \
                    /opt/nginx/logs/$NAME.pid --exec $DAEMON
            sleep 1
            start-stop-daemon --start --quiet --pidfile \
                    /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
            echo "$NAME."
            ;;
      reload)
              echo -n "Reloading $DESC configuration: "
              start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
                  --exec $DAEMON
              echo "$NAME."
              ;;
          *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
                exit 1
                ;;
        esac
    
        exit 0
    
    
    

    external by Cyril Hou modified Jan 11, 2016  82  0  1  0

    Linode Cost Calculator : open https://manager.linode.com/account/billing_history/ then eval code in Web Developer Tool.

    Linode Cost Calculator : open https://manager.linode.com/account/billing_history/ then eval code in Web Developer Tool. : LinodeCost.js
    // Open https://manager.linode.com/account/billing_history/  then run below code in Web Developer Tool. 
    var a = document.querySelectorAll("tbody tr td:last-child");
    
    window.c = 0;
    
    for(i = 0; i< a.length; i++) {
      if(a[i].textContent[0] == "("){
        var d = a[i].textContent.replace(/[\s\(\)\$]/g, "");
        if(d.length > 0){window.c += parseInt(d);}
      }
    }
    
    console.log("您总共花了: $ %d (结果仅供参考)", window.c);
    
    

    external by Vicen Dominguez modified Apr 25, 2015  182  0  2  0

    Ansible Linode template (tested and working)

    Ansible Linode template (tested and working): linode-template.yml
    #### CentOS: yum install pip ; pip install linode-python ; pip install chube
    #### 
    
    - hosts: localhost
      connection: local
      gather_facts: false
      tasks:
      - name: Create linode server
        linode: 
          api_key: '---KEY HERE---'
          name: linodeserver
          plan: 1                   #cheapest
          datacenter: 6             #newmark NJ
          distribution: 127         #centos 6.5
          password: '-AUX-PASSWORD-HERE'
          ssh_pub_key: 'ssh-rsa AAAAB3NzaC----RSA HERE-----'
          wait: yes
          wait_timeout: 300
          state: present
        register: linode
    
      - name: Adding the new box to the dynamic inventory
        add_host: hostname="{{ linode.instance.ipv4  }}" groupname=linodehosts
    
      - name: Wait for SSH to come up
        local_action: wait_for host="{{ linode.instance.ipv4 }}" port=22 delay=60 timeout=320 state=started
    
    - name: Cooking the instance....
      hosts: linodehosts
      user: root
      gather_facts: true
      roles:
        - base
    
    

    external by Gasol modified Apr 28, 2015  114  0  2  0

    linode speedtest from 203.69.67.253

    linode speedtest from 203.69.67.253: gistfile1.txt
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.singapore.linode.com/100MB-singapore.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0  1245k      0  0:01:22  0:01:22 --:--:-- 2168k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.tokyo.linode.com/100MB-tokyo.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0  2468k      0  0:00:41  0:00:41 --:--:-- 3879k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.fremont.linode.com/100MB-fremont.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0   921k      0  0:01:51  0:01:51 --:--:--  591k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.newark.linode.com/100MB-newark.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0   424k      0  0:04:01  0:04:01 --:--:--  446k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.atlanta.linode.com/100MB-atlanta.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0   634k      0  0:02:41  0:02:41 --:--:-- 1070k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.dallas.linode.com/100MB-dallas.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0   511k      0  0:03:20  0:03:20 --:--:--  517k
    [Gasols-MacBook-Pro.local ~/Downloads]$ curl -O http://speedtest.london.linode.com/100MB-london.bin
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  100M  100  100M    0     0   402k      0  0:04:14  0:04:14 --:--:--  554k
    
    

    external by joesavage modified Jul 20, 2014  91  1  1  0

    Linode Rescue Mode Disk Backup

    Linode Rescue Mode Disk Backup: gistfile1.sh
    ## Linode Rescue Mode Disk Backup
    
    # Remote:
    dd if=/dev/xvda | gzip -c > linode.img.gz
    passwd
    /etc/init.d/ssh start
    
    # Local:
    ssh root@remote-location "dd if=~/linode.img.gz " | dd of=~/Developer/Backups/Images/linode.img.gz
    
    

    external by Chang-Hung Liang modified Sep 4, 2014  91  0  1  0

    Basic security setup for a brand new Linode

    Basic security setup for a brand new Linode: linode-security.md
    # Basic Security Setup for a Brand New Linode
    
    ## Why
    
    When you start a clean Linode, it isn't secured in the following aspects:
    
    * Allows root SSH login
    * Uses password authentication on SSH
    * Doesn't have a firewall
    
    I collected some information to this article to address these three issues.
    
    ## Target Operating System
    
    I assume you're using Ubuntu 14.04 LTS.
    
    ## Disabling Root SSH Login and Password Authentication
    
    Edit `/etc/ssh/sshd_config` and set the following settings:
    
    ```
    PasswordAuthentication no
    PermitRootLogin no
    ```
    
    Restart SSH service:
    
    ```
    sudo service ssh restart
    ```
    
    ## Creating New User
    
    Now you can't log in with root, so you need to create another user:
    
    ```
    sudo adduser myuser
    ```
    
    To make `myuser` a sudoer, enter `sudo visudo` and add this line at the bottom:
    
    ```
    myuser ALL=(ALL) NOPASSWD:ALL
    ```
    
    The above line let you sudo without a password. If you prefer having a password when sudoing, use this line instead:
    
    ```
    myuser ALL=(ALL:ALL) ALL
    ```
    
    Log in as `myuser` and generate an SSH key:
    
    ```
    ssh-keygen
    ```
    
    To allow you to log in using `myuser` with public key authentication, add your client public key into `~/.ssh/authorized_keys`.
    
    Make sure `authorized_keys` has the right permissions:
    
    ```
    chmod 600 ~/.ssh/authorized_keys
    ```
    
    Then you can try logging in to the Linode from your local computer:
    
    ```
    ssh myuser@your-linode-ip-or-domain-name
    ```
    
    ## Setting up iptables
    
    By default, Linode accepts all incoming connections. It is better to set up some iptables rules to block unwanted connections.
    
    Create `/etc/network/if-pre-up.d/iptables` and put the content in it:
    
    ```
    #!/bin/sh
    
    # Reset iptables rules
    iptables -F
    
    iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    
    # Web
    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    
    # Allow all traffic from localhost
    iptables -A INPUT -s 127.0.0.1 -p tcp -j ACCEPT
    
    # SSH
    iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    
    # Drop all others
    iptables -A INPUT -j DROP
    ```
    
    This is a typical setup of a web server. Adjust it if needed.
    
    Reboot your Linode to take effect.
    
    ## References
    
    * https://www.digitalocean.com/community/tutorials/how-to-add-and-delete-users-on-an-ubuntu-14-04-vps
    * https://www.linode.com/docs/security/securing-your-server
    
    
    

    external by vivianspencer modified Feb 20, 2015  80  0  1  0

    Server setup - Linode, Debian, Apache, PHP, MariaDB

    Server setup - Linode, Debian, Apache, PHP, MariaDB: server_setup.md
    sudo echo "johnsmith" > /etc/hostname
    
    sudo hostname -F /etc/hostname
    
    sudo nano /etc/hosts
    
    ```
    127.0.0.1       localhost.localdomain localhost 
    12.34.56.78     johnsmith.example.com johnsmith 
    2600:3c01::a123:b456:c789:d012      johnsmith.example.com johnsmith
    ```
    
    sudo dpkg-reconfigure tzdata
    
    date
    
    sudo nano /etc/apt/sources.list
    
    ```
    deb http://mirrors.linode.com/debian/ wheezy main contrib non-free
    deb-src http://mirrors.linode.com/debian/ wheezy main contrib non-free
    
    deb http://mirrors.linode.com/debian-security/ wheezy/updates main contrib non-free
    deb-src http://mirrors.linode.com/debian-security/ wheezy/updates main contrib non-free
    
    # wheezy-updates, previously known as 'volatile'
    deb http://mirrors.linode.com/debian/ wheezy-updates main
    deb-src http://mirrors.linode.com/debian/ wheezy-updates main
    ```
    
    sudo apt-get update && sudo apt-get upgrade --show-upgraded
    
    sudo apt-get install python-software-properties
    
    sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
    
    sudo add-apt-repository 'deb http://mirrors.coreix.net/mariadb/repo/10.0/debian wheezy main'
    
    sudo apt-get update && sudo apt-get upgrade --show-upgraded
    
    sudo apt-get install git fail2ban apache2 apache2-doc apache2-utils php5 php-apc php5-curl php5-gd php5-cli libapache2-mod-fastcgi php5-fpm php5-mysqlnd mariadb-server mysqltuner zsh unattended-upgrades bsd-mailx
    
    curl -sS https://getcomposer.org/installer | php
    
    sudo mv composer.phar /usr/local/bin/composer
    
    sudo adduser exampleuser
    
    sudo usermod -a -G sudo,www-data exampleuser
    
    su exampleuser
    
    cd ~
    
    curl -L http://install.ohmyz.sh | sh
    
    chsh -s /usr/bin/zsh
    
    mkdir ~/.ssh
    
    **from desktop**
    scp ~/.ssh/id_rsa.pub exampleuser@123.456.78.90:
    
    mv ~/id_rsa.pub ~/.ssh/authorized_keys
    
    chown -R exampleuser:exampleuser .ssh
    
    chmod 700 .ssh
    
    chmod 600 .ssh/authorized_keys
    
    sudo nano /etc/ssh/sshd_config
    
    ```
    PasswordAuthentication no
    PubkeyAuthentication yes
    AuthorizedKeysFile     %h/.ssh/authorized_keys
    PermitRootLogin no
    ```
    
    sudo service ssh restart
    
    ssh-keygen -t rsa -C "info@example.com"
    
    eval "$(ssh-agent -s)"
    
    ssh-add ~/.ssh/id_rsa
    
    sudo iptables -L
    
    sudo nano /etc/iptables.firewall.rules
    
    ```
    *filter
    
    #  Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
    -A INPUT -i lo -j ACCEPT
    -A INPUT -d 127.0.0.0/8 -j REJECT
    
    #  Accept all established inbound connections
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    #  Allow all outbound traffic - you can modify this to only allow certain traffic
    -A OUTPUT -j ACCEPT
    
    #  Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).
    -A INPUT -p tcp --dport 80 -j ACCEPT
    -A INPUT -p tcp --dport 443 -j ACCEPT
    
    #  Allow SSH connections
    #  The -dport number should be the same port number you set in sshd_config
    -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
    
    #  Allow ping
    -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
    
    #  Allow incoming Longview connections
    -A INPUT -s longview.linode.com -j ACCEPT
    
    # Allow metrics to be provided Longview
    -A OUTPUT -d longview.linode.com -j ACCEPT
    
    # Prevent DoS Attacks
    -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT
    
    #  Log iptables denied calls
    -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
    
    #  Drop all other inbound - default deny unless explicitly allowed policy
    -A INPUT -j DROP
    -A FORWARD -j DROP
    
    COMMIT
    ```
    
    sudo iptables-restore < /etc/iptables.firewall.rules
    
    sudo iptables -L
    
    sudo nano /etc/network/if-pre-up.d/firewall
    
    ```
    #!/bin/sh
    /sbin/iptables-restore < /etc/iptables.firewall.rules
    ```
    
    sudo chmod +x /etc/network/if-pre-up.d/firewall
    
    sudo a2enmod rewrite
    
    sudo nano /etc/apache2/apache2.conf
    
    **Linode 1024**
    ```
    KeepAlive Off
    
    <IfModule mpm_prefork_module>
    StartServers 2
    MinSpareServers 6
    MaxSpareServers 12
    MaxClients 80
    MaxRequestsPerChild 3000
    </IfModule>
    ```
    
    **Linode 2048**
    ```
    KeepAlive Off
    
    <IfModule mpm_prefork_module>
    StartServers 4
    MinSpareServers 12
    MaxSpareServers 24
    MaxClients 160
    MaxRequestsPerChild 6000
    </IfModule>
    ```
    
    **Linode 4096**
    ```
    KeepAlive Off
    
    <IfModule mpm_prefork_module>
    StartServers 8
    MinSpareServers 24
    MaxSpareServers 48
    MaxClients 320
    MaxRequestsPerChild 12000
    </IfModule>
    ```
    
    sudo a2dissite default
    
    sudo a2enmod actions
    
    sudo nano /etc/php5/fpm/pool.d/www.conf
    
    ```
    listen = /var/run/php5-fpm.sock
    ```
    
    sudo service php5-fpm restart
    
    sudo apache2 -v
    
    sudo nano /etc/apache2/mods-enabled/fastcgi.conf
    
    **Apache version 2.2 or earlier**
    ```
    <IfModule mod_fastcgi.c>
        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php5-fcgi
        Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
    </IfModule>
    ```
    
    **Apache version 2.4 or later**
    ```
    <IfModule mod_fastcgi.c>
        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php5-fcgi
        Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
        <Directory /usr/lib/cgi-bin>
            Require all granted
        </Directory>
    </IfModule>
    ```
    
    sudo mysql_secure_installation
    
    sudo nano /etc/php5/apache2/php.ini
    
    **if new file, exit, run the following command and reopen
    sudo mkdir /etc/php5/apache2
    sudo cp /etc/php5/fpm/php.ini /etc/php5/apache2/php.ini
    
    ```
    short_open_tag = Off
    asp_tags = Off
    expose_php = Off
    max_execution_time = 30
    max_input_time = 30
    memory_limit = 128M
    error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
    display_errors = Off 
    log_errors = On 
    register_globals = Off
    file_uploads = On
    upload_max_filesize = 100M
    max_file_uploads = 20
    allow_url_include = Off
    date.timezone = Europe/London
    ```
    
    sudo cp /etc/php5/apache2/php.ini /etc/php5/fpm/php.ini
    
    sudo nano /etc/php5/mods-available/apc.ini
    
    ```
    [APC]
    extension=apc.so
    apc.enabled=1
    apc.shm_segments=1
    
    ;32M per WordPress install
    apc.shm_size=128M
    
    ;Relative to the number of cached files (you may need to watch your stats for a day or two to find out a good number)
    apc.num_files_hint=7000
    
    ;Relative to the size of WordPress
    apc.user_entries_hint=4096
    
    ;The number of seconds a cache entry is allowed to idle in a slot before APC dumps the cache
    apc.ttl=7200
    apc.user_ttl=7200
    apc.gc_ttl=3600
    
    ;Setting this to 0 will give you the best performance, as APC will
    ;not have to check the IO for changes. However, you must clear
    ;the APC cache to recompile already cached files. If you are still
    ;developing, updating your site daily in WP-ADMIN, and running W3TC
    ;set this to 1
    apc.stat=1
    
    ;This MUST be 0, WP can have errors otherwise!
    apc.include_once_override=0
    
    ;Only set to 1 while debugging
    apc.enable_cli=0
    
    ;Allow 2 seconds after a file is created before it is cached to prevent users from seeing half-written/weird pages
    apc.file_update_protection=2
    
    ;Leave at 2M or lower. WordPress does't have any file sizes close to 2M
    apc.max_file_size=2M
    
    apc.cache_by_default=1
    apc.use_request_time=1
    apc.slam_defense=0
    apc.mmap_file_mask=/tmp/apc.XXXXXX
    apc.stat_ctime=0
    apc.canonicalize=1
    apc.write_lock=1
    apc.report_autofilter=0
    apc.rfc1867=0
    apc.rfc1867_prefix =upload_
    apc.rfc1867_name=APC_UPLOAD_PROGRESS
    apc.rfc1867_freq=0
    apc.rfc1867_ttl=3600
    apc.lazy_classes=0
    apc.lazy_functions=0
    ```
    
    sudo service apache2 restart
    
    sudo updatedb
    
    sudo dpkg-reconfigure -plow unattended-upgrades
    
    sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
    
    
    

    external by unicolet modified Dec 13, 2015  79  0  1  0

    salt-cloud linode patch

    salt-cloud linode patch: linode.py.patch
    --- /usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.py.orig	2015-12-12 16:32:49.860428104 +0100
    +++ /usr/lib/python2.7/site-packages/salt/cloud/clouds/linode.py	2015-12-12 17:09:37.384331055 +0100
    @@ -537,6 +537,18 @@
                 'disk_size', vm_, __opts__, default=disksize - swap
             )
     
    +    def get_data_disk_size(vm_, size, swap):
    +        '''
    +        Return the size of of the data disk in MB
    +        '''
    +        conn = get_conn()
    +        vmsize = get_size(conn, vm_)
    +        disksize = int(vmsize['disk']) * 1024
    +        root_disk_size = config.get_cloud_config_value(
    +            'disk_size', vm_, __opts__, default=disksize - swap
    +        )
    +        return disksize - root_disk_size - swap
    +
     # End of linode-python specific functions.  The following are
     # usable by both Apache Libcloud and Linode-python, or just Linode-python.
     # Linode-python functions almost all take a LinodeID.
    @@ -601,6 +613,14 @@
             'private_ip', vm_, __opts__, default=False
         )
     
    +def get_data_disk(vm_):
    +    '''
    +    Return True if a data disk is requested
    +    '''
    +    return config.get_cloud_config_value(
    +        'data_disk', vm_, __opts__, default=False
    +    )
    +
     
     def get_swap(vm_):
         '''
    @@ -738,6 +758,17 @@
                                          Type='swap')
         return result
     
    +def create_data_disk(vm_=None, LinodeID=None, datasize=None):
    +    '''
    +    Create a data disk for the linode (type is hardcoded to ext4 at the moment)
    +    '''
    +    conn = get_conn()
    +
    +    result = conn.linode_disk_create(LinodeID=LinodeID,
    +                                     Label='data',
    +                                     Size=datasize,
    +                                     Type='ext4')
    +    return result
     
     def create_disk_from_distro(vm_=None, LinodeID=None, swapsize=None):
         '''
    @@ -767,7 +798,7 @@
         return result
     
     
    -def create_config(vm_, LinodeID=None, root_disk_id=None, swap_disk_id=None):
    +def create_config(vm_, LinodeID=None, root_disk_id=None, swap_disk_id=None, data_disk_id=None):
         '''
         Create a Linode Config
         '''
    @@ -775,11 +806,14 @@
     
     # 138 appears to always be the latest 64-bit kernel for Linux
         kernelid = 138
    +   
    +    disklist = '{0},{1}'.format(root_disk_id,swap_disk_id)
    +    if data_disk_id is not None:
    +       disklist = '{0},{1},{2}'.format(root_disk_id,swap_disk_id,data_disk_id)
     
         result = conn.linode_config_create(LinodeID=LinodeID,
                                            Label=vm_['name'],
    -                                       Disklist='{0},{1}'.format(root_disk_id,
    -                                                                 swap_disk_id),
    +                                       Disklist=disklist,
                                            KernelID=kernelid,
                                            RootDeviceNum=1,
                                            RootDeviceRO=True,
    @@ -952,10 +986,17 @@
                 root_result = create_disk_from_distro(vm_, LinodeID=node_data['LinodeID'],
                                                      swapsize=get_swap(vm_))
     
    +            if get_data_disk(vm_):
    +               data_result = create_data_disk(LinodeID=node_data['LinodeID'], datasize=get_data_disk_size(vm_, None, get_swap(vm_)))
    +            else:
    +               # make sure we have the required key
    +               data_result = { 'DiskID' : None }
    +
                 # Create config
                 config_result = create_config(vm_, LinodeID=node_data['LinodeID'],
                                               root_disk_id=root_result['DiskID'],
    -                                          swap_disk_id=swap_result['DiskID'])
    +                                          swap_disk_id=swap_result['DiskID'],
    +                                          data_disk_id=data_result['DiskID'])
     
                 # Boot!
                 boot_result = boot(LinodeID=node_data['LinodeID'],
    
    
    • Public Snippets
    • Channels Snippets