Traditionally network device names in linux started with eth0/wlan0 where number 0 was incremented for each additional device. Problem with this naming was that device numbers did not match actual locations in computer.
Starting with v197 systemd/udev assigns predictable, stable network interface names for all local Ethernet, WLAN and WWAN interfaces. Naming is based on firmware, topology and location information.
Advantage of this approach is that the names are fully automatic, predictable and they stay fixed even if the hardware is removed or added. This allows hardware to be replaced without network cards being renamed.
Device naming is following the schemes:
o = onboard device
s = PCI hotplug
x = MAC address
P = PCI domain
p = PCI bus number
s = slot number
For example device enp0s3 would be Ethernet device in PCI bus 0 slot 3.
Ethernet device named by MAC address would start with en followed by x and MAC address (f.e. enx00112233445566).
PCI hotplug Ethernet device would start with en followed by s and the slot number, followed by f and the function number for cards that have more than one function (f.e. ens1f4).
Colection of Openstack resources that work together as three-tier application is called a stack. Stack uses openstack resources like instances, networks, volumes and objects, and other elements. The application runs on a stack.
Stack can be set-up via CLI or Horizon GUI which will send API request to various Openstack services (Keystone, Nova, Neutron, Cinder, Swift, Glance …).
Heat is the Openstack orchestration service that sends these API requests automatically. Stack description is taken by heat and interpreted to API requests. Heat accepts AWS Cloudformation templates written in JSON, but heat has it’s own native format called Heat Orchestration Template (HOT) based on YAML.
Create simple stack with heat orchestration template:
Retrieve all parameter functions supported by Openstack version:
openstack orchestration template version list
+--------------------------------------+------+
| version | type |
+--------------------------------------+------+
| AWSTemplateFormatVersion.2010-09-09 | cfn |
| HeatTemplateFormatVersion.2012-12-12 | cfn |
| heat_template_version.2013-05-23 | hot |
| heat_template_version.2014-10-16 | hot |
| heat_template_version.2015-04-30 | hot |
| heat_template_version.2015-10-15 | hot |
| heat_template_version.2016-04-08 | hot |
| heat_template_version.2016-10-14 | hot |
+--------------------------------------+------+
openstack orchestration template function list heat_template_version.2016-10-14
+-----------------+-------------------------------------------------------------------------+
| functions | description |
+-----------------+-------------------------------------------------------------------------+
| list_join | A function for joining one or more lists of strings. |
| if | A function to return corresponding value based on condition evaluation. |
| yaql | A function for executing a yaql expression. |
| digest | A function for performing digest operations. |
| get_attr | A function for resolving resource attributes. |
| repeat | A function for iterating over a list of items. |
| resource_facade | A function for retrieving data in a parent provider template. |
| map_replace | A function for performing substitutions on maps. |
| str_replace | A function for performing string substitutions. |
| get_resource | A function for resolving resource references. |
| map_merge | A function for merging maps. |
| str_split | A function for splitting delimited strings into a list. |
| get_param | A function for resolving parameter references. |
| get_file | A function for including a file inline. |
+-----------------+-------------------------------------------------------------------------+
Parameters can be provided via command line with --parameter imgname=cirros-image keyname=erol-keypair Or combine several parameters under one option: --parameter "imgname=cirros-image; keyname=erol-keypair"
If you have a lot of parameters it is probably better to put them in a file again in YAML format, with single parameters key and parameter key value pairs under that key. For example create myparameters.yaml file with following contents:
In Openstack Ceilometer is the component that gathers data from the cloud and pre-processes it. It distinguishes between samples (CPU time) and events (creation of an instance). Resources, Meters and Samples are fundamental concepts in Ceilometer.
Samples are retrieved at regular intervals and if Ceilometar fails to get the sample it can be estimated by interpolation. Events are retrieved as they happen and cannot be estimated.
Ceilometer sends events to the a storage service, while samples are sent to a service named Gnocchi, which is optimized to handle large amount of time-series data.
Aodh gets measures from Gnocchi, checks whether certain conditions are met and triggers actions. This is the foundation for application auto-scaling.
Other uses for Gnocchi data are monitoring the health of the cloud and billing.
Ceilometer has three ways retrieving samples and events:
Services may voluntarily provide them by sending Ceilometer notification via Openstack’s messaging system. This is preferred way since it is based on internal knowledge that the service has about it’s resources and it is fast without much overhead and stress on the systems.
Ceilometer actively retrieves data via APIs which is a costly method for billing and alarming.
Ceilometer can get data by accessing sub-components of services such as the hypervisor that run the instances.
Second and third method are referred also as methods where Ceilometer “polls” the samples.
While Ceilometer has resources, meters and samples Gnocchi has resources, metrics and measures. Gnocchi resource corresponds to Ceilometer resource. Metric is roughly equivalent to a meter in Ceilometer. Gnocchi does not store every metric value it receives from Ceilomter, but rather it combines values and stores the results at regular intervals according to Archive policy.
Listing gnocchi resources, metrics, measures:
Resources:
gnocchi resource list gnocchi resource show UUID
Metrics:
gnocchi metric list* gnocchi metric show cpu --resource UUID
Measures:
gnocchi measures show cpu --resource UUID --start YYYY-MM-DDTHH:MM:SS+00:00
* Output will be empty for non-admin users.
Listing resources, metrics, measures with openstack client:
Resources:
openstack metric resource list openstack metric resource show UUID
Metrics:
openstack metric metric list* openstack metric metric show cpu --resource UUID
Measures:
openstack metric measures show cpu --resource UUID --start YYYY-MM-DDTHH:MM:SS+00:00
* Output will be empty for non-admin users.
Aggregation:
Server grouping:
openstack server create --property metering.server_group=Mail*
Metrics aggregation:
gnocchi measures aggregation --query server_group=Mail --resource-type=instance --aggregation mean -m cpu_util
* For gnocchi all servers with ‘–property metering.server_group=Mail’ can be considered tagged.
* For gnocchi all servers with ‘–property metering.server_group=Mail’ can be considered tagged. ** There is no option in horizon GUI to view events or statictics, but gnocchi visualisation can be provided by Grafana.
Example generating CPU and disk load and showing gnocchi measures:
Let the instances finish creating and leave them running for a while:
openstack server list
Show cpu usage measures from cpu-user server:
gnocchi measures show cpu.delta --resource-id SERVER_UUID 795 gnocchi measures show cpu_util --resource-id SERVER_UUID
Show disk usage measures from disk-user server:
gnocchi measures show disk.read.requests --resource-id SERVER_UUID gnocchi measures show disk.read.requests.rate --resource-id SERVER_UUID
* Files cpu.sh and disk.sh are your bash scripts to generate CPU load and disk load. ** Don’t forget to stop cpu-server and disk-server after you have finished, since they will continue to generate CPU and disk load.
Alarms:
An alarm has:
Type Condition: depends on type Evaluation window State: OK/Alarm/Insufficient Data Actions for state transitions
Condition example:
mean cpu_util > 60 all resources tagged server_group=Mail
openstack alarm list openstack alarm show ALARM_ID openstack alarm-history show ALARM_ID openstack alarm state get ALARM_ID openstack alarm update ALARM_ID ...
Volumes can not be smaller than 1GB, that is why –size 1 is used. * It is not posible to undo a delete operation ** Adding –type [VOLUME_TYPE] to create options
Volume types:
Volume operations:
openstack volume type create thin --property volume_backend_name=lvm --property lvm:provisioning=thin* openstack volume types openstack volume type show [NAME] openstack volume create --type thin --size 1 [thinvol] openstack volume list --long**
* In reality lvm backend does not have parameter provisioning, actually it has no parameters at all, but this “fake” property “thin” is used to show how types are used ** In order to see parameter type use the “–long” option
Openstack commands:
Nova commands:
Attaching and detaching volumes:
openstack server add volume SERVER_REF VOLUME_REF openstack server add volume --device /dev/vdc* SERVER_REF VOLUME_REF openstack server remove volume SERVER_REF VOLUME_REF
nova volume-attach SERVER_REF VOLUME_ID [DEVICE] nova volume-dettach SERVER_REF VOLUME_ID
nova boot myinstance --nic .. --flavor .. --block-device source=volume,id=VOLUME_ID,dest=volume, size=SIZE,bootindex=0 nova boot myinstance --nic .. --flavor .. --block-device source=image,id=IMAGE_ID,dest=volume, size=SIZE,bootindex=0 nova boot myinstance --nic .. --flavor .. --block-device source=snapshot,id=SNAPSHOT_ID,dest=volume, size=SIZE,bootindex=0
When instances are launched from images, instance’s internal disk is created from image and the instance boot from it’s that disk. Such internal disk is called ephemeral storage. It dissapears when instance is deleted. * Libvirt (QEMU and KVM) ignore ‘–device’ parameter and you are stuck with whatever device filename Nova assigns
*This command will fail on attached volumes, so ‘–force’ parameter must be specified. ** To backup attached volume add parameter ‘–force’ , or ‘–incremental’ which stores the difference between current volume and previous backup. Base for incremental backup is the backup with the most recent timestamp. *** Cinder client has ‘backup-create’ and ‘backup-restore’ commands. **** Other openstack commands include ‘delete/list/show/set’ to delete backup, list backups, show backup details and set backup properties respectively.
Add a security group and floating IP address and login:
openstack server add security group volserver-restored ssh openstack server add floating ip volserver 172.24.4.233 ssh -i mykey.pem username@172.24.4.233
Check that all files are restored:
ls -la /
* Backup process takes some time, and while working it is shown as ‘creating’ when completed it will show ‘available’. ** Initial backup should have ‘has_dependant_backups’ set to ‘True’ and ‘is_incremental’ set to ‘False’. *** Incremental backup should have ‘is_incremental’ set to ‘True’ and has no dependant backups so ‘has_dependant_backups’ is ‘False’. **** Incremental backup is always created from the backup with the latest timestamp, which in this case is our previous incremental backup who should have now ‘has_dependant_backups’ set to ‘True’. ***** System is now broken beyond repair. Something that I always wanted to do 🙂 ****** To restore to attached volume instance must be shutdown, that is why we are restoring to empty volume. ******* To enable volume backup option in the horizon dashboard ‘/etc/openstack-dashboard/local_settings’ should be edited and ‘OPENSTACK_CINDER_FEATURES = { ‘enable_backup’: False. }’ should be changed to ‘True’.
swift upload myphotos localdir/moon.jpg --object-name=moon.jpg
Show object details:
openstack show object myphotos moon.jpg
swift stat myphotos moon.jpg -v
Deleting an object:
openstack object delete myphotos moon.jpg ***
List containers and objects:
openstack container list openstack object list myphotos --long
swift list --lh swift list myphotos --lh
Downloading an object:
openstack object save myphotos sun/2020.jpg****
Downloading objects with wget:
wget --user demo --password ******** $OBJECT_URL
Setting Metadata:
openstack object store account set --property category=astronomy openstack container set --property type=pictures myphotos opestack object set --property location=japan myphotos moon.jpg
swift post -H "X-Remove-Object-Meta-Location: x"****** myphotos moon.jpg
* Swift upload command creates container if it does not exist. ** Name of the object created with openstack command can not be changed, while swift client can change the name. *** Deleted objects can not be undeleted. **** Will create direcotry ‘sun’ and store ‘2020.jpg’ in it. You could also specify an alternate local filename with ‘–file sun.jpg’ parameter. *****Setting an empty metadata item also deletes it, but is not documented. ****** String ‘Location’ is actually the attribute you want to remove from object and ‘x’ is to satisfy HTTP syntax and it is ignored.
Access control lists:
Permissions based on PROJECT:USER
demo:demo *:admin *:*
Permissions based on referrer:
.r:* .r:erol.name
Set ACLs:
swift post -r ACL CONTAINER swift post -w ACL CONTAINER
Clear ACLs:
swift post -r "" CONTAINER swift post -w "" CONTAINER
Downloading object with wget using auth-token header:
* TOKEN_UUID value is ‘Auth Token’ value shown with ‘swift stat -v myphotos moon.jpg” ** In oreder to allow listings of a container add parameter ‘.referrer:*,.rlistings’ instead of just ‘.referrer:*’.
Temporary URLs:
Create TempURL key:
openstack object store account set --property temp-url-key=abc123 openstack container set --property temp-url-key=abc123
Generate TempURL:
swift tempurl GET 86400 /v1/AUTH_..../myvideos/vid.mp4 abc123*
* To allow read access GET is used, 86400 is the validity of the temporary URL in seconds.
Large objects:
Upload object and segment it into smaller parts:
swift upload --segment-size=100M mycontainer bigobject*
Example:
swift upload --segment-size=1M big-container myvideo.mp4
Show object details:
openstack object list big-container --long openstack object show big-container myvideo.mp4 openstack object list big-container_segments --long openstack object list big-container_segments
Delete containers:
openstack container delete big-container** swift delete big-container***
* Any size objects can be segmented, but since limitation on object size is 5GB larger objects than this must be split into segments. Container ‘mycontainer’ in this case is empty it only has metadata. The actual data goes into second container whose name is derived from original container f.e. ‘mycontainer_segments’ where one object per segment is stored. ** Openstack will not delete container while there are segments in it. *** Swift client will delete the main container ‘big-container’ and all it’s segments, but it will not delete container ‘big-container_segments’.
I have decided to summarize in one page all useful Openstack commands. This post will be useful to anyone interested in learning Openstack cloud commands or use it as a daily reference.
Openstack commands:
Old equivalents:
General commands:
openstack image list openstack flavor list openstack network list openstack server list
glance image-list nova flavor-list neutron net-list nova list
Server commands:
openstack server show [SERVER] openstack server stop [SERVER] openstack server start [SERVER] openstack server delete [SERVER] openstack server image create [IMAGE]
nova show [SERVER] nova stop [SERVER] nova start [SERVER] nova delete [SERVER] nova image-create [IMAGE]
Server console commands:
openstack console log show openstack console url show
nova keypair-show [KEYPAIR] | grep Public | awk -F': ' '{print $2}' > ./.ssh/key.pub
nova keypair-show [KEYPAIR]
Metadata**:
Key-value pairs: openstack server create --property [KEY]=[VALUE] Script (any language): openstack server create --user-data [SCRIPT] Cloud-config file (yaml) openstack server create --user-data [FILE] File injection openstack server create --file [DEST_FILE]=[SRC_FILE]
nova boot --meta [KEY]=[VALUE]
nova boot --user-data [SCRIPT]
nova boot --user-data [FILE]
nova boot --file [DEST_FILE]=[SRC_FILE]
* Don’t forget to chmod 600 key.pem in order to protect it and make it usable by SSH command ** There can only be 1 user-data option, but many property and file options . Metadata is retrieved by process cloud-int in cloud images . Server requests with curl http://169.254.169.254 –> Metadata service (nova) which replies with data in JSON format <– (Restful API).
Openstack network related commands:
Security group:
openstack security group create [SEC_GROUP] openstack security group rule create --dst-port 12345 [SEC_GROUP]* openstack server add security group [SERVER] [SEC_GROUP] openstack security group rule list [SEC_GROUP] --long
Network:
openstack network list openstack network show [NETWORK] openstack network create [NETWORK] openstack network delete [NETWORK]
Subnet:
openstack subnet list openstack subnet show [SUBNET] openstack subnet create --network --subnet-range [CIDR] [SUBNET] openstack subnet delete [SUBNET]
Port:
openstack port list openstack port show [PORT] openstack port create --network [NETWORK] [PORT]** openstack port delete [PORT]
Floating IP:
openstack floating ip list openstack floating ip create [EXT_NET]*** openstack server add floating ip [SERVER] [IP_ADDRESS] openstack server remove floating ip [SERVER] [IP_ADDRESS] openstack floating ip delete [IP_ADDRESS] openstack floating ip set [IP_ADDRESS]***
Router:
openstack router create [ROUTER] openstack router show [ROUTER] openstack router delete [ROUTER] openstack router list set [ROUTER] gateway: neutron router-gateway-set [ROUTER] public clear [ROUTER] gateway: neutron router-gateway-clear [ROUTER] add private subnet to [ROUTER]: openstack router add subnet [ROUTER] private_subnet remove private subnet to [ROUTER]: openstack router remove subnet [ROUTER] private_subnet list [ROUTER] interfaces: openstack port list --router [ROUTER]
* You can add additional parameters here like –egress for outgoing traffic or –protocol [UDP|ICMP] ** You can associate floating ip with specific port by adding –port PORT *** You could also add –fixed-ip [subnet=SUBNET|ip-address=IP_ADDRESS]
* Yaml format text files that begin with #cloud-config and are executed by cloud-init process present in most cloud image files, but not in cirros. ** Works with all package managers if specific distro-package is not specified f.e. 2.7.3-0ubuntu3.1