+
+
+def update_nw_subnet_port_quota(neutron_client, tenant_id, nw_quota,
+ subnet_quota, port_quota):
+ json_body = {"quota": {
+ "network": nw_quota,
+ "subnet": subnet_quota,
+ "port": port_quota
+ }}
+
+ try:
+ neutron_client.update_quota(tenant_id=tenant_id,
+ body=json_body)
+ return True
+ except Exception as e:
+ logger.error("Error [update_nw_subnet_port_quota(neutron_client,"
+ " '%s', '%s', '%s', '%s')]: %s" %
+ (tenant_id, nw_quota, subnet_quota, port_quota, e))
+ return False
+
+
+def update_instance_quota_class(nova_client, instances_quota):
+ try:
+ nova_client.quota_classes.update("default", instances=instances_quota)
+ return True
+ except Exception as e:
+ logger.error("Error [update_instance_quota_class(nova_client,"
+ " '%s' )]: %s" % (instances_quota, e))
+ return False
+
+
+def get_neutron_quota(neutron_client, tenant_id):
+ try:
+ return neutron_client.show_quota(tenant_id=tenant_id)['quota']
+ except Exception as e:
+ logger.error("Error in getting neutron quota for tenant "
+ " '%s' )]: %s" % (tenant_id, e))
+ raise
+
+
+def get_nova_instances_quota(nova_client):
+ try:
+ return nova_client.quota_classes.get("default").instances
+ except Exception as e:
+ logger.error("Error in getting nova instances quota: %s" % e)
+ raise
+
+
+def get_ovs_groups(compute_node_list, ovs_br_list, of_protocol="OpenFlow13"):
+ """
+ Gets, as input, a list of compute nodes and a list of OVS bridges
+ and returns the command console output, as a list of lines, that
+ contains all the OVS groups from all bridges and nodes in lists.
+ """
+ cmd_out_lines = []
+ for compute_node in compute_node_list:
+ for ovs_br in ovs_br_list:
+ if ovs_br in compute_node.run_cmd("sudo ovs-vsctl show"):
+ ovs_groups_cmd = ("sudo ovs-ofctl dump-groups {} -O {} | "
+ "grep group".format(ovs_br, of_protocol))
+ cmd_out_lines += (compute_node.run_cmd(ovs_groups_cmd).strip().
+ split("\n"))
+ return cmd_out_lines