<s> from __future__ import unicode_literals <EOL> import socket <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . core . management . base import BaseCommand <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import transaction <EOL> from keystoneclient import exceptions as keystone_exceptions <EOL> from optparse import make_option <EOL> from nodeconductor . backup import models as backup_models <EOL> from nodeconductor . core import NodeConductorExtension <EOL> from nodeconductor . core . tasks import send_task <EOL> from nodeconductor . core . models import SynchronizationStates <EOL> from nodeconductor . iaas import models as iaas_models <EOL> from nodeconductor . monitoring . zabbix . api_client import ZabbixApiClient <EOL> from nodeconductor . openstack import Types <EOL> from nodeconductor . openstack import models as op_models <EOL> from nodeconductor . openstack . apps import OpenStackConfig <EOL> from nodeconductor . quotas . handlers import init_quotas <EOL> from nodeconductor . structure . models import ServiceSettings <EOL> from nodeconductor . template . models import TemplateGroup , Template <EOL> zbx = NodeConductorExtension . is_installed ( '<STR_LIT>' ) <EOL> class Command ( BaseCommand ) : <EOL> help = "<STR_LIT>" <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , default = False , <EOL> help = "<STR_LIT>" ) , <EOL> ) <EOL> def head ( self , message ) : <EOL> self . stdout . write ( self . style . MIGRATE_HEADING ( '<STR_LIT:\n>' + message ) ) <EOL> def warn ( self , message ) : <EOL> self . stdout . write ( self . style . WARNING ( '<STR_LIT>' + message ) ) <EOL> def error ( self , message ) : <EOL> self . stdout . write ( self . style . ERROR ( '<STR_LIT>' + message ) ) <EOL> def get_obj_url ( self , name , obj ) : <EOL> if obj : <EOL> return self . base_url + reverse ( name , args = ( obj . uuid . hex if hasattr ( obj , '<STR_LIT>' ) else obj . pk , ) ) <EOL> def license2tags ( self , tmpl ) : <EOL> tags = [ ] <EOL> if tmpl . os_type : <EOL> tags . append ( ( Types . PriceItems . LICENSE_OS , tmpl . os_type , tmpl . os ) ) <EOL> if tmpl . application_type and tmpl . application_type . name != '<STR_LIT:none>' : <EOL> if tmpl . template_licenses . filter ( license_type = tmpl . application_type . slug ) . exists ( ) : <EOL> pretty_name = tmpl . template_licenses . filter ( license_type = tmpl . application_type . slug ) . first ( ) . name <EOL> else : <EOL> pretty_name = tmpl . application_type . name <EOL> tags . append ( ( Types . PriceItems . LICENSE_APPLICATION , tmpl . application_type . slug , pretty_name ) ) <EOL> tags . append ( ( Types . PriceItems . SUPPORT , Types . Support . PREMIUM ) ) <EOL> is_app = True <EOL> else : <EOL> tags . append ( ( Types . PriceItems . SUPPORT , Types . Support . BASIC ) ) <EOL> is_app = False <EOL> return is_app , [ '<STR_LIT::>' . join ( t ) for t in tags ] <EOL> def get_old_zabbix_client ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . _old_zabbix_client = ZabbixApiClient ( ) <EOL> return self . _old_zabbix_client <EOL> def add_user_to_tenant ( self , username , cpm ) : <EOL> backend = cpm . get_backend ( ) <EOL> session = backend . create_session ( keystone_url = cpm . cloud . auth_url ) <EOL> keystone = backend . create_keystone_client ( session ) <EOL> tenant = keystone . tenants . get ( cpm . tenant_id ) <EOL> backend . ensure_user_is_tenant_admin ( username , tenant , keystone ) <EOL> self . stdout . write ( '<STR_LIT>' % ( username , cpm . tenant_id ) ) <EOL> def create_zabbix_data ( self , iaas_instance , openstack_instance , zabbix_settings , options ) : <EOL> self . stdout . write ( '<STR_LIT>' % iaas_instance ) <EOL> from nodeconductor_zabbix . models import Template , Host , ITService , Trigger , ZabbixServiceProjectLink <EOL> backend = zabbix_settings . get_backend ( ) <EOL> api = backend . api <EOL> old_client = self . get_old_zabbix_client ( ) <EOL> try : <EOL> host_id = old_client . get_host ( iaas_instance ) [ '<STR_LIT>' ] <EOL> except IndexError : <EOL> self . error ( <EOL> '<STR_LIT>' % ( iaas_instance . name , iaas_instance . uuid ) ) <EOL> return <EOL> host_data = api . host . get ( <EOL> filter = { '<STR_LIT>' : host_id } , selectParentTemplates = '<STR_LIT>' , output = '<STR_LIT>' , selectGroups = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> host_interface_data = api . hostinterface . get ( filter = { '<STR_LIT>' : host_id } , output = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> del host_interface_data [ '<STR_LIT>' ] <EOL> del host_interface_data [ '<STR_LIT>' ] <EOL> template_ids = [ el [ '<STR_LIT>' ] for el in host_data [ '<STR_LIT>' ] ] <EOL> try : <EOL> templates = [ Template . objects . get ( backend_id = template_id ) for template_id in template_ids ] <EOL> except Template . DoesNotExist : <EOL> self . error ( '<STR_LIT>' % template_ids ) <EOL> return <EOL> try : <EOL> host_group_name = host_data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] <EOL> except ( IndexError , KeyError ) : <EOL> host_group_name = '<STR_LIT>' <EOL> spl = ZabbixServiceProjectLink . objects . get ( <EOL> service__settings = zabbix_settings , project = openstack_instance . project ) <EOL> self . stdout . write ( '<STR_LIT>' % openstack_instance . name ) <EOL> host = Host . objects . create ( <EOL> service_project_link = spl , <EOL> scope = openstack_instance , <EOL> visible_name = host_data [ '<STR_LIT:name>' ] , <EOL> name = host_data [ '<STR_LIT:host>' ] , <EOL> backend_id = host_id , <EOL> state = Host . States . ONLINE , <EOL> host_group_name = host_group_name , <EOL> interface_parameters = host_interface_data , <EOL> ) <EOL> host . templates . add ( * templates ) <EOL> service_name = old_client . get_service_name ( iaas_instance ) <EOL> try : <EOL> service_data = api . service . get ( filter = { '<STR_LIT:name>' : service_name } , output = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> self . error ( <EOL> '<STR_LIT>' % ( iaas_instance . name , iaas_instance . uuid ) ) <EOL> return <EOL> trigger_data = api . trigger . get ( filter = { '<STR_LIT>' : service_data [ '<STR_LIT>' ] } , output = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> try : <EOL> trigger = Trigger . objects . get ( name = trigger_data [ '<STR_LIT:description>' ] , backend_id = trigger_data [ '<STR_LIT>' ] ) <EOL> except Trigger . DoesNotExist : <EOL> self . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( trigger_data [ '<STR_LIT:description>' ] , trigger_data [ '<STR_LIT>' ] ) ) <EOL> self . stdout . write ( '<STR_LIT>' % openstack_instance . name ) <EOL> ITService . objects . create ( <EOL> service_project_link = spl , <EOL> host = host , <EOL> is_main = True , <EOL> algorithm = int ( service_data [ '<STR_LIT>' ] ) , <EOL> sort_order = int ( service_data [ '<STR_LIT>' ] ) , <EOL> agreed_sla = float ( service_data [ '<STR_LIT>' ] ) , <EOL> backend_trigger_id = service_data [ '<STR_LIT>' ] , <EOL> state = ITService . States . ONLINE , <EOL> backend_id = service_data [ '<STR_LIT>' ] , <EOL> name = service_data [ '<STR_LIT:name>' ] , <EOL> trigger = trigger , <EOL> ) <EOL> if iaas_instance . type == iaas_instance . Services . PAAS : <EOL> self . stdout . write ( '<STR_LIT>' % openstack_instance ) <EOL> mapping = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT:OK>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> openstack_instance . monitoring_items . create ( <EOL> name = Host . MONITORING_ITEMS_CONFIGS [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> value = mapping [ iaas_instance . installation_state ] ) <EOL> @ transaction . atomic <EOL> def handle ( self , * args , ** options ) : <EOL> save_point = transaction . savepoint ( ) <EOL> try : <EOL> self . migrate_data ( * args , ** options ) <EOL> except Exception as e : <EOL> self . error ( "<STR_LIT>" % e ) <EOL> self . error ( "<STR_LIT>" ) <EOL> transaction . savepoint_rollback ( save_point ) <EOL> raise <EOL> else : <EOL> if options . get ( '<STR_LIT>' ) : <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> self . error ( "<STR_LIT>" ) <EOL> transaction . savepoint_rollback ( save_point ) <EOL> def migrate_data ( self , * args , ** options ) : <EOL> self . head ( "<STR_LIT>" ) <EOL> self . base_url = '<STR_LIT>' % ( socket . gethostname ( ) or '<STR_LIT>' ) <EOL> self . portal_base_url = '<STR_LIT>' <EOL> if not options . get ( '<STR_LIT>' ) : <EOL> self . base_url = ( raw_input ( '<STR_LIT>' % self . base_url ) or self . base_url ) <EOL> self . base_url = self . base_url . rstrip ( '<STR_LIT:/>' ) <EOL> self . portal_base_url = ( <EOL> raw_input ( '<STR_LIT>' % self . portal_base_url ) or self . portal_base_url ) <EOL> self . portal_base_url = self . portal_base_url . rstrip ( '<STR_LIT:/>' ) <EOL> if zbx : <EOL> from nodeconductor_zabbix . apps import ZabbixConfig <EOL> self . zabbix_settings = None <EOL> services_settings = list ( ServiceSettings . objects . filter ( type = ZabbixConfig . service_name ) . order_by ( '<STR_LIT:name>' ) ) <EOL> if services_settings : <EOL> self . stdout . write ( '<STR_LIT>' ) <EOL> start = <NUM_LIT:1> <EOL> for i in range ( <NUM_LIT:0> , len ( services_settings ) , <NUM_LIT:3> ) : <EOL> choices = [ ] <EOL> for idx , val in enumerate ( services_settings [ i : i + <NUM_LIT:3> ] , start ) : <EOL> choices . append ( '<STR_LIT>' . format ( idx , val ) ) <EOL> self . stdout . write ( '<STR_LIT>' . join ( choices ) ) <EOL> start += <NUM_LIT:3> <EOL> while True : <EOL> idx = ( raw_input ( self . style . WARNING ( '<STR_LIT>' ) ) or '<STR_LIT:None>' ) <EOL> if idx == '<STR_LIT:None>' : <EOL> break <EOL> try : <EOL> self . zabbix_settings = services_settings [ int ( idx ) - <NUM_LIT:1> ] <EOL> except ( IndexError , TypeError , ValueError ) : <EOL> self . error ( "<STR_LIT>" ) <EOL> else : <EOL> break <EOL> else : <EOL> self . warn ( "<STR_LIT>" ) <EOL> else : <EOL> self . error ( "<STR_LIT>" ) <EOL> self . head ( "<STR_LIT>" ) <EOL> clouds = set ( iaas_models . Cloud . objects . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> iaas_settings = iaas_models . OpenStackSettings . objects . filter ( auth_url__in = clouds ) <EOL> op_settings = set ( ServiceSettings . objects . filter ( <EOL> type = OpenStackConfig . service_name ) . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> new_settings = [ ] <EOL> for s in iaas_settings : <EOL> if s . auth_url in op_settings : <EOL> self . stdout . write ( '<STR_LIT>' % s ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % s ) <EOL> settings = ServiceSettings . objects . create ( <EOL> type = OpenStackConfig . service_name , <EOL> backend_url = s . auth_url , <EOL> username = s . username , <EOL> password = s . password , <EOL> options = { '<STR_LIT>' : s . tenant_name , '<STR_LIT>' : s . availability_zone } , <EOL> state = SynchronizationStates . IN_SYNC , <EOL> shared = False ) <EOL> new_settings . append ( settings . id ) <EOL> self . head ( "<STR_LIT>" ) <EOL> flavors = { } <EOL> for flavor in iaas_models . Flavor . objects . select_related ( '<STR_LIT>' ) : <EOL> try : <EOL> flavors [ flavor . id ] = op_models . Flavor . objects . get ( <EOL> settings__backend_url = flavor . cloud . auth_url , <EOL> settings__shared = True , <EOL> backend_id = flavor . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % flavor ) <EOL> try : <EOL> settings = ServiceSettings . objects . get ( <EOL> type = OpenStackConfig . service_name , <EOL> backend_url = flavor . cloud . auth_url ) <EOL> except ObjectDoesNotExist : <EOL> self . warn ( '<STR_LIT>' % flavor . cloud . auth_url ) <EOL> continue <EOL> flavors [ flavor . id ] = op_models . Flavor . objects . create ( <EOL> settings = settings , <EOL> backend_id = flavor . backend_id , <EOL> name = flavor . name , <EOL> disk = flavor . disk , <EOL> cores = flavor . cores , <EOL> ram = flavor . ram ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % flavor ) <EOL> self . head ( "<STR_LIT>" ) <EOL> images = { } <EOL> for image in iaas_models . Image . objects . select_related ( '<STR_LIT>' ) : <EOL> try : <EOL> images [ image . id ] = op_models . Image . objects . get ( <EOL> settings__backend_url = image . cloud . auth_url , <EOL> settings__shared = True , <EOL> backend_id = image . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % image ) <EOL> try : <EOL> settings = ServiceSettings . objects . get ( <EOL> type = OpenStackConfig . service_name , <EOL> shared = True , <EOL> backend_url = image . cloud . auth_url ) <EOL> except ObjectDoesNotExist : <EOL> self . warn ( '<STR_LIT>' % image . cloud . auth_url ) <EOL> continue <EOL> images [ image . id ] = op_models . Image . objects . create ( <EOL> settings = settings , <EOL> backend_id = image . backend_id , <EOL> min_ram = image . min_ram , <EOL> min_disk = image . min_disk ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % image ) <EOL> self . head ( "<STR_LIT>" ) <EOL> clouds = { } <EOL> for cloud in iaas_models . Cloud . objects . all ( ) : <EOL> try : <EOL> clouds [ cloud . id ] = op_models . OpenStackService . objects . get ( <EOL> customer = cloud . customer , settings__backend_url = cloud . auth_url , settings__shared = True ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % cloud ) <EOL> try : <EOL> settings = ServiceSettings . objects . get ( <EOL> type = OpenStackConfig . service_name , <EOL> shared = True , <EOL> backend_url = cloud . auth_url ) <EOL> except ObjectDoesNotExist : <EOL> self . warn ( '<STR_LIT>' % cloud . auth_url ) <EOL> continue <EOL> clouds [ cloud . id ] = op_models . OpenStackService . objects . create ( <EOL> settings = settings , <EOL> customer = cloud . customer , <EOL> name = cloud . name ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % cloud ) <EOL> self . head ( "<STR_LIT>" ) <EOL> cpms = { } <EOL> spls = [ ] <EOL> for cpm in iaas_models . CloudProjectMembership . objects . filter ( cloud__in = clouds ) : <EOL> try : <EOL> self . add_user_to_tenant ( clouds [ cpm . cloud_id ] . settings . username , cpm ) <EOL> except keystone_exceptions . NotFound : <EOL> self . stdout . write ( '<STR_LIT>' % cpm . tenant_id ) <EOL> continue <EOL> try : <EOL> spl = op_models . OpenStackServiceProjectLink . objects . get ( <EOL> service = clouds [ cpm . cloud_id ] , <EOL> project = cpm . project ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % cpm ) <EOL> init_quotas ( cpm . project . __class__ , cpm . project , created = True ) <EOL> init_quotas ( cpm . project . customer . __class__ , cpm . project . customer , created = True ) <EOL> spl = op_models . OpenStackServiceProjectLink . objects . create ( <EOL> service = clouds [ cpm . cloud_id ] , <EOL> project = cpm . project ) <EOL> tenant = spl . create_tenant ( ) <EOL> tenant . backend_id = cpm . tenant_id <EOL> tenant . availability_zone = cpm . availability_zone <EOL> tenant . internal_network_id = cpm . internal_network_id <EOL> tenant . external_network_id = cpm . external_network_id <EOL> tenant . state = op_models . Tenant . States . OK <EOL> tenant . save ( ) <EOL> spls . append ( spl . to_string ( ) ) <EOL> cpms [ cpm . id ] = spl <EOL> else : <EOL> cpms [ cpm . id ] = spl <EOL> if spl . tenant is not None and spl . tenant_id != cpm . tenant_id : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( spl . service , spl . project ) ) <EOL> else : <EOL> if spl . tenant_id != cpm . tenant_id : <EOL> tenant . backend_id = cpm . tenant_id <EOL> tenant . availability_zone = cpm . availability_zone <EOL> tenant . internal_network_id = cpm . internal_network_id <EOL> tenant . external_network_id = cpm . external_network_id <EOL> tenant . state = op_models . Tenant . States . OK <EOL> tenant . save ( ) <EOL> self . stdout . write ( '<STR_LIT>' % cpm ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % cpm ) <EOL> self . head ( "<STR_LIT>" ) <EOL> for fip in iaas_models . FloatingIP . objects . all ( ) : <EOL> try : <EOL> op_models . FloatingIP . objects . get ( <EOL> service_project_link = cpms [ fip . cloud_project_membership_id ] , <EOL> backend_id = fip . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % fip ) <EOL> op_models . FloatingIP . objects . create ( <EOL> service_project_link = cpms [ fip . cloud_project_membership_id ] , <EOL> backend_id = fip . backend_id , <EOL> backend_network_id = fip . backend_network_id , <EOL> address = fip . address , <EOL> status = fip . status ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % fip ) <EOL> self . head ( "<STR_LIT>" ) <EOL> sgroups = { } <EOL> for sgp in iaas_models . SecurityGroup . objects . all ( ) : <EOL> try : <EOL> sgroups [ sgp . id ] = op_models . SecurityGroup . objects . get ( <EOL> service_project_link = cpms [ sgp . cloud_project_membership_id ] , <EOL> backend_id = sgp . backend_id ) <EOL> except KeyError : <EOL> self . warn ( '<STR_LIT>' % sgp . cloud_project_membership_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % sgp ) <EOL> sgroups [ sgp . id ] = op_models . SecurityGroup . objects . create ( <EOL> service_project_link = cpms [ sgp . cloud_project_membership_id ] , <EOL> backend_id = sgp . backend_id , <EOL> description = sgp . description , <EOL> name = sgp . name , <EOL> state = sgp . state ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % sgp ) <EOL> self . head ( "<STR_LIT>" ) <EOL> for sgr in iaas_models . SecurityGroupRule . objects . all ( ) : <EOL> try : <EOL> op_models . SecurityGroupRule . objects . get ( <EOL> security_group = sgroups [ sgr . group_id ] , <EOL> backend_id = sgr . backend_id ) <EOL> except KeyError : <EOL> self . warn ( '<STR_LIT>' % sgr . group_id ) <EOL> except op_models . SecurityGroupRule . MultipleObjectsReturned : <EOL> self . warn ( '<STR_LIT>' % sgr . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % sgr ) <EOL> op_models . SecurityGroupRule . objects . create ( <EOL> security_group = sgroups [ sgr . group_id ] , <EOL> backend_id = sgr . backend_id , <EOL> protocol = sgr . protocol , <EOL> from_port = sgr . from_port , <EOL> to_port = sgr . to_port , <EOL> cidr = sgr . cidr ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % sgr ) <EOL> if spls and not options . get ( '<STR_LIT>' ) : <EOL> send_task ( '<STR_LIT>' , '<STR_LIT>' ) ( spls ) <EOL> self . head ( "<STR_LIT>" ) <EOL> migrated_iaas_instances = [ ] <EOL> for instance in iaas_models . Instance . objects . filter ( cloud_project_membership__in = cpms ) : <EOL> try : <EOL> op_models . Instance . objects . get ( <EOL> service_project_link = cpms [ instance . cloud_project_membership_id ] , <EOL> backend_id = instance . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % instance ) <EOL> inst = op_models . Instance . objects . create ( <EOL> service_project_link = cpms [ instance . cloud_project_membership_id ] , <EOL> backend_id = instance . backend_id , <EOL> billing_backend_id = instance . billing_backend_id , <EOL> last_usage_update_time = instance . last_usage_update_time , <EOL> system_volume_id = instance . system_volume_id , <EOL> system_volume_size = instance . system_volume_size , <EOL> data_volume_id = instance . data_volume_id , <EOL> data_volume_size = instance . data_volume_size , <EOL> external_ips = instance . external_ips , <EOL> internal_ips = instance . internal_ips , <EOL> flavor_name = instance . flavor_name , <EOL> cores = instance . cores , <EOL> ram = instance . ram , <EOL> state = instance . state , <EOL> name = instance . name , <EOL> ) <EOL> inst . uuid = instance . uuid <EOL> inst . created = instance . created <EOL> image = instance . template . images . first ( ) <EOL> if image : <EOL> inst . min_disk = image . min_disk <EOL> inst . min_ram = image . min_ram <EOL> inst . save ( ) <EOL> for sgrp in instance . security_groups . all ( ) : <EOL> sg = sgroups . get ( sgrp . security_group_id ) <EOL> if sg : <EOL> inst . security_groups . create ( security_group = sg ) <EOL> _ , tags = self . license2tags ( instance . template ) <EOL> inst . tags . add ( * tags ) <EOL> inst . tags . add ( instance . type ) <EOL> if self . zabbix_settings : <EOL> self . create_zabbix_data ( <EOL> iaas_instance = instance , <EOL> openstack_instance = inst , <EOL> zabbix_settings = self . zabbix_settings , <EOL> options = options , <EOL> ) <EOL> migrated_iaas_instances . append ( instance ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % instance ) <EOL> self . head ( "<STR_LIT>" ) <EOL> migrated_backup_schedules = { } <EOL> for backup_schedule in backup_models . BackupSchedule . objects . all ( ) : <EOL> if backup_schedule . backup_source not in migrated_iaas_instances : <EOL> self . stdout . write ( '<STR_LIT>' % backup_schedule ) <EOL> continue <EOL> migrated_backup_schedules [ backup_schedule ] = op_models . BackupSchedule . objects . create ( <EOL> instance = op_models . Instance . objects . get ( uuid = backup_schedule . backup_source . uuid ) , <EOL> schedule = backup_schedule . schedule , <EOL> next_trigger_at = backup_schedule . next_trigger_at , <EOL> is_active = backup_schedule . is_active , <EOL> timezone = backup_schedule . timezone , <EOL> maximal_number_of_backups = backup_schedule . maximal_number_of_backups , <EOL> retention_time = backup_schedule . retention_time , <EOL> description = backup_schedule . description , <EOL> ) <EOL> self . stdout . write ( '<STR_LIT>' % backup_schedule ) <EOL> self . head ( "<STR_LIT>" ) <EOL> for backup in backup_models . Backup . objects . all ( ) : <EOL> if backup . backup_source not in migrated_iaas_instances : <EOL> self . stdout . write ( '<STR_LIT>' % backup_schedule ) <EOL> continue <EOL> op_instance = op_models . Instance . objects . get ( uuid = backup . backup_source . uuid ) <EOL> op_metadata = backup . metadata <EOL> op_metadata [ '<STR_LIT>' ] = [ tag . name for tag in op_instance . tags . all ( ) ] <EOL> op_models . Backup . objects . create ( <EOL> instance = op_instance , <EOL> backup_schedule = migrated_backup_schedules . get ( backup . backup_schedule , None ) , <EOL> kept_until = backup . kept_until , <EOL> created_at = backup . created_at , <EOL> state = backup . state , <EOL> metadata = op_metadata , <EOL> description = backup . description , <EOL> ) <EOL> self . stdout . write ( '<STR_LIT>' % backup ) <EOL> self . head ( "<STR_LIT>" ) <EOL> for tmpl in iaas_models . Template . objects . all ( ) : <EOL> auth_urls = set ( [ c . auth_url for c in iaas_models . Cloud . objects . all ( ) ] ) <EOL> op_settings = ServiceSettings . objects . get ( <EOL> type = OpenStackConfig . service_name , backend_url__in = auth_urls , shared = True ) <EOL> descr = '<STR_LIT>' % ( tmpl , tmpl . uuid ) <EOL> try : <EOL> group = TemplateGroup . objects . get ( description = descr ) <EOL> except ObjectDoesNotExist : <EOL> self . stdout . write ( '<STR_LIT>' % ( tmpl , descr ) ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' % ( tmpl , descr ) ) <EOL> continue <EOL> group = TemplateGroup . objects . create ( <EOL> name = tmpl . name , <EOL> description = descr , <EOL> is_active = tmpl . is_active , <EOL> icon_url = self . portal_base_url + tmpl . icon_name ) <EOL> group . tags . add ( tmpl . type ) <EOL> iaas_image = tmpl . images . all ( ) . first ( ) <EOL> if not iaas_image : <EOL> self . warn ( '<STR_LIT>' % tmpl . name ) <EOL> continue <EOL> try : <EOL> image = op_models . Image . objects . get ( settings = op_settings , backend_id = iaas_image . backend_id ) <EOL> except ObjectDoesNotExist : <EOL> self . warn ( '<STR_LIT>' % iaas_image . name ) <EOL> continue <EOL> main_template = Template . objects . create ( <EOL> resource_content_type = ContentType . objects . get_for_model ( op_models . Instance ) , <EOL> service_settings = op_settings , <EOL> options = { <EOL> '<STR_LIT>' : self . get_obj_url ( '<STR_LIT>' , op_settings ) , <EOL> '<STR_LIT:image>' : self . get_obj_url ( '<STR_LIT>' , image ) , <EOL> } , <EOL> group = group , <EOL> order_number = <NUM_LIT:1> ) <EOL> _ , tags = self . license2tags ( tmpl ) <EOL> main_template . tags . add ( * tags ) <EOL> main_template . tags . add ( tmpl . type ) <EOL> if self . zabbix_settings : <EOL> from nodeconductor_zabbix . models import Host , ITService , Trigger , Template as ZabbixTemplate <EOL> zabbix_templates = [ ZabbixTemplate . objects . get ( <EOL> name = '<STR_LIT>' , settings = self . zabbix_settings ) ] <EOL> if main_template . tags . filter ( name__contains = '<STR_LIT>' ) : <EOL> zabbix_templates . append ( ZabbixTemplate . objects . get ( <EOL> name = '<STR_LIT>' , settings = self . zabbix_settings ) ) <EOL> trigger_name = '<STR_LIT>' <EOL> elif main_template . tags . filter ( name__contains = '<STR_LIT>' ) : <EOL> zabbix_templates . append ( ZabbixTemplate . objects . get ( <EOL> name = '<STR_LIT>' , settings = self . zabbix_settings ) ) <EOL> trigger_name = '<STR_LIT>' <EOL> elif main_template . tags . filter ( name__contains = '<STR_LIT>' ) : <EOL> zabbix_templates . append ( ZabbixTemplate . objects . get ( <EOL> name = '<STR_LIT>' , settings = self . zabbix_settings ) ) <EOL> trigger_name = '<STR_LIT>' <EOL> else : <EOL> trigger_name = '<STR_LIT>' <EOL> Template . objects . create ( <EOL> resource_content_type = ContentType . objects . get_for_model ( Host ) , <EOL> service_settings = self . zabbix_settings , <EOL> options = { <EOL> '<STR_LIT>' : self . get_obj_url ( '<STR_LIT>' , self . zabbix_settings ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ { '<STR_LIT:url>' : self . get_obj_url ( '<STR_LIT>' , t ) } for t in zabbix_templates ] , <EOL> } , <EOL> use_previous_resource_project = True , <EOL> group = group , <EOL> order_number = <NUM_LIT:2> ) <EOL> trigger = Trigger . objects . get ( <EOL> name = trigger_name , template__name = '<STR_LIT>' , settings = self . zabbix_settings ) <EOL> Template . objects . create ( <EOL> resource_content_type = ContentType . objects . get_for_model ( ITService ) , <EOL> service_settings = self . zabbix_settings , <EOL> options = { <EOL> '<STR_LIT>' : self . get_obj_url ( '<STR_LIT>' , self . zabbix_settings ) , <EOL> '<STR_LIT:host>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : self . get_obj_url ( '<STR_LIT>' , trigger ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> use_previous_resource_project = True , <EOL> group = group , <EOL> order_number = <NUM_LIT:3> ) <EOL> ServiceSettings . objects . filter ( id__in = new_settings ) . update ( shared = True ) </s>
