Ask Your Question

What's the correct way to specify username for glance?

asked 2013-05-20 04:07:21 -0500

dcqin gravatar image

updated 2013-05-21 00:33:49 -0500

smaffulli gravatar image

I want to ask, why when I execute

test@cloud:~$   sudo  glance image-create --is-public true --disk-format qcow2 --container-format bare --name "Ubuntu" < ubuntu-12.04-server-cloudimg-amd64-disk1.img

it prompts:

 You must provide a username via either --os-username or env[OS_USERNAME]

and when I specify --os-username glance, it prompts:

 test@cloud:~$ sudo  glance --os-username glance --os-password password  --os-tenant-id test image-create --is-public true --disk-format qcow2 --container-format bare --name "Ubuntu" --os-username glance < ubuntu-12.04-server-cloudimg-amd64-disk1.img
usage: glance [--version] [-d] [-v] [-k] [--cert-file CERT_FILE]
              [--key-file KEY_FILE] [--os-cacert <ca-certificate-file>]
              [--ca-file OS_CACERT] [--timeout TIMEOUT] [--no-ssl-compression]
              [-f] [--dry-run] [--ssl] [-H ADDRESS] [-p PORT]
              [--os-username OS_USERNAME] [-I OS_USERNAME]
              [--os-password OS_PASSWORD] [-K OS_PASSWORD]
              [--os-tenant-id OS_TENANT_ID] [--os-tenant-name OS_TENANT_NAME]
              [-T OS_TENANT_NAME] [--os-auth-url OS_AUTH_URL] [-N OS_AUTH_URL]
              [--os-region-name OS_REGION_NAME] [-R OS_REGION_NAME]
              [--os-auth-token OS_AUTH_TOKEN] [-A OS_AUTH_TOKEN]
              [--os-image-url OS_IMAGE_URL] [-U OS_IMAGE_URL]
              [--os-image-api-version OS_IMAGE_API_VERSION]
              [--os-service-type OS_SERVICE_TYPE]
              [--os-endpoint-type OS_ENDPOINT_TYPE] [-S OS_AUTH_STRATEGY]
              <subcommand> ...
glance: error: unrecognized arguments: --os-username glance

I get the same error even if I specify OS_USERNAME

test@cloud:~$ env |grep OS
LESSCLOSE=/usr/bin/lesspipe %s %s
test@cloud:~$ sudo glance image-create --is-public true --disk-format qcow2 --container-format bare --name "Ubuntu" < ubuntu-12.04-server-c
You must provide a username via either --os-username or env[OS_USERNAME]
edit retag flag offensive close merge delete


Wrong command: sudo glance --os-username glance --os-password password... You have glance two times.

Alen Komljen gravatar imageAlen Komljen ( 2013-05-20 04:20:57 -0500 )edit

3 answers

Sort by ยป oldest newest most voted

answered 2013-05-20 04:19:33 -0500

You can create one file with login credentials e.g openstack with:

export OS_USERNAME=user
export OS_TENANT_NAME=default
export OS_PASSWORD=password
export OS_AUTH_URL=http://keystone_ip:5000/v2.0/
export OS_REGION_NAME=region_name

Then run below command to execute commands from a file in the current shell:

source openstack

After all is prepared try to run glance commands.

edit flag offensive delete link more


@dcqin you can update the question instead of posting more details where the 'Answer' should go :)

smaffulli gravatar imagesmaffulli ( 2013-05-21 00:31:21 -0500 )edit

answered 2013-07-27 17:49:56 -0500

Kui gravatar image

The root cause is "sudo".

sudo will run command as another user. when you run "sudo glance image-create ...", this command run as root, but your credentials file (which define OS_USERNAME, OS_PASSWORD etc.) is sourced for normal user, not for root, and so not for this command. The required variables are not defined while executing this command.

you can verify it using this command:

$ sudo env |grep OS_USERNAME

I think you will get nothing.

You can specify the --os-username in the "glance image-create" command line, but the other settings (e.g. "OS_AUTH_URL" ) are no defined. That is the reaons that the command will still fail.


There are two methods to resolve it:

1. Always using the "root" account to do the operation, no need "sudo".

e.g. under Ubuntu, you can run $ sudo su

the credential file is sourced for root, and glance command is run as root.

2. source the credential file in the command line:

supposing the credential file is : /home/kui/openrc

$ sudo sh /home/kui/openrc && env | grep OS_

so your command would be like this:

$ sudo sh /home/kui/openrc && glance image-create --is-public true --disk-format qcow2 --container-format bare --name "Ubuntu" < ubuntu-12.04-server-cloudimg-amd64-disk1.img

edit flag offensive delete link more


I just followed your instruction and success!

imgiant gravatar imageimgiant ( 2014-03-18 22:43:04 -0500 )edit

answered 2013-12-31 12:42:47 -0500

thewizardofOZ gravatar image

if your openrc file was not sourced correctly you can see that error message. Also I recommend to use su command and log on as root.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools


Asked: 2013-05-20 04:07:21 -0500

Seen: 12,305 times

Last updated: Dec 31 '13