<commit_before>"""Client support for switch related api calls."""
import json
from hil.client.base import check_reserved_chars
from schema import Schema, SchemaError
from hil.client.base import ClientBase

BROCADE = 'http://schema.massopencloud.org/haas/v0/switches/brocade'
POWERCONNECT_55XX = 'http://schema.massopencloud.org/' \
                    'haas/v0/switches/powerconnect55xx'
NEXUS = 'http://schema.massopencloud.org/haas/v0/switches/nexus'
DELL_NOS9 = 'http://schema.massopencloud.org/haas/v0/switches/dellnos9'
DELL_N3000 = 'http://schema.massopencloud.org/haas/v0/switches/delln3000'
MOCK = 'http://schema.massopencloud.org/haas/v0/switches/mock'

known_types = {
    NEXUS: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': <PASSWORD>,
        'dummy_vlan': basestring,
    }),
    DELL_N3000: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': <PASSWORD>,
        'dummy_vlan': basestring,
    }),
    DELL_NOS9: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'interface_type': basestring,
    }),
    BROCADE: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'interface_type': basestring,
    }),
    POWERCONNECT_55XX: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
    }),
    MOCK: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': <PASSWORD>,
    }),
}


class Switch(ClientBase):
    """Consists of calls to query and manipulate node related

    objects and relations.
    """

    def list(self):
        """List all nodes that HIL manages """
        url = self.object_url('/switches')
        return self.check_response(self.httpClient.request("GET", url))

    def register(self, switch, subtype, *args):
        """Registers a switch with name <switch> and
        model <subtype> , and relevant arguments  in <*args>
        """
        schema = 'http://schema.massopencloud.org/haas/v0/switches/'
        switch_api = schema + subtype
        if switch_api in known_types:
            try:
                known_types[switch_api].validate(args)
            except Exception as e:
                SchemaError("Bad Request " + e)

        if subtype == "nexus" or subtype == "delln3000":
            switchinfo = {
                "type": switch_api,
                "hostname": args[0],
                "username": args[1],
                "password": args[2],
                "dummy_vlan": args[3]}
        elif subtype == "mock":
            switchinfo = {"type": switch_api,
                          "hostname": args[0],
                          "username": args[1], "password": args[2]}
        elif subtype == "powerconnect55xx":
            switchinfo = {"type": switch_api,
                          "hostname": args[0],
                          "username": args[1], "password": args[2]}
        elif subtype == "brocade" or "dellnos9":
            switchinfo = {"type": switch_api,
                         "hostname": args[0],
                         "username": args[1], "password": args[2],
                         "interface_type": args[3]}
        else:
            raise Exception('ERROR: Invalid subtype supplied')

        url = self.object_url('switch', switch)
        payload = json.dumps(switchinfo)
        return self.check_response(
                self.httpClient.request("PUT", url, data=payload)
                )

    @check_reserved_chars()
    def delete(self, switch):
        """Deletes the switch named <switch>."""
        url = self.object_url('switch', switch)
        return self.check_response(self.httpClient.request("DELETE", url))

    @check_reserved_chars()
    def show(self, switch):
        """Shows attributes of <switch>. """
        url = self.object_url('switch', switch)
        return self.check_response(self.httpClient.request("GET", url))


class Port(ClientBase):
    """Port related operations. """<commit_msg>lint again<commit_after>"""Client support for switch related api calls."""
import json
from hil.client.base import check_reserved_chars
from schema import Schema, SchemaError
from hil.client.base import ClientBase

BROCADE = 'http://schema.massopencloud.org/haas/v0/switches/brocade'
POWERCONNECT_55XX = 'http://schema.massopencloud.org/' \
                    'haas/v0/switches/powerconnect55xx'
NEXUS = 'http://schema.massopencloud.org/haas/v0/switches/nexus'
DELL_NOS9 = 'http://schema.massopencloud.org/haas/v0/switches/dellnos9'
DELL_N3000 = 'http://schema.massopencloud.org/haas/v0/switches/delln3000'
MOCK = 'http://schema.massopencloud.org/haas/v0/switches/mock'

known_types = {
    NEXUS: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'dummy_vlan': basestring,
    }),
    DELL_N3000: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'dummy_vlan': basestring,
    }),
    DELL_NOS9: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'interface_type': basestring,
    }),
    BROCADE: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
        'interface_type': basestring,
    }),
    POWERCONNECT_55XX: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
    }),
    MOCK: Schema({
        'hostname': basestring,
        'username': basestring,
        'password': basestring,
    }),
}


class Switch(ClientBase):
    """Consists of calls to query and manipulate node related

    objects and relations.
    """

    def list(self):
        """List all nodes that HIL manages """
        url = self.object_url('/switches')
        return self.check_response(self.httpClient.request("GET", url))

    def register(self, switch, subtype, *args):
        """Registers a switch with name <switch> and
        model <subtype> , and relevant arguments  in <*args>
        """
        schema = 'http://schema.massopencloud.org/haas/v0/switches/'
        switch_api = schema + subtype
        if switch_api in known_types:
            try:
                known_types[switch_api].validate(args)
            except Exception as e:
                SchemaError("Bad Request " + e)

        if subtype == "nexus" or subtype == "delln3000":
            switchinfo = {
                "type": switch_api,
                "hostname": args[0],
                "username": args[1],
                "password": args[2],
                "dummy_vlan": args[3]}
        elif subtype == "mock":
            switchinfo = {"type": switch_api,
                          "hostname": args[0],
                          "username": args[1], "password": args[2]}
        elif subtype == "powerconnect55xx":
            switchinfo = {"type": switch_api,
                          "hostname": args[0],
                          "username": args[1], "password": args[2]}
        elif subtype == "brocade" or "dellnos9":
            switchinfo = {"type": switch_api,
                          "hostname": args[0],
                          "username": args[1], "password": args[2],
                          "interface_type": args[3]}
        else:
            raise Exception('ERROR: Invalid subtype supplied')

        url = self.object_url('switch', switch)
        payload = json.dumps(switchinfo)
        return self.check_response(
                self.httpClient.request("PUT", url, data=payload)
                )

    @check_reserved_chars()
    def delete(self, switch):
        """Deletes the switch named <switch>."""
        url = self.object_url('switch', switch)
        return self.check_response(self.httpClient.request("DELETE", url))

    @check_reserved_chars()
    def show(self, switch):
        """Shows attributes of <switch>. """
        url = self.object_url('switch', switch)
        return self.check_response(self.httpClient.request("GET", url))


class Port(ClientBase):
    """Port related operations. """
{'fraction_non_alphanumeric': 0.1318921544814185, 'fraction_numerical': 0.011901870293903327, 'mean_word_length': 2.2130316035895436, 'pattern_counts': {'":': 44, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2183930', 'n_tokens_mistral': 2476, 'n_tokens_neox': 2392, 'n_words': 527}