Package backend :: Package server :: Package importlib :: Module archImport
[hide private]
[frames] | no frames]

Source Code for Module backend.server.importlib.archImport

  1  # 
  2  # Copyright (c) 2008--2015 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15  # 
 16  # Arch import process 
 17  # 
 18   
 19  from importLib import Import 
 20   
 21   
22 -class ArchImport(Import):
23 backend_method = '' 24
25 - def submit(self):
26 meth = getattr(self.backend, self.backend_method) 27 meth(self.batch) 28 self.backend.commit()
29 30
31 -class CPUArchImport(ArchImport):
32 backend_method = 'processCPUArches'
33 34
35 -class TypedArchImport(ArchImport):
36
37 - def preprocess(self):
38 self.arch_types = {} 39 for item in self.batch: 40 arch_type_label = item['arch-type-label'] 41 arch_type_name = item['arch-type-name'] 42 self.arch_types[arch_type_label] = arch_type_name
43
44 - def fix(self):
45 self.backend.lookupArchTypes(self.arch_types) 46 for item in self.batch: 47 item['arch_type_id'] = self.arch_types[item['arch-type-label']]
48 49
50 -class ChannelArchImport(TypedArchImport):
51 backend_method = 'processChannelArches'
52 53
54 -class PackageArchImport(TypedArchImport):
55 backend_method = 'processPackageArches'
56 57
58 -class ServerArchImport(TypedArchImport):
59 backend_method = 'processServerArches'
60 61
62 -class BaseArchCompatImport(Import):
63 # Things that have to be overridden in subclasses 64 arches1_lookup_method_name = '' 65 arches2_lookup_method_name = '' 66 arches1_name = '' 67 arches2_name = '' 68 arches1_field_name = '' 69 arches2_field_name = '' 70 submit_method_name = '' 71
72 - def __init__(self, batch, backend):
73 Import.__init__(self, batch, backend) 74 self.arches1 = {} 75 self.arches2 = {}
76
77 - def preprocess(self):
78 # Build the hashes keyed on the label 79 for entry in self.batch: 80 self.arches1[entry[self.arches1_name]] = None 81 self.arches2[entry[self.arches2_name]] = None
82
83 - def fix(self):
84 # Look up the arches 85 getattr(self.backend, self.arches1_lookup_method_name)(self.arches1) 86 getattr(self.backend, self.arches2_lookup_method_name)(self.arches2) 87 self._postprocess()
88
89 - def _postprocess(self):
90 for entry in self.batch: 91 arch1_name = entry[self.arches1_name] 92 val = self.arches1.get(arch1_name) 93 if not val: 94 raise ValueError("Unsupported arch %s" % arch1_name) 95 entry[self.arches1_field_name] = val 96 97 arch2_name = entry[self.arches2_name] 98 val = self.arches2.get(arch2_name) 99 if not val: 100 raise ValueError("Unsupported arch %s" % arch2_name) 101 entry[self.arches2_field_name] = val
102
103 - def submit(self):
104 getattr(self.backend, self.submit_method_name)(self.batch) 105 self.backend.commit()
106 107
108 -class ServerPackageArchCompatImport(BaseArchCompatImport):
109 arches1_lookup_method_name = 'lookupServerArches' 110 arches2_lookup_method_name = 'lookupPackageArches' 111 arches1_name = 'server-arch' 112 arches2_name = 'package-arch' 113 arches1_field_name = 'server_arch_id' 114 arches2_field_name = 'package_arch_id' 115 submit_method_name = 'processServerPackageArchCompatMap'
116 117
118 -class ServerChannelArchCompatImport(BaseArchCompatImport):
119 arches1_lookup_method_name = 'lookupServerArches' 120 arches2_lookup_method_name = 'lookupChannelArches' 121 arches1_name = 'server-arch' 122 arches2_name = 'channel-arch' 123 arches1_field_name = 'server_arch_id' 124 arches2_field_name = 'channel_arch_id' 125 submit_method_name = 'processServerChannelArchCompatMap'
126 127
128 -class ChannelPackageArchCompatImport(BaseArchCompatImport):
129 arches1_lookup_method_name = 'lookupChannelArches' 130 arches2_lookup_method_name = 'lookupPackageArches' 131 arches1_name = 'channel-arch' 132 arches2_name = 'package-arch' 133 arches1_field_name = 'channel_arch_id' 134 arches2_field_name = 'package_arch_id' 135 submit_method_name = 'processChannelPackageArchCompatMap'
136 137
138 -class ServerGroupServerArchCompatImport(BaseArchCompatImport):
139 arches1_lookup_method_name = 'lookupServerArches' 140 arches2_lookup_method_name = 'lookupServerGroupTypes' 141 arches1_name = 'server-arch' 142 arches2_name = 'server-group-type' 143 arches1_field_name = 'server_arch_id' 144 arches2_field_name = 'server_group_type' 145 submit_method_name = 'processServerGroupServerArchCompatMap' 146 147 # some entitlements are no longer supported, ignore any of them for 148 # backwards compatibility
149 - def _postprocess(self):
150 self.batch[:] = [entry for entry in self.batch if 151 entry[self.arches2_name] not in [ 152 'monitoring_entitled', 'sw_mgr_entitled', 153 'provisioning_entitled', 'nonlinux_entitled', 154 'virtualization_host_platform']] 155 BaseArchCompatImport._postprocess(self)
156