Example #1
0
        def parse_spec(specs, alias=None):
            bits = specs.split('@', 1)
            groups = None
            if len(bits) > 1:
                groups = set(bits[1].split(','))
            bits = bits[0].split(',')

            if len(bits[0].split(':')) > 1:
                address, port = bits[0].split(':')
            else:
                address, port = bits[0], DEFAULT_PORTS['https']

            cred = Options()
            if len(bits) == 1:
                cred.common = DeviceCredential(default_username,
                                               default_password)
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            elif len(bits) == 2:
                cred.common = DeviceCredential(default_username, bits[1])
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            elif len(bits) == 3:
                cred.common = DeviceCredential(bits[1], bits[2])
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            else:
                raise ValueError('Invalid specs: %s', specs)

            device.ports['https'] = port
            device.set_groups(groups)
            return device
Example #2
0
        def parse_spec(specs, alias=None):
            bits = specs.split('@', 1)
            groups = None
            if len(bits) > 1:
                groups = set(bits[1].split(','))
            bits = bits[0].split(',')

            if len(bits[0].split(':')) > 1:
                address, port = bits[0].split(':')
            else:
                address, port = bits[0], DEFAULT_PORTS['https']

            cred = Options()
            if len(bits) == 1:
                cred.common = DeviceCredential(default_username, default_password)
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            elif len(bits) == 2:
                cred.common = DeviceCredential(default_username, bits[1])
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            elif len(bits) == 3:
                cred.common = DeviceCredential(bits[1], bits[2])
                device = DeviceAccess(address, {ADMIN_ROLE: cred})
            else:
                raise ValueError('Invalid specs: %s', specs)

            device.ports['https'] = port
            device.set_groups(groups)
            return device
Example #3
0
        def convert_device(string):
            default_admin_username = self.options.admin_username
            default_admin_password = self.options.admin_password
            default_root_username = self.options.root_username
            default_root_password = self.options.root_password

            bits = string.split(',')

            if len(bits[0].split(':')) > 1:
                address, discover_address = bits[0].split(':')
            else:
                address, discover_address = bits[0], None
            specs = Options()
            specs['discover address'] = discover_address

            admin_cred = Options()
            root_cred = Options()
            if len(bits) == 1:
                admin_cred.common = DeviceCredential(default_admin_username,
                                                     default_admin_password)
                root_cred.common = DeviceCredential(default_root_username,
                                                    default_root_password)
            elif len(bits) == 3:
                admin_cred.common = DeviceCredential(bits[1], bits[2])
                root_cred.common = DeviceCredential(default_root_username,
                                                    default_root_password)
            elif len(bits) == 5:
                admin_cred.common = DeviceCredential(bits[1], bits[2])
                root_cred.common = DeviceCredential(bits[3], bits[4])
            else:
                raise ValueError('Invalid specs: %s', string)

            creds = {ADMIN_ROLE: admin_cred, ROOT_ROLE: root_cred}
            device = DeviceAccess(address, credentials=creds, specs=specs)

            for spec in self.options.https_ports.split(','):
                if len(spec.split(':')) != 2 and spec:
                    raise ValueError('Invalid https input: %s', spec)

            for spec in self.options.ssh_ports.split(','):
                if len(spec.split(':')) != 2 and spec:
                    raise ValueError('Invalid ssh input: %s', spec)

            def create_port_specs(string):
                ret = dict()
                if string:
                    for x in string.split(','):
                        x = x.strip().split(':')
                        ret.update({x[0]: x[1]})
                return ret

            https_by_address = create_port_specs(self.options.https_ports)
            ssh_by_address = create_port_specs(self.options.ssh_ports)

            device.ports['https'] = https_by_address.get(
                address, DEFAULT_PORTS['https'])
            device.ports['ssh'] = ssh_by_address.get(address,
                                                     DEFAULT_PORTS['ssh'])
            device.alias = "device-%s" % device.address

            return device
Example #4
0
        def convert_device(string):
            default_admin_username = self.options.admin_username
            default_admin_password = self.options.admin_password
            default_root_username = self.options.root_username
            default_root_password = self.options.root_password

            bits = string.split(',')

            if len(bits[0].split(':')) > 1:
                address, discover_address = bits[0].split(':')
            else:
                address, discover_address = bits[0], None
            specs = Options()
            specs['discover address'] = discover_address

            admin_cred = Options()
            root_cred = Options()
            if len(bits) == 1:
                admin_cred.common = DeviceCredential(default_admin_username,
                                                     default_admin_password)
                root_cred.common = DeviceCredential(default_root_username,
                                                    default_root_password)
            elif len(bits) == 3:
                admin_cred.common = DeviceCredential(bits[1], bits[2])
                root_cred.common = DeviceCredential(default_root_username,
                                                    default_root_password)
            elif len(bits) == 5:
                admin_cred.common = DeviceCredential(bits[1], bits[2])
                root_cred.common = DeviceCredential(bits[3], bits[4])
            else:
                raise ValueError('Invalid specs: %s', string)

            creds = {ADMIN_ROLE: admin_cred, ROOT_ROLE: root_cred}
            device = DeviceAccess(address, credentials=creds, specs=specs)

            for spec in self.options.https_ports.split(','):
                if len(spec.split(':')) != 2 and spec:
                    raise ValueError('Invalid https input: %s', spec)

            for spec in self.options.ssh_ports.split(','):
                if len(spec.split(':')) != 2 and spec:
                    raise ValueError('Invalid ssh input: %s', spec)

            def create_port_specs(string):
                ret = dict()
                if string:
                    for x in string.split(','):
                        x = x.strip().split(':')
                        ret.update({x[0]: x[1]})
                return ret

            https_by_address = create_port_specs(self.options.https_ports)
            ssh_by_address = create_port_specs(self.options.ssh_ports)

            device.ports['https'] = https_by_address.get(address,
                                                         DEFAULT_PORTS['https'])
            device.ports['ssh'] = ssh_by_address.get(address,
                                                     DEFAULT_PORTS['ssh'])
            device.alias = "device-%s" % device.address

            return device