def update_unmanaged_nodegroup()

in eksupdate/src/eksctlfinal.py [0:0]


def update_unmanaged_nodegroup(region,clust_name,d,bclient):
    start_time=time.ctime()
    start=time.time()
    logs_pusher(regionName=region,cluster_name=clust_name,msg=" update managed nodegroups Started At "+str(start_time))

    old_smg=get_old_smg_node_groups(region,clust_name,bclient)                             #extract SELF MANAGED NODEGROUPS
    args='~/eksctl get nodegroup --cluster='+clust_name+' -o json'
    output=subprocess.check_output(args,shell=True)
    output=json.loads((output))
    response = bclient.list_nodegroups(
    clusterName=clust_name,
    )
    d['un_managed_ndgrp_before_update']={}
    ls=response['nodegroups']
    for i in output:
        if(i['Name'] not in ls):
            print(i['Name'] +" image-id befrore update "+i['ImageID'])                              #to print PRESENT - SELF MANAGED NODEGROUP IMAGE and ID
            d['un_managed_ndgrp_before_update'][i['Name']]=i['ImageID']
    
    if(old_smg!=[ ]): 
        try:                                                      #to verify "if SELF MANAGED GROUP exists"
            for i in old_smg:
                args="~/eksctl create nodegroup --cluster="+clust_name            #creates a node group with CONTROL PLANE version
                output=subprocess.call(args,shell=True)
                ls=get_old_smg_node_groups(region,clust_name,bclient)
                time.sleep(60)
                args="~/eksctl drain nodegroup --cluster="+clust_name+" --name="+i #DRAINS the old node groups
                output=subprocess.call(args,shell=True)
                time.sleep(60)
                args="~/eksctl delete nodegroup --cluster="+clust_name+" --name="+i #DELETES the old node groups
                output=subprocess.call(args,shell=True)
        except Exception as e:
            print('pdb set cant delete pods'+e)
    else:
        print("no unmanaged nodegroups")
        return d
    
    print('**printing unmanaged nodegroups....waiting for nodegroup to be active')
    time.sleep(240)
    args='~/eksctl get nodegroup --cluster='+clust_name+' -o json'
    output=subprocess.check_output(args,shell=True)
    output=json.loads((output))
    response = bclient.list_nodegroups(
    clusterName=clust_name,
    )
    ls=response['nodegroups']
  
    d['un_managed_ndgrp_after_update']={}
    for i in output:
        if(i['Name'] not in ls):
            print(i['Name'] +" image-id after update "+i['ImageID'])                               #to print UPDATED - SELF MANAGED NODEGROUP IMAGE and ID
            d['un_managed_ndgrp_after_update'][i['Name']]=i['ImageID']
    
    end=time.time()
    hours, rem = divmod(end-start, 3600)
    minutes, seconds = divmod(rem, 60)
    print("The time Taken For update managed nodegroups ","{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))
    logs_pusher(regionName=region,cluster_name=clust_name,msg="The time Taken For update managed nodegroups "+"{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))

    return d