Exemple #1
0
 def import_appliance(self, auth, href, type, arch, pae, hvm, size, provider_id, platform, description, link, image_name, group_id, is_manual, date, time):
     try:
         is_hvm = 'False'
         if hvm == 'true':
             is_hvm = 'True'
         is_pae = 'False'
         if pae == 'true':
             is_pae = 'True'
         image_name = re.sub(ImageStore.INVALID_CHARS_EXP, '_', image_name)
         appliance_entry = {}
         appliance_entry['href'] = href
         appliance_entry['type'] = type
         appliance_entry['arch'] = arch
         appliance_entry['PAE'] = is_pae
         appliance_entry['is_hvm'] = is_hvm
         appliance_entry['size'] = size
         appliance_entry['provider_id'] = provider_id
         appliance_entry['platform'] = platform
         appliance_entry['title'] = image_name
         if appliance_entry['provider_id'].lower() == 'jumpbox':
             appliance_entry['is_hvm'] = 'True'
         p_url = self.appliance_store.get_provider_url(provider_id)
         appliance_entry['provider_url'] = p_url
         p_logo_url = self.appliance_store.get_logo_url(provider_id)
         appliance_entry['provider_logo_url'] = p_logo_url
         if is_manual == 'true':
             description = "Manually imported appliance. Plese use 'Edit Description' menu to put appropriate description here."
             link = ''
         appliance_entry['description'] = description
         appliance_entry['link'] = link
         if self.appliance_store.get_provider(provider_id):
             self.appliance_store.get_provider(provider_id)
             appliance_entry['provider'] = self.appliance_store.get_provider(provider_id)
         else:
             self.appliance_store.get_provider(provider_id)
             appliance_entry['provider'] = provider_id
         if image_name:
             image_name = image_name.strip()
         platform = appliance_entry['platform']
         type = appliance_entry['type']
         if type.lower() not in ('xva', 'file_system', 'jb_archive'):
             raise Exception('Invalid Package type %s: supported package types are XVA, FILE_SYSTEM. JB_ARCHIVE' % type)
         image_store = Basic.getImageStore()
         if image_store.image_exists_by_name(image_name):
             image_store.image_exists_by_name(image_name)
             img = image_store.get_image_by_name(image_name)
             image_store.delete_image(auth, group_id, img.get_id())
         title = appliance_entry.get('title')
         if not title:
             title = ''
         tc = TaskCreator()
         result = tc.import_appliance(auth, appliance_entry, image_store, group_id, image_name, platform.lower(), True, date, time)
         return result
     except Exception as e:
         print_traceback()
         LOGGER.error(to_str(e).replace("'", ''))
         raise e
    def import_appliance(self, auth, href, type, arch, pae, hvm, size,
                         provider_id, platform, description, link, image_name,
                         group_id, is_manual, date, time):
        try:
            is_hvm = 'False'
            if hvm == 'true':
                is_hvm = 'True'
            is_pae = 'False'
            if pae == 'true':
                is_pae = 'True'

            image_name = re.sub(ImageStore.INVALID_CHARS_EXP, '_', image_name)

            appliance_entry = {}
            appliance_entry["href"] = href
            appliance_entry["type"] = type
            appliance_entry["arch"] = arch
            appliance_entry["PAE"] = is_pae
            appliance_entry["is_hvm"] = is_hvm
            appliance_entry["size"] = size
            appliance_entry["provider_id"] = provider_id
            appliance_entry["platform"] = platform
            appliance_entry["title"] = image_name

            if appliance_entry["provider_id"].lower() == "jumpbox":
                appliance_entry["is_hvm"] = "True"

            p_url = self.appliance_store.get_provider_url(provider_id)
            appliance_entry["provider_url"] = p_url
            p_logo_url = self.appliance_store.get_logo_url(provider_id)
            appliance_entry["provider_logo_url"] = p_logo_url

            if is_manual == 'true':
                description = "Manually imported appliance. Plese use 'Edit Description' menu to put appropriate description here."
                link = ""

            appliance_entry["description"] = description
            appliance_entry["link"] = link

            if self.appliance_store.get_provider(provider_id):
                appliance_entry[
                    "provider"] = self.appliance_store.get_provider(
                        provider_id)
            else:
                appliance_entry["provider"] = provider_id

            if image_name:
                image_name = image_name.strip()

            platform = appliance_entry["platform"]
            type = appliance_entry["type"]
            if type.lower() not in ("xva", "file_system", "jb_archive"):
                raise Exception(
                    "Invalid Package type %s: supported package types are XVA, FILE_SYSTEM. JB_ARCHIVE"
                    % type)

            image_store = Basic.getImageStore()

            #force = False

            #for image_group in image_store.get_image_groups(auth).values():
            if image_store.image_exists_by_name(image_name):
                img = image_store.get_image_by_name(image_name)
                image_store.delete_image(auth, group_id, img.get_id())

            #image_group = image_store.get_image_groups(auth)[group_id]

            # Create a new image and add it to the group.
            #img = image_store.create_image(auth,group_id, image_name, platform.lower())

            title = appliance_entry.get("title")
            if not title:
                title = ""

            tc = TaskCreator()
            tc.import_appliance(auth, appliance_entry, image_store, \
                                group_id, image_name, platform.lower(),True,date,time)
        except Exception, e:
            print_traceback()
            LOGGER.error(to_str(e).replace("'", ""))
            raise e
    def import_appliance(self,auth,href,type,arch,pae,hvm,size,provider_id,platform,description,link,image_name,group_id,is_manual,date,time):
        try:           
            is_hvm='False'
            if hvm == 'true':
                is_hvm='True'
            is_pae='False'
            if pae == 'true':
                is_pae='True'

            image_name = re.sub(ImageStore.INVALID_CHARS_EXP,'_', image_name)
                        
            appliance_entry = {}
            appliance_entry["href"] = href
            appliance_entry["type"] = type
            appliance_entry["arch"] = arch
            appliance_entry["PAE"] = is_pae
            appliance_entry["is_hvm"] = is_hvm
            appliance_entry["size"] = size
            appliance_entry["provider_id"] = provider_id
            appliance_entry["platform"] = platform
            appliance_entry["title"] = image_name

            if appliance_entry["provider_id"].lower() == "jumpbox":
                appliance_entry["is_hvm"] = "True"

            
            p_url = self.appliance_store.get_provider_url(provider_id)
            appliance_entry["provider_url"] = p_url
            p_logo_url = self.appliance_store.get_logo_url(provider_id)
            appliance_entry["provider_logo_url"] = p_logo_url

            if is_manual=='true':
                description="Manually imported appliance. Plese use 'Edit Description' menu to put appropriate description here."
                link=""

            appliance_entry["description"] = description
            appliance_entry["link"] = link

            if self.appliance_store.get_provider(provider_id):
                appliance_entry["provider"] = self.appliance_store.get_provider(provider_id)
            else:
                appliance_entry["provider"] = provider_id

            if image_name:
                image_name = image_name.strip()

            platform = appliance_entry["platform"]
            type = appliance_entry["type"]
            if type.lower() not in ("xva", "file_system", "jb_archive"):
                raise Exception("Invalid Package type %s: supported package types are XVA, FILE_SYSTEM. JB_ARCHIVE" % type)

            image_store=Basic.getImageStore()
            
            #force = False

            #for image_group in image_store.get_image_groups(auth).values():
            if image_store.image_exists_by_name(image_name):                
                img = image_store.get_image_by_name(image_name)
                image_store.delete_image(auth,group_id, img.get_id())
                    
            #image_group = image_store.get_image_groups(auth)[group_id]
            
            # Create a new image and add it to the group.
            #img = image_store.create_image(auth,group_id, image_name, platform.lower())

            title = appliance_entry.get("title")
            if not title:
                title = ""

            tc = TaskCreator()
            tc.import_appliance(auth, appliance_entry, image_store, \
                                group_id, image_name, platform.lower(),True,date,time)
        except Exception, e:
            print_traceback()
            LOGGER.error(to_str(e).replace("'",""))
            raise e
from UnitList import UnitList
unitlist=UnitList(conn)
hects=unitlist.add({'Name':'Hectares'})
ton=unitlist.add({'Name':'Tonnes'})
mes=unitlist.add({'Name':'Meses'})
seismes=unitlist.add({'Name':'14000 hrs'})

from TaskGroupCreator import TaskGroupCreator
taskgroupcreator=TaskGroupCreator(conn)
prod=taskgroupcreator.add({'Name':'Produccíon'})
silv=taskgroupcreator.add({'Name':'Silviculture'})
other=taskgroupcreator.add({'Name':'Otros'})

from TaskCreator import TaskCreator
taskcreator=TaskCreator(conn)
taskcreator.add(join(hects, prod, {'TaskId':'aa01','AgeMin':12, 'AgeMax':14, 'Description':"do the monkey"}))
taskcreator.add(join(ton, silv, {'TaskId':'bb01','AgeMin':20, 'AgeMax':21, 'Description':"do the monkey1"}))
taskcreator.add(join(hects, prod, {'TaskId':'aa02','AgeMin':12, 'AgeMax':14, 'Description':"do the monkey2"}))
taskcreator.add(join(mes, other, {'TaskId':'aa03','AgeMin':0, 'AgeMax':50, 'Description':"do the monkey3"}))

from PlanningList import PlanningList,planninglistitems_generator
planlist=PlanningList(conn) 
planlist.add(join(planninglistitems_generator(conn)[0],{'Quantity':12, 'EstPrice':100}) );
planlist.add(join(planninglistitems_generator(conn)[1],{'Quantity':12, 'EstPrice':100}) );
planlist.add(join(planninglistitems_generator(conn)[3],{'Quantity':32, 'EstPrice':100}) );
planlist.add(planninglistitems_generator(conn)[3] );


from ContractorCreator import ContractorCreator
cc=ContractorCreator(conn)