Best Python code snippet using autotest_python
host.py
Source:host.py  
...343        self.platform = getattr(options, 'platform', None)344        if options.protection:345            self.data['protection'] = options.protection346        return (options, leftover)347    def _execute_add_one_host(self, host):348        # Always add the hosts as locked to avoid the host349        # being picked up by the scheduler before it's ACL'ed350        self.data['locked'] = True351        self.execute_rpc('add_host', hostname=host,352                         status="Ready", **self.data)353        # Now add the platform label354        labels = self.labels[:]355        if self.platform:356            labels.append(self.platform)357        if len(labels):358            self.execute_rpc('host_add_labels', id=host, labels=labels)359    def execute(self):360        # We need to check if these labels & ACLs exist,361        # and create them if not.362        if self.platform:363            self.check_and_create_items('get_labels', 'add_label',364                                        [self.platform],365                                        platform=True)366        if self.labels:367            self.check_and_create_items('get_labels', 'add_label',368                                        self.labels,369                                        platform=False)370        if self.acls:371            self.check_and_create_items('get_acl_groups',372                                        'add_acl_group',373                                        self.acls)374        success = self.site_create_hosts_hook()375        if len(success):376            for acl in self.acls:377                self.execute_rpc('acl_group_add_hosts', id=acl, hosts=success)378            if not self.locked:379                for host in success:380                    self.execute_rpc('modify_host', id=host, locked=False)381        return success382    def site_create_hosts_hook(self):383        success = []384        for host in self.hosts:385            try:386                self._execute_add_one_host(host)387                success.append(host)388            except topic_common.CliError:389                pass390        return success391    def output(self, hosts):392        self.print_wrapped('Added host', hosts)393class host_delete(action_common.atest_delete, host):394    """atest host delete [--mlist <mach_file>] <hosts>"""...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
