Home Ask Login Register

Developers Planet

Your answer is one click away!

Erik Sjölund February 2016

How to attach a Cloud Block Storage volume to an OnMetal server with pyrax?

I would like to automate the attachment of a Cloud Block Storage volume to an OnMetal server running CentOS 7 by writing a Python script that make uses of the pyrax Python module. Do you know how to do it?


Erik Sjölund February 2016

Attaching a Cloud Block Storage volume to an OnMetal server is a bit more complicated than attaching it to a normal Rackspace virtual server. That you will notice when you try to attach a Cloud Block Storage volume to an OnMetal server in the Rackspace web interface Cloud Control Panel, as you would see this text:

Note: When attaching volumes to OnMetal servers, you must log into the OnMetal server to set the initiator name, discover the targets and then connect to the target.

So you can attach the volume in the web interface but additionally you need to log in to the OnMetal server and run a few commands. The actual commands can be copy-and-pasted from the web interface into the terminal of the OnMetal server.

Also before detaching you need to run a command.

But the web interface is actually not needed. It can be done with the Python module pyrax.

First install the RPM package iscsi-initiator-utils on the OnMetal server

[root@server-01 ~]# yum -y install iscsi-initiator-utils

Assuming the volume_id and the server_id are known, this Python code first attaches the volume and then detaches the volume. Unfortunately, the mount_point argument attach_to_instance() is not working for OnMetal servers, so we would need to use the command lsblk -n -d before and after attaching the volume. By comparing the outputs we would then deduce the device name used for the attached volume. (The part to deduce the device name is not taken care of by the following Python code).

# Disclaimer: Use the script at your own Risk!                                                                                                                                    
import json
import os
import paramiko
import pyrax

# Repla 

Post Status

Asked in February 2016
Viewed 2,617 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life