service_type='standalone', version=version, verify=verify, log=log) result = vca_tenant.login(password=password, org=tenant_org, org_url=tenant_org_url) assert (result) user_id = vca_tenant.vcloud_session.session.get_userId().split(':')[-1] user_name = vca_tenant.vcloud_session.username result = vca_tenant.login(token=vca_tenant.token, org=tenant_org, org_url=vca_tenant.vcloud_session.org_url) assert (result) task = Task(session=vca_tenant.vcloud_session, verify=verify, log=log) assert (task) catalog = 'mycatalog' template = 'kube.ova' t = vca_tenant.create_vapp(tenant_vdc, vm_name, template, catalog, vm_name=vm_name) assert (t) task_id = t.get_id().split(':')[-1] wait_for_task(task, task_id) the_vdc = vca_tenant.get_vdc(tenant_vdc)
def cluster(cmd_proc, operation, cluster_name, cluster_id, node_count, vdc, network_name): """Operations with Container Service Extension""" result = cmd_proc.re_login() if not result: utils.print_error('Not logged in', cmd_proc) sys.exit(1) if vdc is None: vdc = cmd_proc.vdc_name the_vdc = cmd_proc.vca.get_vdc(vdc) if the_vdc is None: utils.print_error("VDC not found '%s'" % vdc, cmd_proc) sys.exit(1) if cmd_proc.vca.vcloud_session and \ cmd_proc.vca.vcloud_session.organization: cse = Cluster(session=cmd_proc.vca.vcloud_session, verify=cmd_proc.verify, log=cmd_proc.vca.log) if 'list' == operation: headers = ['Name', 'Id', 'Status', 'Leader IP', 'Masters', 'Nodes'] table1 = [] try: clusters = cse.get_clusters() except Exception: utils.print_error("can't get list of clusters", cmd_proc, cse) sys.exit(1) n = 1 for cluster in clusters: cluster['name'] = 'k8s-cluster-%s' % n n += 1 table1.append([ cluster['name'], cluster['cluster_id'], cluster['status'], cluster['leader_endpoint'], len(cluster['master_nodes']), len(cluster['nodes']), ]) table = sorted(table1, key=operator.itemgetter(0), reverse=False) utils.print_table( "Available clusters in VDC '%s', profile '%s':" % (vdc, cmd_proc.profile), headers, table, cmd_proc) elif 'create' == operation: utils.print_message("creating cluster '%s'" % (cluster_name)) try: r = cse.create_cluster(vdc, network_name, cluster_name, node_count) t = Task(session=cmd_proc.vca.vcloud_session, verify=cmd_proc.verify, log=cmd_proc.vca.log) task = t.get_task(r['task_id']) utils.display_progress( task, cmd_proc, cmd_proc.vca.vcloud_session.get_vcloud_headers()) except Exception: utils.print_error("can't create cluster", cmd_proc, cse) sys.exit(1) elif 'delete' == operation: utils.print_message("deleting cluster with id '%s'" % (cluster_id)) try: r = cse.delete_cluster(cluster_id) t = Task(session=cmd_proc.vca.vcloud_session, verify=cmd_proc.verify, log=cmd_proc.vca.log) task = t.get_task(r['task_id']) utils.display_progress( task, cmd_proc, cmd_proc.vca.vcloud_session.get_vcloud_headers()) except Exception: utils.print_error("can't delete cluster", cmd_proc, cse) sys.exit(1) else: utils.print_error('not implemented', cmd_proc) sys.exit(1) cmd_proc.save_current_config()
org=tenant_org, org_url=vca_tenant.vcloud_session.org_url) print(result) namespace = 'cpsbu.cse' operation_name = 'create_cluster' operation_description = 'create cluster' org_id = vca_tenant.vcloud_session.organization.get_id().split(':')[-1] org_name = vca_tenant.vcloud_session.organization.get_name() owner_href = 'urn:cse:cluster:77a8c02f-643c-4ba4-9517-f93f08932422' owner_name = 'cluster-77a8c02f' owner_type = 'application/cpsbu.cse.cluster+xml' progress = 1 status = 'running' print((status, namespace, operation_name, operation_description, owner_href, owner_name, owner_type, user_id, user_name, progress, org_id)) task = Task(session=vca_system.vcloud_session, verify=verify, log=log) t = task.create_or_update_task(status, namespace, operation_name, operation_description, owner_href, owner_name, owner_type, user_id, user_name, progress, org_id=org_id) print((t.get_id().split(':')[-1]))