Skip to content
Snippets Groups Projects
Commit a3b3a37e authored by Frederic GAUDET's avatar Frederic GAUDET
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
Showing
with 1068 additions and 0 deletions
DS_Store
This repo contains all files used during the MaDICS meeting which took place on the june, 23th 2017.
[MaDICS](http://www.madics.fr)
#/bin/bash
set -v
openstack floating ip list
openstack server add floating ip madics 193.55.95.151
# Introduction
This heat template allows you to easily deploy a Cassandra cluster on OpenStack.
# Quick start
1) Clone this repository :
`git clone https://github.com/frgaudet/openstack-heat-cassandra.git`
2) Source your OpenStack environment file :
`source openrc.sh`
3) Prepare your parameters :
* key_name: Name of key-pair to be used
* image_id: Server image
* net_id: Private network id
* name: Prefix for all your instances's name
4) Launch a Cluster :
```
cd openstack-heat-cassandra
openstack stack create -e lib/env.yaml \
--parameter "key_name=fgaudet-key;image_id=Ubuntu Server 16.04_Cassandra-3.10_java8;net_id=fred-net2;name=fgaudet-cassandra" \
-t cassandra.yaml \
Cassandra-stack
```
Default node count is 3 (+ 1 seeder).
# Parameters
You can change the default parameters to suit your own environment. For example, create a 5 nodes cluster, with a m1.xlarge flavor :
```
openstack stack create -e lib/env.yaml \
--parameter "count=5;flavor=m1.xlarge;key_name=fgaudet-key;image_id=Ubuntu Server 16.04_Cassandra-3.10_java8;net_id=fred-net2;name=fgaudet-cassandra" \
-t cassandra.yaml \
Cassandra-stack
```
Note the stack id :
```
+---------------------+--------------------------------------------------------+
| Field | Value |
+---------------------+--------------------------------------------------------+
| id | 3372c082-a049-405b-99b5-ac439278ea5f |
| stack_name | Cassandra-stack |
| description | Template that installs a cluster of Cassandra servers. |
| creation_time | 2017-05-30T12:13:47 |
| updated_time | None |
| stack_status | CREATE_IN_PROGRESS |
| stack_status_reason | Stack CREATE started |
+---------------------+--------------------------------------------------------+
```
# Check the master
Get your cluster's public IP address using the stack id (see above):
`openstack stack output show 3372c082-a049-405b-99b5-ac439278ea5f public_ip`
This command should return you something like this, with of course a real IP :
```
+--------------+--------------------------------------------------+
| Property | Value |
+--------------+--------------------------------------------------+
| description | The public IP address of this Cassandra cluster. |
| output_key | public_ip |
| output_value | "XXX.XXX.XXX.XXX" |
+--------------+--------------------------------------------------+
```
# Check it !
Connect to your seeder, using this IP you've just find out :
`ssh <username>@IP`
Then login with the cassandra user (via root):
```
ubuntu@fgaudet-cassandra:~$ sudo su - cassandra
```
and check your cluster :
```
cassandra@fgaudet-cassandra:~$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.0.0.73 83.19 KB 256 49.3% eb05607c-ee98-4173-9cfc-51735c72b692 rack1
UN 10.0.0.74 106.9 KB 256 49.0% d8c96c25-abfb-4f29-aee4-874f54ce0247 rack1
UN 10.0.0.75 15.42 KB 256 50.9% e68a3426-fc01-4e08-b304-ea8ebc91526d rack1
UN 10.0.0.76 107.37 KB 256 50.7% cc043259-c900-42ea-961f-ab5119670cfa rack1
```
heat_template_version: 2013-05-23
description: Template that installs a cluster of Cassandra servers.
parameters:
count:
description: Number of Cassandra nodes
type: number
default: 3
key_name:
type: string
description: Name of key-pair to be used
flavor:
type: string
default: m1.large
description: |
Choose an instance flavor
image_id:
type: string
label: Server image
net_id:
type: string
label: Network ID
description: ID of the public network to use
name:
type: string
description: Name of each Cassandra machine booted
public_network:
type: string
description: Public network id
default: ext-publicnet
private_key:
type: string
description: Name of private key to be used for the local Cassandra user
default: []
hidden: true
public_key:
type: string
description: Name of plublic key to be used for the local Cassandra user
default: []
hidden: true
resources:
my_cassandra_key:
properties:
name: my_cassandra_key
save_private_key: true
type: OS::Nova::KeyPair
cassandra_cluster:
type: OS::Heat::ResourceGroup
properties:
count: { get_param: count}
resource_def:
type: Lib::MSG::CassandraNode
properties:
image_id: { get_param: image_id }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
net_id: { get_param: net_id }
public_key: { get_attr: [ my_cassandra_key, public_key ] }
name:
str_replace:
template:
$name-$index
params:
$name: { get_param: name }
$index: "%index%"
cassandra_seeder:
type: Lib::MSG::CassandraSeeder
depends_on: cassandra_cluster
properties:
image_id: { get_param: image_id }
flavor: { get_param: flavor }
key_name: { get_param: key_name }
net_id: { get_param: net_id }
servers: { get_attr: [cassandra_cluster, node_param] }
private_key: { get_attr: [ my_cassandra_key, private_key ] }
name: { get_param: name }
public_network: { get_param: public_network }
outputs:
public_ip:
description: The public IP address of this Cassandra cluster.
value: { get_attr: [cassandra_seeder, ip] }
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
set -x
openstack stack create -e lib/env.yaml \
--parameter "key_name=fgaudet-key;image_id=Ubuntu Server 16.04_Cassandra-3.10_java8;net_id=fred-net;name=madics-cassandra" \
-t cassandra.yaml \
Madics-Cassandra-stack
\ No newline at end of file
heat_template_version: 2014-10-16
description: Deploy a Cassandra Node instance
parameters:
key_name:
type: string
description: Name of key-pair to be used for the default user
flavor:
type: string
description: |
Choose an instance flavor
image_id:
type: string
label: Server image
net_id:
type: string
label: Network ID
description: ID of the network to use
name:
type: string
description: Name of each Cassandra machine booted
public_key:
type: string
description: Name of plublic key to be used for the local Cassandra user
resources:
wait_condition:
type: OS::Heat::WaitCondition
properties:
handle: { get_resource: wait_handle }
count: 1
timeout: 300
wait_handle:
type: OS::Heat::WaitConditionHandle
cassandra_node:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: { get_param: image_id }
networks:
- port: { get_resource: cassandra_port }
flavor: { get_param: flavor }
name: { get_param: name }
user_data_format: RAW
user_data:
str_replace:
params:
__public_key__: { get_param: public_key }
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] }
template: |
#!/bin/bash
export CASSANDRA_VERSION=3.10
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; wc_notify --data-binary '{"status": "FAILURE"}' ; exit 1; }
try() { "$@" || die "cannot $*"; }
# Create local cassandra user
useradd -m cassandra
mkdir -p /home/cassandra/.ssh
echo "__public_key__" > /home/cassandra/.ssh/authorized_keys
# Create Cassandra systemd service
cat > /lib/systemd/system/cassandra.service << EOF
[Unit]
Description=Cassandra DB
After=network.target auditd.service
[Service]
EnvironmentFile=-/etc/default/cassandra
ExecStart=/opt/cassandra/bin/cassandra
User=cassandra
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=cassandra.service
EOF
cat > /etc/init/cassandra.conf << EOF
# cassandra - DB server
#
description "Cassandra server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
umask 022
env SSH_SIGSTOP=1
expect stop
console none
pre-start script
test -x /opt/cassandra/bin/cassandra || { stop; exit 0; }
mkdir -p -m0755 /var/run/cassandra
end script
exec /opt/cassandra/bin/cassandra
EOF
# Enable either systemd or Upstart service
systemctl enable cassandra.service 2>/dev/null || ln -s /lib/init/upstart-job /etc/init.d/cassandra
# Save cassandra configuration file
cp /opt/cassandra/conf/cassandra.yaml /opt/cassandra/conf/casssandra_base.yaml
# Fix perms
chown -R cassandra. /home/cassandra/.ssh
chown -R cassandra. /home/cassandra
chown -R cassandra. /opt/apache-cassandra-$CASSANDRA_VERSION
# Export Cassandra environment variables
cat >> /etc/profile << EOF
export CASSANDRA_HOME=/opt/cassandra
export PATH=\$PATH:\$CASSANDRA_HOME/bin
EOF
# Disable requiretty
sed -i -e "s/Defaults requiretty/#Defaults requiretty/g" \
/etc/sudoers
cat > /etc/sudoers.d/cassandra << EOF
cassandra ALL=(ALL) NOPASSWD: /usr/sbin/service cassandra restart,/bin/mv /tmp/hosts /etc/hosts
EOF
chmod 440 /etc/sudoers.d/cassandra
# Notify Heat we're done
wc_notify --data-binary '{"status": "SUCCESS"}'
cassandra_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: cassandra_security_group
rules:
- protocol: icmp
- protocol: tcp
port_range_min: 22
port_range_max: 22
- protocol: tcp
port_range_min: 7000
port_range_max: 7001
- protocol: tcp
port_range_min: 7199
port_range_max: 7199
cassandra_port:
type: OS::Neutron::Port
properties:
network: { get_param: net_id }
security_groups:
- { get_resource: cassandra_security_group }
outputs:
node_param:
description: The IP address of this Cassandra instance.
value: { list_join: ['@', [ get_attr: [cassandra_node, first_address], get_attr: [cassandra_node, name] ] ] }
heat_template_version: 2014-10-16
description: Deploy a Cassandra seeder instance
parameters:
key_name:
type: string
description: Name of key-pair to be used for the default user
flavor:
type: string
description: |
Choose an instance flavor
image_id:
type: string
label: Server image
net_id:
type: string
label: Network ID
description: ID of the network to use
name:
type: string
description: Name of each Cassandra machine booted
servers:
type: comma_delimited_list
label: Servers
description: Comma separated list of servers in the cluster.
private_key:
type: string
description: Name of private key to be used for the local Cassandra user
public_network:
type: string
description: Public network id
resources:
wait_condition:
type: OS::Heat::WaitCondition
properties:
handle: { get_resource: wait_handle }
count: 1
timeout: 600
wait_handle:
type: OS::Heat::WaitConditionHandle
cassandra_seeder:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
name: { get_param: name }
image: { get_param: image_id }
networks:
- port: { get_resource: cassandra_port }
flavor: { get_param: flavor }
metadata:
servers: { get_param: servers }
user_data_format: RAW
user_data:
str_replace:
params:
wc_notify: { get_attr: ['wait_handle', 'curl_cli'] }
__private_key__: { get_param: private_key }
template: |
#!/bin/bash
export CASSANDRA_VERSION=3.10
yell() { echo "$0: $*" >&2; }
die() { yell "$*"; wc_notify --data-binary '{"status": "FAILURE"}'; exit 1; }
try() { "$@" || die "cannot $*"; }
# Create local cassandra user
useradd -m cassandra
mkdir -p /home/cassandra/.ssh
echo "__private_key__" > /home/cassandra/.ssh/id_rsa
# Put ssh config
cat > /home/cassandra/.ssh/config <<EOF
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
# Fix perms
chown -R cassandra. /opt/apache-cassandra-$CASSANDRA_VERSION
chmod 600 /home/cassandra/.ssh/id_rsa
chown -R cassandra. /home/cassandra/.ssh
chown -R cassandra. /home/cassandra
# Export Cassandra environment variables
cat >> /etc/profile << EOF
export CASSANDRA_HOME=/opt/cassandra
export PATH=\$PATH:\$CASSANDRA_HOME/bin
EOF
# Create Cassandra systemd service
if [ -d /lib/systemd/system/ ]; then
cat > /lib/systemd/system/cassandra.service << EOF
[Unit]
Description=Cassandra DB
After=network.target auditd.service
[Service]
EnvironmentFile=-/etc/default/cassandra
User=cassandra
ExecStart=/opt/cassandra/bin/cassandra
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=cassandra.service
EOF
fi
if [ -d /etc/init ]; then
cat > /etc/init/cassandra.conf << EOF
# cassandra - DB server
#
description "Cassandra server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
umask 022
env SSH_SIGSTOP=1
expect stop
console none
pre-start script
test -x /opt/cassandra/bin/cassandra || { stop; exit 0; }
mkdir -p -m0755 /var/run/cassandra
end script
exec /opt/cassandra/bin/cassandra
EOF
fi
# Enable either systemd or Upstart service
systemctl enable cassandra.service 2>/dev/null || ln -s /lib/init/upstart-job /etc/init.d/cassandra
# Get nodes IP from openstack metadata
list=$(curl http://169.254.169.254/openstack/latest/meta_data.json 2>/dev/null | python -c 'import json,sys;metadata=json.load(sys.stdin);list=json.loads(metadata.get("meta", {}).get("servers", "[]")); print tuple(map(str,list)) ')
# Remove useless chars
list=${list//[\' ()]}
# Convert string to array
IFS=',' read -r -a server_list <<< "$list"
cp /opt/cassandra/conf/cassandra.yaml /opt/cassandra/conf/cassandra_base.yaml
# Select default network device
dev=$(/sbin/ip route | awk '/default/ { print $5 }')
# Find out associated IP
my_ip=$(ip a | grep ${dev} -A1 | grep inet | awk '{print $2}' | cut -d "/" -f 1)
# seeder settings
sed -i -e "s/listen_address.*/listen_address: ${my_ip}/" \
-e "s/- seeds:.*/- seeds: \"${my_ip}\"/" \
-e "s/num_tokens:.*/num_tokens: 256/" \
-e "s/cluster_name.*/cluster_name: 'MyFirstCluster'/" \
-e "s/rpc_address:.*/rpc_address: ${my_ip}/" /opt/cassandra/conf/cassandra.yaml
# Add Seeder IP in hosts file
cat >> /etc/hosts << EOF
${my_ip} $(hostname)
EOF
# Add nodes IP in hosts file
for item in "${server_list[@]}"
do
ip=$(echo ${item} | cut -d "@" -f 1)
hostname=$(echo ${item} | cut -d "@" -f 2)
cat >> /etc/hosts << EOF
${ip} ${hostname}
EOF
done
try service cassandra restart
# Disable requiretty
sed -i -e "s/Defaults requiretty/#Defaults requiretty/g" \
/etc/sudoers
sleep 5
# node settings
for item in "${server_list[@]}"
do
ip=$(echo ${item} | cut -d "@" -f 1)
# Create node's configuration file
cp /opt/cassandra/conf/cassandra.yaml /opt/cassandra/conf/cassandra_${ip}.yaml
sed -i -e "s/listen_address.*/listen_address: ${ip}/" \
-e "s/rpc_address:.*/rpc_address: ${ip}/" /opt/cassandra/conf/cassandra_${ip}.yaml
try sudo -H -u cassandra scp /opt/cassandra/conf/cassandra_${ip}.yaml ${ip}:/opt/cassandra/conf/cassandra.yaml
try sudo -H -u cassandra ssh ${ip} sudo service cassandra restart
try sudo -H -u cassandra scp /etc/hosts ${ip}:/tmp/hosts
try sudo -H -u cassandra ssh ${ip} sudo mv /tmp/hosts /etc/hosts
sleep 60
done
# Notify Heat we're done
wc_notify --data-binary '{"status": "SUCCESS"}'
cassandra_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: cassandra_security_group
rules:
- protocol: icmp
- protocol: tcp
port_range_min: 22
port_range_max: 22
- protocol: tcp
port_range_min: 7000
port_range_max: 7001
- protocol: tcp
port_range_min: 7199
port_range_max: 7199
cassandra_port:
type: OS::Neutron::Port
properties:
network: { get_param: net_id }
security_groups:
- { get_resource: cassandra_security_group }
floating_ip:
type: OS::Neutron::FloatingIP
properties:
floating_network: { get_param: public_network }
floating_ip_assoc:
type: OS::Neutron::FloatingIPAssociation
properties:
floatingip_id: { get_resource: floating_ip }
port_id: { get_resource: cassandra_port }
outputs:
name:
description: Name of this Cassandra instance.
value: { get_attr: [cassandra_seeder, name] }
ip:
description: The floating IP address of this Cassandra instance.
value: { get_attr: [floating_ip, floating_ip_address] }
resource_registry:
Lib::MSG::CassandraNode: cassandra_node.yaml
Lib::MSG::CassandraSeeder: cassandra_seeder.yaml
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
set -x
ceilometer sample-list --meter cpu_util \
--query "resource_id=$UUID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
set -x
ceilometer sample-list --meter disk.read.bytes \
--query "resource_id=$UUID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
set -x
ceilometer sample-list --meter disk.write.bytes \
--query "resource_id=$UUID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
# Awful hack to retrieve resource_id from image UUID
# Challenge is to retrieve the SRV part of this resource id which is by default only available to admin
PORT_ID=$(ceilometer sample-list --meter network.outgoing.bytes | grep $UUID | cut -d "|" -f 2 | uniq)
PORT_ID=${PORT_ID//[\' ()]}
set -x
ceilometer sample-list --meter network.incoming.bytes \
--query "resource_id=$PORT_ID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
set -x
ceilometer sample-list --meter memory.usage \
--query "resource_id=$UUID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -s server-name" >&2
}
optspec=":hs-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] ; then
help
exit 1
fi
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
set -x
ceilometer meter-list --query "resource_id=$UUID"
ceilometer meter-list --query "resource_id=$UUID-vdb"
#!/bin/bash
# coding=utf-8
#
# 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.
#
# <http://www.gnu.org/licenses/>.
#
# F-Gaudet 2017
#
# WARNING : Due to resolution issue (remember this script has been written for Audace2017 talk), I don't rely on server UUID but names.
# This is not a good practice as you can have 2 VM with the exact same name in OpenStack. So I would suggest you to change that before using this script.
help () {
echo "usage: $0 -d day(s) -s server-name" >&2
}
optspec=":hsd-:"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
help
exit 1
;;
s)
NAME="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
d)
DAYS="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 ))
;;
esac
done
# Check arg number
if [ -z "$NAME" ] || [ -z "$DAYS" ] ; then
help
exit 1
fi
TODAY=$(date -j "+%Y-%m-%d")
PAST_DATE=$(date -j -v-${DAYS}d "+%Y-%m-%d")
# Get UUID from (first...) name
UUID=$(openstack server list | grep $NAME | cut -d '|' -f 2)
UUID=${UUID//[\' ()]}
# Awful hack to retrieve resource_id from image UUID
# Challenge is to retrieve the SRV part of this resource id which is by default only available to admin
PORT_ID=$(ceilometer sample-list --meter network.outgoing.bytes | grep $UUID | cut -d "|" -f 2 | uniq)
PORT_ID=${PORT_ID//[\' ()]}
set -x
ceilometer sample-list --meter network.outgoing.bytes \
--query "resource_id=$PORT_ID;timestamp>${PAST_DATE}T00:00:00;timestamp<=${TODAY}T23:59:59" \
--limit 5000
\ No newline at end of file
#/bin/bash
set -v
FLAVOR=m1.small
IMAGE="Ubuntu Server 16.04 LTS (xenial)"
NET_ID=11cfde5b-b7d7-4102-8008-d20fa6a56564
KEY=fgaudet-key
openstack server create --flavor $FLAVOR --image "$IMAGE" --key $KEY --nic net-id=$NET_ID madics
#!/bin/bash
cd openstack-heat-slurm
set -x
openstack stack create -t slurm.yaml \
-e lib/env.yaml \
--parameter "count=4;flavor=c1.large;key_name=fgaudet-key;image_id=7c09f5aa-52fa-4daf-a14d-8956cde1e0f2;net_id=fgaudet-net2;name=fgaudet-slurm" \
slurm-stack
\ No newline at end of file
images/gq.gif

2.94 MiB

images/questions.gif

6.58 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment