How to check number of floating IPs available in a pool? - openstack

I am writing a script to create a VM on Openstack.
I may get error if floating IPs get exhausted in pool. How can I check if there are floating IPs available in that pool or not? Is there a way where openstack can automatically choose the pool from all available pools?

You have a choice of working from the API (using curl, for example) or using the openstack CLI, which is what you were using when you submitted this question. The CLI is easier for straight scripting. Here is how you query for floating IPs. Caveat: It is becoming very commonplace to use '-f json' output and then the 'jq' command for field querying. You can also use '-f csv' or '-f value' and parse using grep or sed. But, although you may not have done it before, I recommend trying json and jq. It is worth your time for exactly the problem you are solving.
(Be aware the "None" column is DISPLAY ONLY text. The actual stored field value is 'null'.)
Given:
[user#system ~]$ openstack floating ip list
+--------------------------------------+---------------------+------------------+--------------------------------------+
| ID | Floating IP Address | Fixed IP Address | Port |
+--------------------------------------+---------------------+------------------+--------------------------------------+
| 2492aa71-cadf-4011-9c4f-87f856cd2551 | 172.25.250.29 | 192.168.3.10 | 1e0b868b-8b3c-4e8d-8f11-d6ed15d0e750 |
| 74c9233e-1420-4681-aaa7-357843f48962 | 172.25.250.36 | None | None |
| f235dfae-a01c-4290-864d-89b83f9a8de9 | 172.25.250.37 | None | None |
+--------------------------------------+---------------------+------------------+--------------------------------------+
Which looks like this in json:
[stack#director ~]$ openstack floating ip list -f json
[
{
"Fixed IP Address": "192.168.3.10",
"ID": "2492aa71-cadf-4011-9c4f-87f856cd2551",
"Floating IP Address": "172.25.250.29",
"Port": "1e0b868b-8b3c-4e8d-8f11-d6ed15d0e750"
},
{
"Fixed IP Address": null,
"ID": "74c9233e-1420-4681-aaa7-357843f48962",
"Floating IP Address": "172.25.250.36",
"Port": null
},
{
"Fixed IP Address": null,
"ID": "f235dfae-a01c-4290-864d-89b83f9a8de9",
"Floating IP Address": "172.25.250.37",
"Port": null
}
]
Using 'jq' to parse this output, allow me to paraphrase in English first. Piping in jq is like piping in the bash shell.
So "take the whole array" | "select this-field equals this-value" | "return this other field". Could return multiple fields if wanted.
[user#system ~]$ openstack floating ip list -f json | jq '.[] | select(.["Fixed IP Address"] == null ) | .["Floating IP Address"] '
"172.25.250.36"
"172.25.250.37"
If you don't want the results in quotes, ask for raw output (-r for short).
[user#system ~]$ openstack floating ip list -f json | jq --raw-output '.[] | select(.["Fixed IP Address"] == null ) | .["Floating IP Address"]'
172.25.250.36
172.25.250.37
These are your available floating IPs. If you pull them into an array, you can query the array to see how many you have.
[user#system ~]$ floats=( $( openstack floating ip list -f json | jq --raw-output '.[] | select(.["Fixed IP Address"] == null ) | .["Floating IP Address"]' ) )
[user#system ~]$ echo ${#floats[#]}
2

You can see the documentation of scripting API you are using , but from the command line to list all floating IP addresses that are allocated to the current project, run:
$ openstack floating ip list
+--------------------------------------+---------------------+------------------+------+
| ID | Floating IP Address | Fixed IP Address | Port |
+--------------------------------------+---------------------+------------------+------+
| 760963b2-779c-4a49-a50d-f073c1ca5b9e | 172.24.4.228 | None | None |
| 89532684-13e1-4af3-bd79-f434c9920cc3 | 172.24.4.235 | None | None |
| ea3ebc6d-a146-47cd-aaa8-35f06e1e8c3d | 172.24.4.229 | None | None |
+--------------------------------------+---------------------+------------------+------+
you can then do some command line editing to extract the ip colmn and have an ip count.

Related

public endpoint for load-balancer service not found

I have an issue to list loadbalancers on open stack using cli
from#ge ~
$ openstack loadbalancer list
public endpoint for load-balancer service not found
from#ge ~
$ export | grep OS_
declare -x OS_AUTH_TYPE="password"
declare -x OS_AUTH_URL="http://192.168.20.33:5000/v3"
declare -x OS_IDENTITY_API_VERSION="3"
declare -x OS_PASSWORD="XXXXXX"
declare -x OS_PROJECT_NAME="project-name"
declare -x OS_TENANT_NAME="tenant-name"
declare -x OS_USERNAME="from"
declare -x OS_USER_DOMAIN_ID="default"
from#ge ~
$ echo "endpoint list" | openstack
You are not authorized to perform the requested action: identity:list_endpoints. (HTTP 403) (Request-ID: req-aec8b22e-d3ad-4116-b7bb-52545f641667)
I've tried to set OS_REGION_NAME to RegionOne, but I get the same result
Any tip ?
load-balancer service not found
It seems that the load balance service not work, have you deployment Octavia service successful?
identity:list_endpoints. (HTTP 403)
According to the official document, it's Forbidden about the authorization.
The identity was successfully authenticated but it is not authorized to perform the requested action.
Maybe there is a miss-configuration of the admin's roles in keystone, you should check it in database first.
Ok thanks for your answers.
I finally managed to play with load balancers using neutron cli:
$ neutron
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
(neutron) lbaas-loadbalancer-list
+--------------------------------------+------------------------+----------------+---------------------+----------+
| id | name | vip_address | provisioning_status | provider |
+--------------------------------------+------------------------+----------------+---------------------+----------+
| 00f3453d-8738-4eb6-b362-aefc8dfaeea6 | lb1 | 192.168.36.93 | ACTIVE | haproxy |
| 090e062d-d6cc-4ebe-bcbf-165d5c21051d | lb2 | 192.168.36.169 | ACTIVE | haproxy |
| 0c244567-8f49-4be0-9055-17fa903d4619 | lb3 | 192.168.36.43 | ACTIVE | haproxy |

Openstack Keystone Install Issues

When trying to create Keystone:
openstack domain create --description "An Example Domain" example
I get this return error below:
Could not clean up: 'ClientManager' object has no attribute
'sdk_connection'
I am not sure what this is in reference to...
following the Doc here https://docs.openstack.org//keystone/wallaby/doc-keystone.pdf
This means that you aren't authenticated.
stack#ubuntu:~/devstack$ openstack domain create --description "An Example Domain" example
Missing value auth-url required for auth plugin password
Could not clean up: 'ClientManager' object has no attribute 'sdk_connection'
If you are using devstack you can just source userrc_early inside the devstack folder.
stack#ubuntu:~/devstack$ source userrc_early
stack#ubuntu:~/devstack$ openstack domain create --description "An Example Domain" example
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | An Example Domain |
| enabled | True |
| id | 1ddc2084930d492dbe39680cda5ef660 |
| name | example |
| options | {} |
| tags | [] |
+-------------+----------------------------------+

How to restart ceilometer service

I changed pulling intervals in /etc/ceilometer/pipeline.yaml file from 600 to 60 and can't make the service to use new values. I restarted everything that relates to ceilometer in openstack-status command, but that did not work. Can somebody tell me the proper way how to do it?
I am using Openstack Liberty on Ubuntu 14.04 LTS
root#OS1:~# openstack service list
+----------------------------------+------------+---------------+
| ID | Name | Type |
+----------------------------------+------------+---------------+
| 056fcccaad5c4991a8a0da199ed1d737 | cinderv2 | volumev2 |
| 483a0cd1ba79430690a8960ae3d40222 | glance | image |
| 5c704fc9253e4c15895589eb19fab2ac | keystone | identity |
| 92bfcfb417314e80a43e6e7d4d21f99b | nova | compute |
| a7a3809d73674d3da3fbe8030b47055a | horizon | dashboard |
| c21b5e3c9d68417cb11df60d72f9bb58 | heat | orchestration |
| c7030edb082346328a715b00098b974a | neutron | network |
| d331f5360e2b4d3a854e7f47107a9421 | ec2 | ec2 |
| f0a22f827bed43dbbc43822abfc3e3e0 | ceilometer | metering |
+----------------------------------+------------+---------------+
root#OS11:~# openstack-status
.
.
.
== Ceilometer services ==
ceilometer-api: active
ceilometer-agent-central: active
ceilometer-agent-compute: inactive (disabled on boot)
ceilometer-collector: active
ceilometer-alarm-notifier: active
ceilometer-alarm-evaluator: active
ceilometer-agent-notification:active
.
.
.
Well, you need to restart ceilometer-agent-notification service because this service is responsible for transforming the data into samples in the ceilometer database.
Thus, systemctl restart ceilometer-agent-notification.service will help along with restarting other services.
Since ceilometer-agent-compute service is disabled, you just need to restart ceilometer-agent-central service on the node you have modified the config file.
sudo service ceilometer-agent-central restart
You might want to auto reload pipelines after you modify it, for that, you can set refresh_pipeline_cfg=True and a proper time for pipeline_polling_interval such as 120 seconds in /etc/ceilometer/ceilometer.conf.
Note, be careful when you enable auto reload, and only save pipeline config file after you are sure about the content is right (otherwise it might lose 1 polling period data)

Script with network settings

Hey there I want to write a script that will change the network profile settings (ifconfig, /etc/resolv.comf). Let the script retrieve and display the contents of the file with network profiles to root. The format of the database file will be in the form of: IP, IP Mask, Gateway. I've already done something but don't know if it's correct.
#!/bin/bash
IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
IPMask=$(/sbin/ifconfig eth0 | grep Mask | cut -d":" -f4)
Gateway=$(/sbin/ip route | awk '/default/ {print $3}')
echo "IP is : $IP"
echo "IP Mask is: $IPMask"
echo Gateway is: $Gateway"
The part I don't understand how to do is - Root interactively selects the network profile (by number), which is then activated. Any help please?

Passing Local IP as argument when running command line application in Unix

I have a command line application which I use and also have to pass my local ip address as an argument, like:
jekyll --url 'http://192.168.1.2:3000' --pygments --safe --server 3000 --auto
I would like to make the url argument get my ip automatically, since I am always on different networks and get different loal ip addresses.
so I can use this alias in my .bashrc
alias jkl="jekyll --url 'http://$IP:3000' --pygments --safe --server 3000 --auto"
where $IP would be my local ip adress acquired dynamically.
Is there any way to do it?
First, use double quotes instead of single quotes around your $IP variable or else it won't interpolate the value
#!/bin/bash
# tested on bash 4
while read -r line
do
case "$line" in
"inet "* )
line="${line/inet /}"
line="${line%% *}"
if [[ ! $line =~ ^(127|172) ]] ;then
IP="$line"
echo "IP: $IP"
fi
;;
esac
done < <(ifconfig)
echo jekyll --url "http://$IP:3000" --pygments --safe --server 3000 --auto
Note that you will have a few different IPs in the output. Choose the one that fits your requirement most.
A computer does not necessarily have "a local IP address", there are often several. For instance, you typically have the localhost address (127.0.0.1), and one or more "true" externally visible addresses. It's hard for an automated solution to know which one to pick.
One easy solution is perhaps to hard-code the "eth0" interface (or whatever the name is of your most typical interface).
On Linux, you could use something like this:
$ ifconfig | grep -A1 eth0 | cut -d: -f2 | cut -d ' ' -f1 | grep \\.
192.168.0.8
So to stuff this into a variable (assuming bash) you would use
MY_IP=$(ifconfig | grep -A1 eth0 | cut -d: -f2 | cut -d ' ' -f1 | grep \\.)
Note that this hard-codes the interface name as eth0.

Resources