import sys
import time
+from cinderclient import client as cinderclient
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
from glanceclient import client as glanceclient
from keystoneclient.v2_0 import client as keystoneclient
from neutronclient.v2_0 import client as neutronclient
from novaclient import client as novaclient
+logger = ft_logger.Logger("openstack_utils").getLogger()
+
# *********************************************
# CREDENTIALS
envvars = ('OS_USERNAME', 'OS_PASSWORD', 'OS_AUTH_URL', 'OS_TENANT_NAME')
for envvar in envvars:
if os.getenv(envvar) is None:
- print("'%s' is not exported as an env variable." % envvar)
+ logger.error("'%s' is not exported as an env variable." % envvar)
exit(-1)
# Unfortunately, each of the OpenStack client will request slightly
"auth_url": os.environ.get("OS_AUTH_URL"),
tenant: os.environ.get("OS_TENANT_NAME")
})
+ if os.getenv('OS_ENDPOINT_TYPE') is not None:
+ creds.update({
+ "endpoint_type": os.environ.get("OS_ENDPOINT_TYPE")
+ })
+ if os.getenv('OS_REGION_NAME') is not None:
+ creds.update({
+ "region_name": os.environ.get("OS_REGION_NAME")
+ })
cacert = os.environ.get("OS_CACERT")
if cacert is not None:
# each openstack client uses differnt kwargs for this
"ca_file": cacert})
creds.update({"insecure": "True", "https_insecure": "True"})
if not os.path.isfile(cacert):
- print ("WARNING: The 'OS_CACERT' environment variable is " +
- "set to %s but the file does not exist." % cacert)
+ logger.info("WARNING: The 'OS_CACERT' environment variable is "
+ "set to %s but the file does not exist." % cacert)
return creds
return env
+def get_credentials_for_rally():
+ creds = get_credentials("keystone")
+ admin_keys = ['username', 'tenant_name', 'password']
+ endpoint_types = [('internalURL', 'internal'),
+ ('publicURL', 'public'), ('adminURL', 'admin')]
+ if 'endpoint_type' in creds.keys():
+ for k, v in endpoint_types:
+ if creds['endpoint_type'] == k:
+ creds['endpoint_type'] = v
+ rally_conf = {"type": "ExistingCloud", "admin": {}}
+ for key in creds:
+ if key in admin_keys:
+ rally_conf['admin'][key] = creds[key]
+ else:
+ rally_conf[key] = creds[key]
+ return rally_conf
+
+
# *********************************************
# CLIENTS
# *********************************************
return novaclient.Client('2', **creds_nova)
+def get_cinder_client():
+ creds_cinder = get_credentials("cinder")
+ creds_cinder.update({
+ "service_type": "volume"
+ })
+ return cinderclient.Client('2', **creds_cinder)
+
+
def get_neutron_client():
creds_neutron = get_credentials("neutron")
return neutronclient.Client(**creds_neutron)
def get_glance_client():
keystone_client = get_keystone_client()
+ glance_endpoint_type = 'publicURL'
+ os_endpoint_type = os.getenv('OS_ENDPOINT_TYPE')
+ if os_endpoint_type is not None:
+ glance_endpoint_type = os_endpoint_type
glance_endpoint = keystone_client.service_catalog.url_for(
- service_type='image', endpoint_type='publicURL')
+ service_type='image', endpoint_type=glance_endpoint_type)
return glanceclient.Client(1, glance_endpoint,
token=keystone_client.auth_token)
instances = nova_client.servers.list(search_opts={'all_tenants': 1})
return instances
except Exception, e:
- print "Error [get_instances(nova_client)]:", e
+ logger.error("Error [get_instances(nova_client)]: %s" % e)
return None
try:
instance = nova_client.servers.get(instance.id)
return instance.status
- except:
- # print ("Error [get_instance_status(nova_client, '%s')]:" %
- # str(instance)), e
+ except Exception, e:
+ logger.error("Error [get_instance_status(nova_client)]: %s" % e)
return None
instance = nova_client.servers.find(name=instance_name)
return instance
except Exception, e:
- print ("Error [get_instance_by_name(nova_client, '%s')]:" %
- instance_name), e
+ logger.error("Error [get_instance_by_name(nova_client, '%s')]: %s"
+ % (instance_name, e))
return None
floating_ips = nova_client.floating_ips.list()
return floating_ips
except Exception, e:
- print "Error [get_floating_ips(nova_client)]:", e
+ logger.error("Error [get_floating_ips(nova_client)]: %s" % e)
return None
nodes.append(hypervisor.hypervisor_hostname)
return nodes
except Exception, e:
- print "Error [get_hypervisors(nova_client)]:", e
+ logger.error("Error [get_hypervisors(nova_client)]: %s" % e)
return None
def create_flavor(nova_client, flavor_name, ram, disk, vcpus):
try:
flavor = nova_client.flavors.create(flavor_name, ram, vcpus, disk)
+ try:
+ extra_specs = ft_utils.get_functest_config(
+ 'general.flavor_extra_specs')
+ flavor.update(extra_specs)
+ except ValueError:
+ # flavor extra specs are not configured, therefore skip the update
+ pass
+
except Exception, e:
- print ("Error [create_flavor(nova_client, '%s', '%s', '%s', "
- "'%s')]:" % (flavor_name, ram, disk, vcpus)), e
+ logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', "
+ "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e))
return None
return flavor.id
instance_name="functest-vm",
confdrive=True,
userdata=None,
- av_zone=''):
+ av_zone='',
+ fixed_ip=None,
+ files=None):
nova_client = get_nova_client()
try:
flavor = nova_client.flavors.find(name=flavor_name)
except:
- print("Error: Flavor '%s' not found. Available flavors are:" %
- flavor_name)
- print(nova_client.flavor.list())
- return -1
+ flavors = nova_client.flavors.list()
+ logger.error("Error: Flavor '%s' not found. Available flavors are: "
+ "\n%s" % (flavor_name, flavors))
+ return None
+ if fixed_ip is not None:
+ nics = {"net-id": network_id, "v4-fixed-ip": fixed_ip}
+ else:
+ nics = {"net-id": network_id}
if userdata is None:
instance = nova_client.servers.create(
name=instance_name,
flavor=flavor,
image=image_id,
- nics=[{"net-id": network_id}],
- availability_zone=av_zone
+ nics=[nics],
+ availability_zone=av_zone,
+ files=files
)
else:
instance = nova_client.servers.create(
name=instance_name,
flavor=flavor,
image=image_id,
- nics=[{"net-id": network_id}],
+ nics=[nics],
config_drive=confdrive,
userdata=userdata,
- availability_zone=av_zone
+ availability_zone=av_zone,
+ files=files
)
return instance
instance_name="",
config_drive=False,
userdata="",
- av_zone=''):
+ av_zone='',
+ fixed_ip=None,
+ files=None):
SLEEP = 3
VM_BOOT_TIMEOUT = 180
nova_client = get_nova_client()
instance_name,
config_drive,
userdata,
- av_zone)
-
+ av_zone=av_zone,
+ fixed_ip=fixed_ip,
+ files=files)
count = VM_BOOT_TIMEOUT / SLEEP
for n in range(count, -1, -1):
status = get_instance_status(nova_client, instance)
if status.lower() == "active":
return instance
elif status.lower() == "error":
- print("The instance %s went to ERROR status." % instance_name)
+ logger.error("The instance %s went to ERROR status."
+ % instance_name)
return None
time.sleep(SLEEP)
- print("Timeout booting the instance %s." % instance_name)
+ logger.error("Timeout booting the instance %s." % instance_name)
return None
fip_addr = ip_json['floatingip']['floating_ip_address']
fip_id = ip_json['floatingip']['id']
except Exception, e:
- print "Error [create_floating_ip(neutron_client)]:", e
+ logger.error("Error [create_floating_ip(neutron_client)]: %s" % e)
return None
return {'fip_addr': fip_addr, 'fip_id': fip_id}
nova_client.servers.add_floating_ip(server_id, floatingip_id)
return True
except Exception, e:
- print ("Error [add_floating_ip(nova_client, '%s', '%s')]:" %
- (server_id, floatingip_id)), e
+ logger.error("Error [add_floating_ip(nova_client, '%s', '%s')]: %s"
+ % (server_id, floatingip_id, e))
return False
nova_client.servers.force_delete(instance_id)
return True
except Exception, e:
- print "Error [delete_instance(nova_client, '%s')]:" % instance_id, e
+ logger.error("Error [delete_instance(nova_client, '%s')]: %s"
+ % (instance_id, e))
return False
nova_client.floating_ips.delete(floatingip_id)
return True
except Exception, e:
- print ("Error [delete_floating_ip(nova_client, '%s')]:" %
- floatingip_id), e
+ logger.error("Error [delete_floating_ip(nova_client, '%s')]:"
+ % (floatingip_id, e))
return False
for network in neutron_client.list_networks()['networks']:
if network['router:external']:
return network['name']
- return False
+ return None
def get_external_net_id(neutron_client):
for network in neutron_client.list_networks()['networks']:
if network['router:external']:
return network['id']
- return False
+ return None
def check_neutron_net(neutron_client, net_name):
network_dict = network['network']
return network_dict['id']
except Exception, e:
- print "Error [create_neutron_net(neutron_client, '%s')]:" % name, e
- return False
+ logger.error("Error [create_neutron_net(neutron_client, '%s')]: %s"
+ % (name, e))
+ return None
def create_neutron_subnet(neutron_client, name, cidr, net_id):
subnet = neutron_client.create_subnet(body=json_body)
return subnet['subnets'][0]['id']
except Exception, e:
- print ("Error [create_neutron_subnet(neutron_client, '%s', '%s', "
- "'%s')]:" % (name, cidr, net_id)), e
- return False
+ logger.error("Error [create_neutron_subnet(neutron_client, '%s', "
+ "'%s', '%s')]: %s" % (name, cidr, net_id, e))
+ return None
def create_neutron_router(neutron_client, name):
router = neutron_client.create_router(json_body)
return router['router']['id']
except Exception, e:
- print "Error [create_neutron_router(neutron_client, '%s')]:" % name, e
- return False
+ logger.error("Error [create_neutron_router(neutron_client, '%s')]: %s"
+ % (name, e))
+ return None
def create_neutron_port(neutron_client, name, network_id, ip):
port = neutron_client.create_port(body=json_body)
return port['port']['id']
except Exception, e:
- print ("Error [create_neutron_port(neutron_client, '%s', '%s', "
- "'%s')]:" % (name, network_id, ip)), e
- return False
+ logger.error("Error [create_neutron_port(neutron_client, '%s', '%s', "
+ "'%s')]: %s" % (name, network_id, ip, e))
+ return None
def update_neutron_net(neutron_client, network_id, shared=False):
neutron_client.update_network(network_id, body=json_body)
return True
except Exception, e:
- print ("Error [update_neutron_net(neutron_client, '%s', '%s')]:" %
- (network_id, str(shared))), e
+ logger.error("Error [update_neutron_net(neutron_client, '%s', '%s')]: "
+ "%s" % (network_id, str(shared), e))
return False
body=json_body)
return port['port']['id']
except Exception, e:
- print ("Error [update_neutron_port(neutron_client, '%s', '%s')]:" %
- (port_id, device_owner)), e
- return False
+ logger.error("Error [update_neutron_port(neutron_client, '%s', '%s')]:"
+ " %s" % (port_id, device_owner, e))
+ return None
def add_interface_router(neutron_client, router_id, subnet_id):
neutron_client.add_interface_router(router=router_id, body=json_body)
return True
except Exception, e:
- print ("Error [add_interface_router(neutron_client, '%s', '%s')]:" %
- (router_id, subnet_id)), e
+ logger.error("Error [add_interface_router(neutron_client, '%s', "
+ "'%s')]: %s" % (router_id, subnet_id, e))
return False
neutron_client.add_gateway_router(router_id, router_dict)
return True
except Exception, e:
- print ("Error [add_gateway_router(neutron_client, '%s')]:" %
- router_id), e
+ logger.error("Error [add_gateway_router(neutron_client, '%s')]: %s"
+ % (router_id, e))
return False
neutron_client.delete_network(network_id)
return True
except Exception, e:
- print ("Error [delete_neutron_net(neutron_client, '%s')]:" %
- network_id), e
+ logger.error("Error [delete_neutron_net(neutron_client, '%s')]: %s"
+ % (network_id, e))
return False
neutron_client.delete_subnet(subnet_id)
return True
except Exception, e:
- print ("Error [delete_neutron_subnet(neutron_client, '%s')]:" %
- subnet_id), e
+ logger.error("Error [delete_neutron_subnet(neutron_client, '%s')]: %s"
+ % (subnet_id, e))
return False
neutron_client.delete_router(router=router_id)
return True
except Exception, e:
- print ("Error [delete_neutron_router(neutron_client, '%s')]:" %
- router_id), e
+ logger.error("Error [delete_neutron_router(neutron_client, '%s')]: %s"
+ % (router_id, e))
return False
neutron_client.delete_port(port_id)
return True
except Exception, e:
- print "Error [delete_neutron_port(neutron_client, '%s')]:" % port_id, e
+ logger.error("Error [delete_neutron_port(neutron_client, '%s')]: %s"
+ % (port_id, e))
return False
body=json_body)
return True
except Exception, e:
- print ("Error [remove_interface_router(neutron_client, '%s', '%s')]:" %
- (router_id, subnet_id)), e
+ logger.error("Error [remove_interface_router(neutron_client, '%s', "
+ "'%s')]: %s" % (router_id, subnet_id, e))
return False
neutron_client.remove_gateway_router(router_id)
return True
except Exception, e:
- print ("Error [remove_gateway_router(neutron_client, '%s')]:" %
- router_id), e
+ logger.error("Error [remove_gateway_router(neutron_client, '%s')]: %s"
+ % (router_id, e))
return False
-def create_network_full(logger,
- neutron_client,
+def create_network_full(neutron_client,
net_name,
subnet_name,
router_name,
subnet_id = create_neutron_subnet(neutron_client, subnet_name,
cidr, network_id)
if not subnet_id:
- return False
+ return None
logger.debug("Subnet '%s' created successfully" % subnet_id)
logger.debug('Creating Router...')
router_id = create_neutron_router(neutron_client, router_name)
if not router_id:
- return False
+ return None
logger.debug("Router '%s' created successfully" % router_id)
logger.debug('Adding router to subnet...')
if not add_interface_router(neutron_client, router_id, subnet_id):
- return False
+ return None
logger.debug("Interface added successfully.")
logger.debug('Adding gateway to router...')
if not add_gateway_router(neutron_client, router_id):
- return False
+ return None
logger.debug("Gateway added successfully.")
return network_dic
+def create_shared_network_full(net_name, subnt_name, router_name, subnet_cidr):
+ neutron_client = get_neutron_client()
+
+ network_dic = create_network_full(neutron_client,
+ net_name,
+ subnt_name,
+ router_name,
+ subnet_cidr)
+ if network_dic:
+ if not update_neutron_net(neutron_client,
+ network_dic['net_id'],
+ shared=True):
+ logger.error("Failed to update network %s..." % net_name)
+ return None
+ else:
+ logger.debug("Network '%s' is available..." % net_name)
+ else:
+ logger.error("Network %s creation failed" % net_name)
+ return None
+ return network_dic
+
+
def create_bgpvpn(neutron_client, **kwargs):
# route_distinguishers
# route_targets
return neutron_client.create_network_association(bgpvpn_id, json_body)
+def create_router_association(neutron_client, bgpvpn_id, router_id):
+ json_body = {"router_association": {"router_id": router_id}}
+ return neutron_client.create_router_association(bgpvpn_id, json_body)
+
+
def update_bgpvpn(neutron_client, bgpvpn_id, **kwargs):
json_body = {"bgpvpn": kwargs}
return neutron_client.update_bgpvpn(bgpvpn_id, json_body)
+
+def delete_bgpvpn(neutron_client, bgpvpn_id):
+ return neutron_client.delete_bgpvpn(bgpvpn_id)
+
+
+def get_bgpvpn(neutron_client, bgpvpn_id):
+ return neutron_client.show_bgpvpn(bgpvpn_id)
+
+
+def get_bgpvpn_routers(neutron_client, bgpvpn_id):
+ return get_bgpvpn(neutron_client, bgpvpn_id)['bgpvpn']['routers']
+
+
+def get_bgpvpn_networks(neutron_client, bgpvpn_id):
+ return get_bgpvpn(neutron_client, bgpvpn_id)['bgpvpn']['networks']
+
# *********************************************
# SEC GROUPS
# *********************************************
'security_groups']
return security_groups
except Exception, e:
- print "Error [get_security_groups(neutron_client)]:", e
+ logger.error("Error [get_security_groups(neutron_client)]: %s" % e)
return None
secgroup = neutron_client.create_security_group(json_body)
return secgroup['security_group']
except Exception, e:
- print ("Error [create_security_group(neutron_client, '%s', '%s')]:" %
- (sg_name, sg_description)), e
- return False
+ logger.error("Error [create_security_group(neutron_client, '%s', "
+ "'%s')]: %s" % (sg_name, sg_description, e))
+ return None
def create_secgroup_rule(neutron_client, sg_id, direction, protocol,
'port_range_max': port_range_max,
'protocol': protocol}}
else:
- print ("Error [create_secgroup_rule(neutron_client, '%s', '%s', "
- "'%s', '%s', '%s', '%s')]:" % (neutron_client, sg_id, direction,
- port_range_min, port_range_max,
- protocol),
- " Invalid values for port_range_min, port_range_max")
+ logger.error("Error [create_secgroup_rule(neutron_client, '%s', '%s', "
+ "'%s', '%s', '%s', '%s')]:" % (neutron_client,
+ sg_id, direction,
+ port_range_min,
+ port_range_max,
+ protocol),
+ " Invalid values for port_range_min, port_range_max")
return False
try:
neutron_client.create_security_group_rule(json_body)
return True
except Exception, e:
- print ("Error [create_secgroup_rule(neutron_client, '%s', '%s', "
- "'%s', '%s', '%s', '%s')]:" % (neutron_client, sg_id, direction,
- port_range_min, port_range_max,
- protocol)), e
+ logger.error("Error [create_secgroup_rule(neutron_client, '%s', '%s', "
+ "'%s', '%s', '%s', '%s')]: %s" % (neutron_client,
+ sg_id,
+ direction,
+ port_range_min,
+ port_range_max,
+ protocol, e))
return False
-def create_security_group_full(logger, neutron_client,
+def create_security_group_full(neutron_client,
sg_name, sg_description):
sg_id = get_security_group_id(neutron_client, sg_name)
if sg_id != '':
sg_description)
if not SECGROUP:
logger.error("Failed to create the security group...")
- return False
+ return None
sg_id = SECGROUP['id']
if not create_secgroup_rule(neutron_client, sg_id,
'ingress', 'icmp'):
logger.error("Failed to create the security group rule...")
- return False
+ return None
logger.debug("Adding SSH rules in security group '%s'..."
% sg_name)
if not create_secgroup_rule(
neutron_client, sg_id, 'ingress', 'tcp', '22', '22'):
logger.error("Failed to create the security group rule...")
- return False
+ return None
if not create_secgroup_rule(
neutron_client, sg_id, 'egress', 'tcp', '22', '22'):
logger.error("Failed to create the security group rule...")
- return False
+ return None
return sg_id
nova_client.servers.add_security_group(instance_id, secgroup_id)
return True
except Exception, e:
- print ("Error [add_secgroup_to_instance(nova_client, '%s', '%s')]: " %
- (instance_id, secgroup_id)), e
+ logger.error("Error [add_secgroup_to_instance(nova_client, '%s', "
+ "'%s')]: %s" % (instance_id, secgroup_id, e))
return False
body=json_body)
return True
except Exception, e:
- print ("Error [update_sg_quota(neutron_client, '%s', '%s', "
- "'%s')]:" % (tenant_id, sg_quota, sg_rule_quota)), e
+ logger.error("Error [update_sg_quota(neutron_client, '%s', '%s', "
+ "'%s')]: %s" % (tenant_id, sg_quota, sg_rule_quota, e))
return False
neutron_client.delete_security_group(secgroup_id)
return True
except Exception, e:
- print ("Error [delete_security_group(neutron_client, '%s')]:" %
- secgroup_id), e
+ logger.error("Error [delete_security_group(neutron_client, '%s')]: %s"
+ % (secgroup_id, e))
return False
images = nova_client.images.list()
return images
except Exception, e:
- print "Error [get_images]:", e
+ logger.error("Error [get_images]: %s" % e)
return None
def create_glance_image(glance_client, image_name, file_path, disk="qcow2",
- container="bare", public=True, logger=None):
+ container="bare", public=True):
if not os.path.isfile(file_path):
- print "Error: file " + file_path + " does not exist."
- return False
+ logger.error("Error: file %s does not exist." % file_path)
+ return None
try:
image_id = get_image_id(glance_client, image_name)
if image_id != '':
if logger:
logger.info("Creating image '%s' from '%s'..." % (image_name,
file_path))
+ try:
+ properties = ft_utils.get_functest_config(
+ 'general.image_properties')
+ except ValueError:
+ # image properties are not configured
+ # therefore don't add any properties
+ properties = {}
with open(file_path) as fimage:
image = glance_client.images.create(name=image_name,
is_public=public,
disk_format=disk,
container_format=container,
+ properties=properties,
data=fimage)
image_id = image.id
return image_id
except Exception, e:
- print ("Error [create_glance_image(glance_client, '%s', '%s', "
- "'%s')]:" % (image_name, file_path, str(public))), e
- return False
+ logger.error("Error [create_glance_image(glance_client, '%s', '%s', "
+ "'%s')]: %s" % (image_name, file_path, str(public), e))
+ return None
+
+
+def get_or_create_image(name, path, format):
+ image_exists = False
+ glance_client = get_glance_client()
+
+ image_id = get_image_id(glance_client, name)
+ if image_id != '':
+ logger.info("Using existing image '%s'..." % name)
+ image_exists = True
+ else:
+ logger.info("Creating image '%s' from '%s'..." % (name, path))
+ image_id = create_glance_image(glance_client, name, path, format)
+ if not image_id:
+ logger.error("Failed to create a Glance image...")
+ else:
+ logger.debug("Image '%s' with ID=%s created successfully."
+ % (name, image_id))
+
+ return image_exists, image_id
def delete_glance_image(nova_client, image_id):
nova_client.images.delete(image_id)
return True
except Exception, e:
- print ("Error [delete_glance_image(nova_client, '%s')]:" % image_id), e
+ logger.error("Error [delete_glance_image(nova_client, '%s')]: %s"
+ % (image_id, e))
return False
volumes = cinder_client.volumes.list(search_opts={'all_tenants': 1})
return volumes
except Exception, e:
- print "Error [get_volumes(cinder_client)]:", e
+ logger.error("Error [get_volumes(cinder_client)]: %s" % e)
return None
volume_types = [vt for vt in volume_types if vt.is_public]
return volume_types
except Exception, e:
- print "Error [list_volume_types(cinder_client)]:", e
+ logger.error("Error [list_volume_types(cinder_client)]: %s" % e)
return None
volume_type = cinder_client.volume_types.create(name)
return volume_type
except Exception, e:
- print "Error [create_volume_type(cinder_client, '%s')]:" % name, e
+ logger.error("Error [create_volume_type(cinder_client, '%s')]: %s"
+ % (name, e))
return None
cinder_client.quotas.update(tenant_id, **quotas_values)
return True
except Exception, e:
- print ("Error [update_cinder_quota(cinder_client, '%s', '%s', '%s'"
- "'%s')]:" % (tenant_id, vols_quota,
- snapshots_quota, gigabytes_quota)), e
+ logger.error("Error [update_cinder_quota(cinder_client, '%s', '%s', "
+ "'%s' '%s')]: %s" % (tenant_id, vols_quota,
+ snapshots_quota, gigabytes_quota, e))
return False
try:
cinder_client.volumes.detach(volume_id)
except:
- print "Error:", sys.exc_info()[0]
+ logger.error(sys.exc_info()[0])
cinder_client.volumes.force_delete(volume_id)
else:
cinder_client.volumes.delete(volume_id)
return True
except Exception, e:
- print ("Error [delete_volume(cinder_client, '%s', '%s')]:" %
- (volume_id, str(forced))), e
+ logger.error("Error [delete_volume(cinder_client, '%s', '%s')]: %s"
+ % (volume_id, str(forced), e))
return False
cinder_client.volume_types.delete(volume_type)
return True
except Exception, e:
- print ("Error [delete_volume_type(cinder_client, '%s')]:" %
- volume_type), e
+ logger.error("Error [delete_volume_type(cinder_client, '%s')]: %s"
+ % (volume_type, e))
return False
tenants = keystone_client.tenants.list()
return tenants
except Exception, e:
- print "Error [get_tenants(keystone_client)]:", e
+ logger.error("Error [get_tenants(keystone_client)]: %s" % e)
return None
users = keystone_client.users.list()
return users
except Exception, e:
- print "Error [get_users(keystone_client)]:", e
+ logger.error("Error [get_users(keystone_client)]: %s" % e)
return None
enabled=True)
return tenant.id
except Exception, e:
- print ("Error [create_tenant(cinder_client, '%s', '%s')]:" %
- (tenant_name, tenant_description)), e
- return False
+ logger.error("Error [create_tenant(keystone_client, '%s', '%s')]: %s"
+ % (tenant_name, tenant_description, e))
+ return None
def create_user(keystone_client, user_name, user_password,
enabled=True)
return user.id
except Exception, e:
- print ("Error [create_user(keystone_client, '%s', '%s', '%s'"
- "'%s')]:" % (user_name, user_password, user_email, tenant_id),
- e)
- return False
+ logger.error("Error [create_user(keystone_client, '%s', '%s', '%s'"
+ "'%s')]: %s" % (user_name, user_password,
+ user_email, tenant_id, e))
+ return None
def add_role_user(keystone_client, user_id, role_id, tenant_id):
keystone_client.roles.add_user_role(user_id, role_id, tenant_id)
return True
except Exception, e:
- print ("Error [add_role_user(keystone_client, '%s', '%s'"
- "'%s')]:" % (user_id, role_id, tenant_id)), e
+ logger.error("Error [add_role_user(keystone_client, '%s', '%s'"
+ "'%s')]: %s " % (user_id, role_id, tenant_id, e))
return False
keystone_client.tenants.delete(tenant_id)
return True
except Exception, e:
- print "Error [delete_tenant(keystone_client, '%s')]:" % tenant_id, e
+ logger.error("Error [delete_tenant(keystone_client, '%s')]: %s"
+ % (tenant_id, e))
return False
keystone_client.users.delete(user_id)
return True
except Exception, e:
- print "Error [delete_user(keystone_client, '%s')]:" % user_id, e
+ logger.error("Error [delete_user(keystone_client, '%s')]: %s"
+ % (user_id, e))
return False