def attach_l2(l2_uuid, cluster_uuid, session_uuid=None): action = api_actions.AttachL2NetworkToClusterAction() action.clusterUuid = cluster_uuid action.l2NetworkUuid = l2_uuid evt = acc_ops.execute_action_with_session(action, session_uuid) test_util.action_logger("Attach [L2:] %s to [Cluster:] %s " \ % (l2_uuid, cluster_uuid)) return evt
def _add_cluster(action, zone_ref, cluster, cluster_ref): evt = action.run() deploy_logger(jsonobject.dumps(evt)) cinv = evt.inventory try: if xmlobject.has_element(cluster, 'primaryStorageRef'): for pref in xmlobject.safe_list(cluster.primaryStorageRef): ps_name = generate_dup_name(generate_dup_name(pref.text_, zone_ref, 'z'), cluster_ref, 'c') pinvs = res_ops.get_resource(res_ops.PRIMARY_STORAGE, session_uuid, name=ps_name) pinv = get_first_item_from_list(pinvs, 'Primary Storage', ps_name, 'Cluster') action_ps = api_actions.AttachPrimaryStorageToClusterAction() action_ps.sessionUuid = session_uuid action_ps.clusterUuid = cinv.uuid action_ps.primaryStorageUuid = pinv.uuid evt = action_ps.run() deploy_logger(jsonobject.dumps(evt)) except: exc_info.append(sys.exc_info()) if cluster.allL2NetworkRef__ == 'true': # find all L2 network in zone and attach to cluster cond = res_ops.gen_query_conditions('zoneUuid', '=', action.zoneUuid) l2_count = res_ops.query_resource_count(res_ops.L2_NETWORK, cond, session_uuid) l2invs = res_ops.query_resource_fields(res_ops.L2_NETWORK, [{'name': 'zoneUuid', 'op': '=', 'value': action.zoneUuid}], session_uuid, ['uuid'], 0, l2_count) else: l2invs = [] if xmlobject.has_element(cluster, 'l2NetworkRef'): for l2ref in xmlobject.safe_list(cluster.l2NetworkRef): l2_name = generate_dup_name(generate_dup_name(l2ref.text_, zone_ref, 'z'), cluster_ref, 'c') cond = res_ops.gen_query_conditions('zoneUuid', '=', action.zoneUuid) cond = res_ops.gen_query_conditions('name', '=', l2_name, cond) l2inv = res_ops.query_resource_fields(res_ops.L2_NETWORK, cond, session_uuid, ['uuid']) if not l2inv: raise DeployError("Can't find l2 network [%s] in database." % l2_name) l2invs.extend(l2inv) for l2inv in l2invs: action = api_actions.AttachL2NetworkToClusterAction() action.sessionUuid = session_uuid action.clusterUuid = cinv.uuid action.l2NetworkUuid = l2inv.uuid thread = threading.Thread(target=_thread_for_action, args=(action,)) wait_for_thread_queue() thread.start()