Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/bin/env python
  2.  
  3. import sys
  4. import random
  5.  
  6. main_nmc_list = ["fnmc", "nmc"]
  7.  
  8. def allocate_instance_id():
  9. return random.randint(2, 20)
  10.  
  11. def main(vm_name):
  12. tmp = vm_name.split('_')
  13.  
  14. if len(tmp) < 3:
  15. print "SERVER_VNFC_ID or SERVER_VNFC_ID_ID2"
  16. return
  17.  
  18. host_name = tmp[0]
  19. vnfc_type = tmp[1]
  20. vnf_id = tmp[2]
  21.  
  22. print "-"*80
  23. print "vm_name ", vm_name
  24. print "host_name ", host_name
  25. print "vnfc_type ", vnfc_type
  26. print "vnf_id ", vnf_id
  27.  
  28. if len(tmp) == 4:
  29. if vnfc_type in main_nmc_list:
  30. print "Incorrect VM name. VM should not have instance_id"
  31. return
  32. else:
  33. instance_id = eval(tmp[3])
  34. print "instance_id", instance_id
  35. else:
  36. if vnfc_type not in main_nmc_list:
  37. instance_id = allocate_instance_id()
  38. print "instance_id", instance_id, "(new)"
  39.  
  40.  
  41. # assign IP address
  42.  
  43.  
  44.  
  45.  
  46. if __name__ == '__main__':
  47. if sys.argv[1] == "-t":
  48. main("seoul_nmc_1")
  49. main("seoul_nmc_2")
  50. main("seoul_cpc_2")
  51. main("seoul_upc_3_2")
  52. else:
  53. main(sys.argv[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement