How to use get_sdk_type method in localstack

Best Python code snippet using localstack_python

netlib.py

Source:netlib.py Github

copy

Full Screen

...28 VIRTIO = types.NicInterface.VIRTIO29class Network(SDKSubEntity):30 @property31 def name(self):32 return self.get_sdk_type().name33 def create(34 self,35 name,36 vlan=None,37 usages=(NetworkUsage.VM,),38 qos=None,39 auto_generate_profile=True,40 external_provider=None,41 external_provider_physical_network=None,42 mtu=None,43 port_isolation=None,44 ):45 """46 :type name: string47 :type vlan: integer48 :type usages: (netlib.NetworkUsage,)49 :type qos: netlib.QoS50 :type auto_generate_profile: bool51 :type external_provider: providerlib.OpenStackNetworkProvider52 :type external_provider_physical_network: netlib.Network53 :type mtu: integer54 :type port_isolation: bool55 """56 qos_type = None if qos is None else qos.get_sdk_type()57 sdk_type = types.Network(58 name=name,59 data_center=self._parent_sdk_entity.service.get(),60 usages=usages,61 qos=qos_type,62 profile_required=auto_generate_profile,63 mtu=mtu,64 port_isolation=port_isolation,65 )66 if vlan is not None:67 sdk_type.vlan = types.Vlan(id=vlan)68 if external_provider is not None:69 sdk_type.external_provider = types.OpenStackNetworkProvider(id=external_provider.id)70 if external_provider_physical_network is not None:71 if external_provider is None:72 raise ExternalProviderRequired73 sdk_type.external_provider_physical_network = types.Network(id=external_provider_physical_network.id)74 self._create_sdk_entity(sdk_type)75 def _get_parent_service(self, dc):76 return dc.service.networks_service()77 def labels(self):78 return self._system_network_service().network_labels_service().list()79 def vnic_profiles(self):80 profiles = self._system_network_service().vnic_profiles_service().list()81 vnic_profiles = []82 for profile in profiles:83 vnic_profile = VnicProfile(self.system)84 vnic_profile.import_by_id(profile.id)85 vnic_profiles.append(vnic_profile)86 return vnic_profiles87 def vnic_profile(self, name=None):88 """89 :param name: if no name is specified the default name for a vnic90 profile is assumed, which is the network name91 """92 profile_name = self.name if name is None else name93 return next(vnic_profile for vnic_profile in self.vnic_profiles() if vnic_profile.name == profile_name)94 def _system_network_service(self):95 return self.system.networks_service.network_service(self.id)96 def __repr__(self):97 return self._execute_without_raising(98 lambda: (99 f'<{self.__class__.__name__}| '100 f'name:{self.name}, '101 f'qos:{self.get_sdk_type().qos}, '102 f'mtu:{self.get_sdk_type().mtu}, '103 f'vlan:{self.get_sdk_type().vlan}, '104 f'dc:{self._parent_sdk_entity}, '105 f'id:{self.id}>'106 )107 )108 @staticmethod109 def get_networks_ids(networks):110 """111 :param networks: []netlib.Network112 :return: frozenset(String)113 """114 return frozenset(network.id for network in networks)115class VnicProfile(SDKRootEntity):116 @property117 def name(self):118 return self.get_sdk_type().name119 def create(self, name, network, qos=None):120 qos_type = None if qos is None else qos.get_sdk_type()121 sdk_type = types.VnicProfile(name=name, network=network.get_sdk_type(), qos=qos_type)122 self._create_sdk_entity(sdk_type)123 def _get_parent_service(self, system):124 return system.vnic_profiles_service125 @property126 def filter(self):127 sdk_network_filter = self.get_sdk_type().network_filter128 if sdk_network_filter:129 network_filter = NetworkFilter(self.system)130 network_filter.import_by_id(sdk_network_filter.id)131 return network_filter132 return None133 @filter.setter134 def filter(self, new_filter):135 new_filter_id = None if new_filter is None else new_filter.id136 new_sdk_filter = types.NetworkFilter(id=new_filter_id)137 self.update(network_filter=new_sdk_filter)138 @staticmethod139 def iterate(system):140 for sdk_obj in system.vnic_profiles_service.list():141 profile = VnicProfile(system)142 profile.import_by_id(sdk_obj.id)143 yield profile144 @property145 def custom_properties(self):146 sdk_custom_properties = self.service.get().custom_properties or []147 return [CustomProperty(p.name, p.value) for p in sdk_custom_properties]148 @custom_properties.setter149 def custom_properties(self, properties):150 service = self.service.get()151 service.custom_properties = [types.CustomProperty(name=p.name, value=p.value) for p in properties]152 self.service.update(service)153 def __repr__(self):154 return self._execute_without_raising(155 lambda: (156 f'<{self.__class__.__name__}| '157 f'name:{self.name}, '158 f'filter:{self.filter}, '159 f'custom_props:{[(p.name, p.value) for p in self.custom_properties]}'160 f'id:{self.id}>'161 )162 )163class Vnic(SDKSubEntity):164 @property165 def name(self):166 return self.get_sdk_type().name167 @property168 def plugged(self):169 return self.get_sdk_type().plugged170 @property171 def linked(self):172 return self.get_sdk_type().linked173 @linked.setter174 def linked(self, linked):175 sdk_type = self.get_sdk_type()176 sdk_type.linked = linked177 self._service.update(sdk_type)178 @property179 def mac_address(self):180 return self.get_sdk_type().mac.address181 @mac_address.setter182 def mac_address(self, address):183 sdk_type = self.get_sdk_type()184 sdk_type.mac.address = address185 self._service.update(sdk_type)186 def create(187 self,188 name,189 vnic_profile,190 interface=VnicInterfaceType.VIRTIO,191 mac_addr=None,192 ):193 """194 :type name: string195 :type vnic_profile: netlib.VnicProfile196 :type interface: netlib.VnicInterfaceType197 :type mac_addr: string198 """199 sdk_type = types.Nic(200 name=name,201 interface=interface,202 vnic_profile=vnic_profile.get_sdk_type(),203 )204 if mac_addr is not None:205 sdk_type.mac = types.Mac(address=mac_addr)206 try:207 self._create_sdk_entity(sdk_type)208 except EntityCreationError as err:209 message = err.args[0]210 if 'MAC Address' in message and 'in use' in message:211 raise MacAddrInUseError(message)212 elif 'Not enough MAC addresses' in message:213 raise MacPoolIsInFullCapacityError(message)214 raise215 def hotunplug(self):216 self._service.deactivate()217 def hotplug(self):218 self._service.activate()219 def hot_replace_mac_addr(self, mac_addr):220 self.hotunplug()221 self.mac_address = mac_addr222 self.hotplug()223 def hot_replace_profile(self, profile):224 time.sleep(15)225 self.hotunplug()226 self.vnic_profile = profile227 time.sleep(15)228 self.hotplug()229 @contextlib.contextmanager230 def toggle_profile(self, profile):231 original_profile = self.vnic_profile232 self.hot_replace_profile(profile)233 try:234 yield235 finally:236 self.hot_replace_profile(original_profile)237 def _get_parent_service(self, vm):238 return vm.service.nics_service()239 @property240 def vnic_profile(self):241 sdk_profile = self.get_sdk_type().vnic_profile242 if sdk_profile is None:243 return EmptyVnicProfile()244 profile = VnicProfile(self._parent_sdk_entity._parent_sdk_system)245 profile.import_by_id(sdk_profile.id)246 return profile247 @vnic_profile.setter248 def vnic_profile(self, new_profile):249 sdk_nic = self.get_sdk_type()250 if sdk_nic.vnic_profile is None:251 sdk_nic.vnic_profile = new_profile.get_sdk_type()252 sdk_nic.vnic_profile.id = new_profile.id253 self.service.update(sdk_nic)254 def __repr__(self):255 return self._execute_without_raising(256 lambda: (257 f'<{self.__class__.__name__}| '258 f'name:{self.name}, '259 f'linked:{self.linked}, '260 f'synced:{self.get_sdk_type().synced}, '261 f'plugged:{self.get_sdk_type().plugged}, '262 f'mac:{self.mac_address}, '263 f'id:{self.id}>'264 )265 )266class NetworkFilter(SDKRootEntity):267 @property268 def name(self):269 return self.get_sdk_type().name270 def _get_parent_service(self, system):271 return system.network_filters_service272 def create(self):273 raise NotImplementedError('oVirt connot create NetworkFilters')274 def __repr__(self):275 return self._execute_without_raising(lambda: f'<{self.__class__.__name__}| name:{self.name}, id:{self.id}>')276class QoS(SDKSubEntity):277 @property278 def name(self):279 return self.get_sdk_type().name280 def create(281 self,282 name,283 qos_type,284 inbound_average=None,285 inbound_peak=None,286 inbound_burst=None,287 outbound_average=None,288 outbound_peak=None,289 outbound_burst=None,290 outbound_average_upperlimit=None,291 outbound_average_realtime=None,292 outbound_average_linkshare=None,293 ):294 self._create_sdk_entity(295 types.Qos(296 name=name,297 type=qos_type,298 inbound_average=inbound_average,299 inbound_peak=inbound_peak,300 inbound_burst=inbound_burst,301 outbound_average=outbound_average,302 outbound_peak=outbound_peak,303 outbound_burst=outbound_burst,304 outbound_average_upperlimit=outbound_average_upperlimit,305 outbound_average_realtime=outbound_average_realtime,306 outbound_average_linkshare=outbound_average_linkshare,307 )308 )309 self.get_sdk_type().id = self.id310 def _get_parent_service(self, dc):311 return dc.service.qoss_service()312class EmptyVnicProfile(object):313 """314 Class needed to mimic the API behaviour.315 Engine defines an empty vnic profile by assigning no profile316 to the vnic.317 This class represents an empty API concrete type hidden318 behind the methods that are needed by other netlib319 classes.320 There are two flows thad needs to covered with321 this class:322 1. vnic creation with empty vnic does not need profile323 to be specified -> profile can be None or empty concrete324 sdk type325 2. vnic profile change into empty requires326 profile to be specified with None id327 """328 @property329 def id(self):330 return None331 def get_sdk_type(self):332 return types.VnicProfile()333@contextlib.contextmanager334def create_vnic_profile(system, name, network, qos=None):335 vnic_p = VnicProfile(system)336 vnic_p.create(name, network, qos)337 try:338 yield vnic_p339 finally:340 vnic_p.remove()341@contextlib.contextmanager342def new_network(name, dc, vlan=None, port_isolation=None):343 network = Network(dc)344 network.create(name=name, vlan=vlan, port_isolation=port_isolation)345 try:...

Full Screen

Full Screen

BotMonitorConfig.py

Source:BotMonitorConfig.py Github

copy

Full Screen

...9 @staticmethod10 def get_sdk_version():11 return '2.0.0'12 @staticmethod13 def get_sdk_type():14 return 'python'15 @staticmethod16 def get_upload_port():17 return 44318 @staticmethod19 def get_upload_path():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful