A command line tool to manage IBM PowerVC
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
conf First commit Oct 25, 2016
jsons First commit Oct 25, 2016
README.md Update README.md Oct 25, 2016
pvcctl fixing json directory Oct 28, 2016

README.md

pvcctl

pvcctl is a tool that allows you to manage IBM's PowerVC in command line. The tool allows you to use non standard calls to the API (ibm grow volume, finish onboard, entitlement capacity, vm onboarding, and so on). You can also use it to write your own scripts based on pvcctl. For instance you can write a ksh script calling pvcctl to orchestrate your powervc deployments. The tool is not perfect. It surely can be improved (please email me to benoit.creau@chmod666.org).

about coding

I'm not a developper. I'm not even a python developper but I try to do my best. The script was linted and corrected with pep8 and autopep8. If you have any advice about my coding style please email me. If you want new functions in the tool please email me. This tool was developed and redeveloped over and over and over. I first started playing with python sockets, then used the librequest api and finally decided that using OpenStack python api will be better than everything else. You know ... I'm dumb, I need to learn step by step. The advantage of doing that is that I'm now 100% aware about the Openstack api. Good point.

thanks

Thank to Matthew Edmonds from the IBM PowerVC team. He helped me a lot answering to my questions about the OpenStack api. Without him this tool would not have existed. So thank you.

writing your rc file

Create a rc file.
Replace OS_USERNAME and OS_PASSWORD by your OpenStack credentials.
Set the OS_AUTH_URL and OS_IMAGE_ENDPOINT to your OpenStack endpoint.
Set the OS_TENANT_NAME to your OpenStack tenant.
The crt file must be copied from your PowerVC instance located in /etc/pki/tls/certs/powervc.crt.

# cat powervc_powervc
export OS_AUTH_URL=https://mypowervc:5000/v3/
export OS_USERNAME=root
export OS_PASSWORD=root
export OS_TENANT_NAME=ibm-default
export OS_REGION_NAME=RegionOne
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_CACERT=~/mypowervc.crt
export OS_IMAGE_ENDPOINT=https://mypowervc.fr.net.intra:9292/
export NOVACLIENT_DEBUG=0

enabling or disabling debug

# export NOVACLIENT_DEBUG=1
# export NOVACLIENT_DEBUG=0

prerequistes

tabular

# pip install tabular

pep8

This tool was linted by pep8 and autopep8.

# pip install pep8
# pip install autopep8

sourcing powervc instance

You need to source the right file for the PowerVC instance you want to work on.
Generally these files are .rc files.
Put theses rc files in the conf directory.

# source conf/mypowervc.rc

using the tool

help

Global help.

# pvcctl help

vm help.

# pvcctl vm help

volume help.

# pvcctl volume help

network help.

# pvcctl network help

volumes

Here are the commands available for volumes.
List all the volumes on the OpenStack.

# pvcctl volume list

List all the storage providers.

# pvcctl volume list_sp

Get the state of a volume.

# pvcctl volume getstate vol=myvol

Get states of multiples volumes.
Will get the state of all the volumes containing the string "vols=string".

# pvcctl volume get_state vols=filter

Create a volume.
Give the name, the storage provider and the size.

# pvcctl volume create provider=mystorageprovider name=volume_test size=10

Grow a volume.
Give the name, and the new size (in total).

# pvcctl volume grow vol=test_volume size=50

Share a volume.
Give the name of the volume.

# pvcctl volume share vol=test_volume

Unshare a volume.
Give the name of the volume.

# pvcctl volume unshare vol=test_volume

List manageable volumes on a given storage provider.

# pvcctl volume list_manageable provider=myssp

Onboard volumes.
Will onboard all the volumes containing the string "vols=string".

# pvcctl volume onboard provider=mystorageprovider vols=myvols

Unmanage volumes. Will unmanage all the volumes containing the string "vols=string".

# pvcctl volume unmanage provider=mystorageprovider voles=myvols

network

Here are the commands available for managing network.
Create a new network.
cidr must be written like this '10.10.20.20/24'.

# pvcctl network create name=newvlan id=666 cidr='10.10.20.20/24' dns1='8.8.8.8' dns2='8.8.9.9' gw='10.10.20.254'

Fix an SEA. Rules are hardcoded in the function. (check the script).
The code will search to match the name of the vlan with the vswitch id.
Vlan name must contains the name of the vswitch to use the function.
The fix_sea command will choose the SEA in the right vswitch for each host managed by the OpenStack.

# pvcctl network fix_sea vlan=vswitchname-myvlan

vm

Here are the commands available for managing vms.
Get the vlan name assiociated with this vm.

# pvcctl vm get_vlan vm=deckard

Rename the vm.
Give the new name.

# pvcctl vm rename vm=deckard new_name=priss

Set description on a vm.

# pvcctl vm set_description vm=deckard desc="We call it Voight-Kampff"

Migrate a vm to another host.
You must provide the serial id of the host where to migrate.

# pvcctl vm migrate vm=tyrell host=21AFF8V

List all the vm in the OpenStack.

# pvcctl vm list

Attach a volume to a vm.
Give the name of the volumes.

# pvcctl vm attach_vol vm=tyrell vol=myvol

List all vms with a warning health.

# pvcctl vm list_warning

List all vms with a 'OK' health and a OK 'state'.

# pvcctl vm list_ok

Create a vm.
You must provider all the args.
1. ip of the machine 2. maximum entitled capacity 3. name of the disks to attach at vm create (separated by comma) 4. name of the vm 5. weight of the vm 6. memory 7. minimum virtual processors 8. name of the image 9. name of the vlan 10. simplified remote restart (yes|no) 11. minimum memory 12. entitled capacity 13. user_data file to inject at vm creation (located in user_data) 14. virtual processors 15. maximum memory 16. maximum virtual processors 17. maximum virtual processors 18. name of the aggregate where to create the machine 19. storage connectivt group name 20. minmum entitled capacity

# pvcctl vm create ip='10.14.33.240' ec_max=1 ec_min=0.1 ec=0.1 vp=1 vp_min=1 vp_max=4 mem=4096 mem_min=1024 mem_max=8192 weight=240 name=bcubcu disks="death" scg=ssp vlan=vdct-3331 image=kitchen-aix72 aggregate=hg2 user_data=testvm srr=yes

Start a vm.

# pvcctl vm start vm=deckard

Stop a vm.

# pvcctl vm stop vm=deckard

Get the volume instance mapping (still in dev).

# pvcctl vm volume_instance_mapping vm=deckard

Count the number of volumes attached to a vm.

# pvvctl vm count_vols vm=deckard

Get the vms details.
1. Host of the vm. 2. Managment type. 3. Managment access.

# pvcctl vm get_host vm=deckard

Detach a volume from a vm.
Give the name of the volume.

# pvcctl vm detach_vol vm=deckard vol=myvol

Set the lun order of a VM.
pvcctl will search for 'boot' string in the name of the volumes attached to the vm.
pvcctl will search for 'data' string in the name of the volumes attached to the vm.
Then the lun order will set the boot lun on the first position.

# pvcctl vm lun_roder vm=deckard

Get the state of a vm.

# pvcctl vm get_state vm=deckard

List vms in shutoff state.

# pvcctl vm list_shutoff

Onboard a vm (manage it).
Give the name of the vm.
Give the serial number of the host where the vm is hosted.

# pvcctl vm onboard host=21FF8CV vm=myvm

Count the number of network interfaces attached to a vm.

# pvcctl vm count_ifaces vm=myvm

Resize a vm.
Mandatory args are:
1. ec: entitled capacity (0 means do not change it). 2. vp: virutal processors (0 means do not change it). 3. ram: memory in gb (0 means do not change it). 4. weight: weight (0 means do not change it). 5. vm: name of the vm.

# pvcctl vm resize vm=myvm ec=0 vp=2 ram=4096 weigh=140

List vm in error state.

# pvcctl vm list_error

Detach an interface from a vm.
Give the ip of the interface to detach. (delete the interface).

# pvcctl vm detach_iface vm=myvm ip='1.1.1.1'

List all running vms.

# pvcctl vm list_running

List all the vm for a host.
You must give the serial number of the host.

# pvcctl vm list_host host=21FF8CV

Attach multiple volumes to a vm.
All the luns containing the string "vols=string" will be attached to the vm.

# pvcctl vm attach_luns vols=wildcard

Unmanage a vm.

# pvcctl vm unmanage vm=deckard host=21FF8CV

List all critical vms.

# pvcctl vm list_critical

Get a list of host where a vm is able to migrate.

# pvcctl vmget_dest_hosts vm=myvm

Attach a network interface to a virtual machine. (create the interface).

# pvcctl vm attach_iface vm=myvm vlan=myvlan ip='10.11.12.13'

Introduction to Openstack python API

Using environmet variable.

All the rc files used in pvcctl contains OS_ variables. Here is how to implement this in python.
The OS_CA_CERT is a crt file.
For PowerVC this one can be found in /etc/pki/tls/certs/powervc.crt

from keystoneauth1.identity import v3
from keystoneauth1 import loading as ks_loading
from keystoneauth1 import session

[..]
    auth = v3.Password(auth_url=env['OS_AUTH_URL'],
                       username=env['OS_USERNAME'],
                       password=env['OS_PASSWORD'],
                       project_name=env['OS_TENANT_NAME'],
                       user_domain_id=env['OS_USER_DOMAIN_NAME'],
                       project_domain_id=env['OS_PROJECT_DOMAIN_NAME'])

    sess = session.Session(auth=auth, verify=env['OS_CACERT'])

Logging

To enable logging on python OpenStack API you need to create a logger object.

    # +------+
    # | logs |
    # +------+
    # init logger
    if env['NOVACLIENT_DEBUG'] == "1":
        logger = logging.getLogger('pvcctl')
        hdlr = logging.FileHandler(BASE_DIR + "/logs/pvcctl.log")
        logger.addHandler(hdlr)
        logger.setLevel(logging.DEBUG)

Once the logger is created you can use it to debug your call to the rest api.

        nova = client_nova.Client(
            2.19,
            session=sess,
            http_log_debug=True,
            logger=logger)

python novaclient: http://docs.openstack.org/developer/python-novaclient/api.html

# nova client
from novaclient import client as client_nova

nova = client_nova.Client(2.19, session=sess)

python neutronclient: http://docs.openstack.org/developer/python-neutronclient/usage/library.html

# neutron client
from neutronclient.v2_0 import client as client_neutron

neutron = client_neutron.Client(session=sess)

python cinderclient: http://docs.openstack.org/developer/python-cinderclient/

# cinder client
from cinderclient import client as client_cinder

cinder = client_cinder.Client(2.0, service_type="volume", session=sess)

If you want to use unsupported api calls you can do it this way.
For each api you can use:
1. get. 2. post. 3. delete. 4. put.

In case if you want to use an unsupported api call.
Use body= in case of a put/post.

                resp, body = nova.client.post(
                    "/host-network-mapping", body=mapping_json)