<commit_before>PackStackSandBox
================

A template for further sanbox work with packstack, brings up two nodes. One controller and One Compute/Netowrking. Should be easy to modify to meet your needs. 

Can be run in bridged mode or nat mode, see below for details

nodes can be reached after vagrant up with
    vagrant ssh controller
    vagrant ssh compute 

Requirements
============
Get VirtualBox https://www.virtualbox.org/wiki/Downloads

Get Vagrant https://www.vagrantup.com/downloads.html

Install vagrant-vbguest

    vagrant plugin install vagrant-vbguest

Get this repo

    git clone https://github.com/Aricg/PackStackSandBox.git && cd PackStackSandBox


Nat Mode
========

Copy Vagrantfile.yml.template.natmode to Vagrantfile.yml 

Nat networking will provide the gateway to the internet as well as connectivity between hosts throught the vboxnetX interface created by vagrant

Setup Masquerade/Forwarding on your host to you vboxnet interface

make sure these are set in /etc/sysctl.d

    net.ipv4.ip_forward = 1
    net.ipv4.conf.all.proxy_arp = 1

And loaded

    sudo sysctl -p

In my example my hosts interface for internet connetiviy is docker0 (yours might be eth0 for example) and my the vboxnet brought up by vagrant up is vboxnet4 and the subnet I have set for the sandbox machines in the vagrantfile.yaml is 10.0.20.0/22

    iptables -A FORWARD -o docker0 -i vboxnet4 -s 10.0.20.0/22 -m conntrack --ctstate NEW -j ACCEPT
    iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    iptables -A POSTROUTING -t nat -j MASQUERADE

In this example we have set the vboxnet to  the 10.0.20.0/22 range.

Vagrant ssh into the compute and the controller node and set the default route to vboxnet0 rather than the nat device that vagrant sets at default

TODO automate this.

    ip route del default
    ip route add default via 10.0.20.1 (the gateway set it your Vagrantfile.yml) dev eth1

You are now ready to "Launch Vagrant" (see below) 

Bridged Mode
===========

If you are able to configure and use a bridge we can bring up openstack VMs on your local network. you will need a netmask of 23 or below.

My bridge in this readme is called docker0

    $ brctl show
    bridge name     bridge id               STP enabled     interfaces
    docker0     


To start copy Vagrantfile.yml.template.bridgemode to Vagrantfile.yml to reflect the network avaliable to you. In this example I have a /22 avaliable on my home network, Later we reserve a /24 section of my /22 network for the neutron router we create. 

My example config:

    bridge: docker0  
    netmask: 255.255.252.0 
    gateway: 192.168.0.1
    neutron_router_start: 192.168.3.1
    neutron_router_end: 192.168.3.128
    controller:
      bridged_ip: 192.168.1.91
      private_ip: 10.2.20.2
    compute:
      bridged_ip: 192.168.1.93
      private_ip: 10.2.20.3
    
You are now ready to "Launch Vagrant" (see below)

Vagrantfile.yml Explanation
==========================

Warning, make sure there are no trailing white spaces in this file

**nat_mode:** set to yes for nat mode, leave blank for bridge mode

**bridge:** name of your bridge interface ($ brctl show ) leave blank for nat mode

**netmask:** netmask of your private subnet, probably given to you via dhcp. you can see this with ifconfig, however on osx if will be in the unreadble format, something like 0xffffff00 Refer here for a table that human can read. http://www.pawprint.net/designresources/netmask-converter.php Most home networks only give out a /24 you will need to log into your router and change your range to at least a /23 so that we an properly route to the router that neutron creates. 

**gateway:**  For bridged mode Your workstations gateway to the internet (your routers ip, this is also the ip you go to to increase your network size
) you can check this with ip r on linux or netstat -nr on osx
For nat mode set this to the first ip in the range you are choosing for private_ip 

**neutron_router_start:** This will be the start of your openstack dhcp, I also use this as your neutron router gateway. give neutron its own /24 range

**neutron_router_end:** the end of the range explained above

controller:

  **bridged_ip:** this interface should be given an ip on the same /24 as your workstation.

  **private_ip:** this interface can have any ip you want, virtualbox deals with the routing.

compute:

  **bridged_ip:** same rules as the controller bridged_ip but unique

  **private_ip:** same rules as controller: private_ip but unique

for nat mode set the bridged_ip and private_ip to the same values for each host (as seen in Vagrantfile.yml.template.natmode)

Launch Vagrant
==============
    
    vagrant up

ssh into the vagrant controller (password is <PASSWORD>)

    vagrant ssh controller

run packstack (for nat mode complete steps below first) 

    cd /vagrant
    sudo bash
    packstack  --answer-file=ans.txt && yes|cp /root/keystonerc_admin /vagrant

the answerfile is generated from ans.template or ans.NAT.template when you run vagrant up. 
packstack should now prompt you for the root password of both nodes. The password is "<PASSWORD>"
if packstack fails for some reason, just run it again. 

Networking
==========
To setup networking, and launch the cirros minimal VM you must wait for the above operations to complete. (packstack and copying the keystonerc_admin) Once those are done, vagrant ssh into the networking (compute node):

    vagrant ssh compute
    [vagrant@compute]# sudo bash
    [root@compute ]# cd /vagrant && ./SetupComputeNode

That's it everything should work now.

Testing
=======

Dashboard

Natmode:
http://localhost:8080/dashboard/ 

Bridgemode:
http:// compute: bridged_ip: from your vagtantfile.yml

CirrosVM

ssh into your machine and ping the outside world

    [root@compute vagrant]# source keystonerc_admin
    [root@compute vagrant(keystone_admin)]# neutron floatingip-list
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | id                                   | fixed_ip_address | floating_ip_address | port_id                              |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | ea3d5757-e646-4d6e-9c0d-e6304cee3ff0 | 172.17.0.2       | 10.0.23.2           | 53157795-741e-479c-afb6-1ceb26fd500e |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    [root@compute vagrant(keystone_admin)]# ssh cirros@10.0.23.2
    cirros@10.0.23.2's password: <PASSWORD>:)
    $ ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8): 56 data bytes
    64 bytes from 8.8.8.8: seq=0 ttl=50 time=24.782 ms
    64 bytes from 8.8.8.8: seq=1 ttl=50 time=23.527 ms

Tools<commit_msg>fix line break<commit_after>PackStackSandBox
================

A template for further sanbox work with packstack, brings up two nodes. One controller and One Compute/Netowrking. Should be easy to modify to meet your needs. 

Can be run in bridged mode or nat mode, see below for details

nodes can be reached after vagrant up with
    vagrant ssh controller
    vagrant ssh compute 

Requirements
============
Get VirtualBox https://www.virtualbox.org/wiki/Downloads

Get Vagrant https://www.vagrantup.com/downloads.html

Install vagrant-vbguest

    vagrant plugin install vagrant-vbguest

Get this repo

    git clone https://github.com/Aricg/PackStackSandBox.git && cd PackStackSandBox


Nat Mode
========

Copy Vagrantfile.yml.template.natmode to Vagrantfile.yml 

Nat networking will provide the gateway to the internet as well as connectivity between hosts throught the vboxnetX interface created by vagrant

Setup Masquerade/Forwarding on your host to you vboxnet interface

make sure these are set in /etc/sysctl.d

    net.ipv4.ip_forward = 1
    net.ipv4.conf.all.proxy_arp = 1

And loaded

    sudo sysctl -p

In my example my hosts interface for internet connetiviy is docker0 (yours might be eth0 for example) and my the vboxnet brought up by vagrant up is vboxnet4 and the subnet I have set for the sandbox machines in the vagrantfile.yaml is 10.0.20.0/22

    iptables -A FORWARD -o docker0 -i vboxnet4 -s 10.0.20.0/22 -m conntrack --ctstate NEW -j ACCEPT
    iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    iptables -A POSTROUTING -t nat -j MASQUERADE

In this example we have set the vboxnet to  the 10.0.20.0/22 range.

Vagrant ssh into the compute and the controller node and set the default route to vboxnet0 rather than the nat device that vagrant sets at default

TODO automate this.

    ip route del default
    ip route add default via 10.0.20.1 (the gateway set it your Vagrantfile.yml) dev eth1

You are now ready to "Launch Vagrant" (see below) 

Bridged Mode
===========

If you are able to configure and use a bridge we can bring up openstack VMs on your local network. you will need a netmask of 23 or below.

My bridge in this readme is called docker0

    $ brctl show
    bridge name     bridge id               STP enabled     interfaces
    docker0     


To start copy Vagrantfile.yml.template.bridgemode to Vagrantfile.yml to reflect the network avaliable to you. In this example I have a /22 avaliable on my home network, Later we reserve a /24 section of my /22 network for the neutron router we create. 

My example config:

    bridge: docker0  
    netmask: 255.255.252.0 
    gateway: 192.168.0.1
    neutron_router_start: 192.168.3.1
    neutron_router_end: 192.168.3.128
    controller:
      bridged_ip: 192.168.1.91
      private_ip: 10.2.20.2
    compute:
      bridged_ip: 192.168.1.93
      private_ip: 10.2.20.3
    
You are now ready to "Launch Vagrant" (see below)

Vagrantfile.yml Explanation
==========================

Warning, make sure there are no trailing white spaces in this file

**nat_mode:** set to yes for nat mode, leave blank for bridge mode

**bridge:** name of your bridge interface ($ brctl show ) leave blank for nat mode

**netmask:** netmask of your private subnet, probably given to you via dhcp. you can see this with ifconfig, however on osx if will be in the unreadble format, something like 0xffffff00 Refer here for a table that human can read. http://www.pawprint.net/designresources/netmask-converter.php Most home networks only give out a /24 you will need to log into your router and change your range to at least a /23 so that we an properly route to the router that neutron creates. 

**gateway:**  For bridged mode Your workstations gateway to the internet (your routers ip, this is also the ip you go to to increase your network size
) you can check this with ip r on linux or netstat -nr on osx
For nat mode set this to the first ip in the range you are choosing for private_ip 

**neutron_router_start:** This will be the start of your openstack dhcp, I also use this as your neutron router gateway. give neutron its own /24 range

**neutron_router_end:** the end of the range explained above

controller:

  **bridged_ip:** this interface should be given an ip on the same /24 as your workstation.

  **private_ip:** this interface can have any ip you want, virtualbox deals with the routing.

compute:

  **bridged_ip:** same rules as the controller bridged_ip but unique

  **private_ip:** same rules as controller: private_ip but unique

for nat mode set the bridged_ip and private_ip to the same values for each host (as seen in Vagrantfile.yml.template.natmode)

Launch Vagrant
==============
    
    vagrant up

ssh into the vagrant controller (password is <PASSWORD>)

    vagrant ssh controller

run packstack (for nat mode complete steps below first) 

    cd /vagrant
    sudo bash
    packstack  --answer-file=ans.txt && yes|cp /root/keystonerc_admin /vagrant

the answerfile is generated from ans.template or ans.NAT.template when you run vagrant up. 
packstack should now prompt you for the root password of both nodes. The password is "<PASSWORD>"
if packstack fails for some reason, just run it again. 

Networking
==========
To setup networking, and launch the cirros minimal VM you must wait for the above operations to complete. (packstack and copying the keystonerc_admin) Once those are done, vagrant ssh into the networking (compute node):

    vagrant ssh compute
    [vagrant@compute]# sudo bash
    [root@compute ]# cd /vagrant && ./SetupComputeNode

That's it everything should work now.

Testing
=======

Dashboard

Natmode:
http://localhost:8080/dashboard/ 

Bridgemode:
http:// compute: bridged_ip: from your vagtantfile.yml

CirrosVM:

ssh into your machine and ping the outside world

    [root@compute vagrant]# source keystonerc_admin
    [root@compute vagrant(keystone_admin)]# neutron floatingip-list
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | id                                   | fixed_ip_address | floating_ip_address | port_id                              |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    | ea3d5757-e646-4d6e-9c0d-e6304cee3ff0 | 172.17.0.2       | 10.0.23.2           | 53157795-741e-479c-afb6-1ceb26fd500e |
    +--------------------------------------+------------------+---------------------+--------------------------------------+
    [root@compute vagrant(keystone_admin)]# ssh cirros@10.0.23.2
    cirros@10.0.23.2's password: <PASSWORD>:)
    $ ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8): 56 data bytes
    64 bytes from 8.8.8.8: seq=0 ttl=50 time=24.782 ms
    64 bytes from 8.8.8.8: seq=1 ttl=50 time=23.527 ms

Tools
{'fraction_non_alphanumeric': 0.12439947590624545, 'fraction_numerical': 0.034794002038142376, 'mean_word_length': 2.7466593946004907, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 42, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '434980', 'n_tokens_mistral': 4374, 'n_tokens_neox': 3917, 'n_words': 1717}