#NEWLINE# @ require_enabled #NEWLINE# def save_slice( self , slice ) : #NEWLINE# #INDENT# if ( not slice . tenant_id ) : #NEWLINE# #INDENT# nova_fields = { #NEWLINE# #INDENT# 'tenant_name' : slice . name , #NEWLINE# 'description' : slice . description , #NEWLINE# 'enabled' : slice . enabled , #NEWLINE# #UNINDENT# } #NEWLINE# tenant = self . driver . create_tenant ( ** nova_fields ) #NEWLINE# slice . tenant_id = tenant . id #NEWLINE# self . driver . add_user_role ( self . caller . kuser_id , tenant . id , 'admin' ) #NEWLINE# self . driver . shell . connect ( username = self . driver . shell . keystone . username , password = self . driver . shell . keystone . password , tenant = tenant . name ) #NEWLINE# network = self . driver . create_network ( slice . name ) #NEWLINE# slice . network_id = network [ 'id' ] #NEWLINE# router = self . driver . create_router ( slice . name ) #NEWLINE# slice . router_id = router [ 'id' ] #NEWLINE# next_subnet = self . get_next_subnet ( ) #NEWLINE# cidr = str ( next_subnet . cidr ) #NEWLINE# ip_version = ip_version . version #NEWLINE# start = str ( next_subnet [ 2 ] ) #NEWLINE# end = str ( next_subnet [ ( - 2 ) ] ) #NEWLINE# subnet = self . driver . create_subnet ( name = slice . name , network_id = network [ 'id' ] , cidr_ip = cidr , ip_version = ip_version , start = start , end = end ) #NEWLINE# slice . subnet_id = subnet [ 'id' ] #NEWLINE# self . driver . add_router_interface ( router [ 'id' ] , subnet [ 'id' ] ) #NEWLINE# self . driver . add_external_route ( subnet ) #NEWLINE# #UNINDENT# if ( slice . id and slice . tenant_id ) : #NEWLINE# #INDENT# self . driver . update_tenant ( slice . tenant_id , description = slice . description , enabled = slice . enabled ) #NEWLINE# #UNINDENT# slice . save ( ) #NEWLINE# slice . enacted = datetime . now ( ) #NEWLINE# slice . save ( update_fields = [ 'enacted' ] )