I am new to rabbit, so here are some notes:
First find out where rabbit api listens:
ss -na | grep 15672
And then get the management cli:
wget 192.168.243.81:15672/cli/rabbitmqadmin
chmod +x rabbitmqadmin
Get a message from a queue:
./rabbitmqadmin --host 192.168.243.81 -u nova -p gD6Yzyvr4E7h -V /nova get queue=notifications.info
Wednesday, 30 August 2017
Thursday, 25 May 2017
Associate a file extension with an application in Linux
Let's try to associate a file extension to a specific application. For the sake of this example, I would like to associate .somefile to be opened with sublime /usr/bin/subl
Before beginning, let's set a baseline. If you use the xdg-mime utility to query a file's type, you most probably will get something like text/plain. To try this out, let's create a sample file:
touch x.somefile
And then see what the system thinks about this filetype:
xdg-mime query filetype x.somefile
Most probably it will print out something, like text/plain. The first exercise is to change it.
Let's create a new mime type. For this, I'll need to create an xml file, with the name of lakat-somefile.xml (lakat is a vendor string, you might want to replace it with something else):
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-somefile">
<comment>somefile type file</comment>
<glob pattern="*.somefile"/>
</mime-type>
</mime-info>
Now let's install this mimetype:
xdg-mime install lakat-somefile.xml
And see that now the type of our dummy file is recognised:
xdg-mime query filetype x.somefile
We are expecting application/x-somefile there. If you are seeing something like inode/x-empty there, you most likely need to install some mime specific packages. In arch linux, what you need is:
sudo pacman -S perl-file-mimeinfo
Once that's done, the next thing to do is to create an "application" that will be used to open this file. If you already have an application, you don't need to do this.
Create a file, called somefile.desktop with the following contents:
[Desktop Entry]
Name=Somefile opener
Comment=Opens with sublime
Exec=/usr/bin/subl
Version=1.0
Type=Application
MimeType=application/x-somefile
Before beginning, let's set a baseline. If you use the xdg-mime utility to query a file's type, you most probably will get something like text/plain. To try this out, let's create a sample file:
touch x.somefile
And then see what the system thinks about this filetype:
xdg-mime query filetype x.somefile
Most probably it will print out something, like text/plain. The first exercise is to change it.
Let's create a new mime type. For this, I'll need to create an xml file, with the name of lakat-somefile.xml (lakat is a vendor string, you might want to replace it with something else):
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-somefile">
<comment>somefile type file</comment>
<glob pattern="*.somefile"/>
</mime-type>
</mime-info>
Now let's install this mimetype:
xdg-mime install lakat-somefile.xml
And see that now the type of our dummy file is recognised:
xdg-mime query filetype x.somefile
We are expecting application/x-somefile there. If you are seeing something like inode/x-empty there, you most likely need to install some mime specific packages. In arch linux, what you need is:
sudo pacman -S perl-file-mimeinfo
Once that's done, the next thing to do is to create an "application" that will be used to open this file. If you already have an application, you don't need to do this.
Create a file, called somefile.desktop with the following contents:
[Desktop Entry]
Name=Somefile opener
Comment=Opens with sublime
Exec=/usr/bin/subl
Version=1.0
Type=Application
MimeType=application/x-somefile
now move this file to your home directory, as a per user application:
cp somefile.desktop ~/.local/share/applications/
Now we need to associate the two. Before we do that, let's make sure that we have the correct files in place. Some old applications refer to this config file as ~/.local/share/applications/mimeapps.list, others refer to it as ~/.config/mimeapps.list. But both should be the same, so let's say that ~/.config/mimeapps.list is a symlink to ~/.local/share/applications/mimeapps.list:
ln -s ~/.local/share/applications/mimeapps.list ~/.config/mimeapps.list
Now before we start to edit this file, let's see what is the situation now, what application is used to open application/x-somefile type files:
xdg-mime query default application/x-somefile
That should yield nothing at the moment. So let's add some associations. Open ~/.config/mimeapps.list, and add something like this:
[Default Applications]
application/x-somefile=somefile.desktop
Now doing the query again, you should see that:
xdg-mime query default application/x-somefile
returns somefile.desktop as expected. Now you should be all set, and you can open your files with xdg-open:
xdg-open x.somefile
Tuesday, 23 May 2017
Git - find a specific version by stacktrace
So you have a stacktrace, something that tells you that on line XXX an exception has been raised. You want to find out what was the exact version of the code that was running at that time.
git log origin/neutron-ha-tool-maintenance --oneline -- files/default/neutron-ha-tool.py |
cut -d " " -f 1 |
while read revision; do echo $revision; git show $revision:files/default/neutron-ha-tool.py |
sed -n 576,577p ; done |
less
git log origin/neutron-ha-tool-maintenance --oneline -- files/default/neutron-ha-tool.py |
cut -d " " -f 1 |
while read revision; do echo $revision; git show $revision:files/default/neutron-ha-tool.py |
sed -n 576,577p ; done |
less
Friday, 19 May 2017
OpenStack - Launch your First VM
Some notes on how to get started with a freshly baked OpenStack (Liberty)
wget -qO - http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img | openstack image create cirros --public --container-format=bare --disk-format=qcow2
openstack network create testnetwork
neutron subnet-create --name testsubnet testnetwork 192.168.37.0/24
neutron router-create testrouter
neutron router-gateway-set testrouter floating
neutron router-interface-add testrouter testsubnet
nova boot --flavor m1.tiny --image cirros --nic net-id=a6a6c271-a391-4bff-9eda-79a97a8e1154 i1
neutron floatingip-create floating
nova floating-ip-associate i1 192.168.122.131
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22:22 default
- First, an image needs to be uploaded:
wget -qO - http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img | openstack image create cirros --public --container-format=bare --disk-format=qcow2
- Then we need to create a network:
openstack network create testnetwork
- Within the network, a subnet needs to be created:
neutron subnet-create --name testsubnet testnetwork 192.168.37.0/24
- Please note that a more recent version of OpenStack might support the openstack subnet create command as well.
- Let's create a router now:
neutron router-create testrouter
- Now set the router's default gateway by connecting it to a network:
neutron router-gateway-set testrouter floating
- And link the router to the subnet:
neutron router-interface-add testrouter testsubnet
- Now launch your instance:
nova boot --flavor m1.tiny --image cirros --nic net-id=a6a6c271-a391-4bff-9eda-79a97a8e1154 i1
- Create a floating IP:
neutron floatingip-create floating
nova floating-ip-associate i1 192.168.122.131
- Add rules to security group for icmp and ssh
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22:22 default
Saturday, 29 April 2017
Remove Already Merged Branches from Git
In case you need that, here is the draft:
git branch --merged master | sed -n 's,^ \+\(.*\)$,\1,p' | xargs git branch -d
git branch --merged master | sed -n 's,^ \+\(.*\)$,\1,p' | xargs git branch -d
Wednesday, 26 April 2017
Tmate cheatsheet
If you detached tmate, you might want to re-attach by:
tmate -S /tmp/tmate-0/DpfNjI attach
tmate -S /tmp/tmate-0/DpfNjI attach
Tuesday, 25 April 2017
iptables - deny connecting to a host
I would like to test a scenario where server A cannot reach server B. To establish this, I will add iptables rules on server A so ssh connections fail. After some research (basically reading this article) I managed to come up with the rules I need. Before doing anything it is good to know the state of the system. Use
iptables -S
to find out existing rules on your system. To block connections to ssh, use:
iptables -A OUTPUT -p tcp --dport ssh -d 192.168.124.82 -j REJECT
removing the rule is simple, list the rules with iptables -S and replace -A with -D:
iptables -D OUTPUT -d 192.168.124.82/32 -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable
iptables -S
to find out existing rules on your system. To block connections to ssh, use:
iptables -A OUTPUT -p tcp --dport ssh -d 192.168.124.82 -j REJECT
removing the rule is simple, list the rules with iptables -S and replace -A with -D:
iptables -D OUTPUT -d 192.168.124.82/32 -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable
Subscribe to:
Posts (Atom)