Пример #1
0
 def value(self, new_value):
     for v in new_value or []:
         part1, sep, part2 = v.partition(',')
         netid, ip = '', ''
         if part1.startswith('id='):
             netid = part1[len('id='):]
         elif part1.startswith('ip='):
             ip = part1[len('ip='):]
         else:
             netid = part1
         if part2:
             if (part2.startswith('id=') and netid) or (
                     part2.startswith('ip=') and ip):
                 raise CLIInvalidArgument(
                     'Invalid network argument %s' % v,
                     details=['Valid format: [id=]NETWORK_ID[,[ip=]IP]'])
             if part2.startswith('id='):
                 netid = part2[len('id='):]
             elif part2.startswith('ip='):
                 ip = part2[len('ip='):]
             elif netid:
                 ip = part2
             else:
                 netid = part2
         if not netid:
             raise CLIInvalidArgument(
                 'Invalid network argument %s' % v,
                 details=['Valid format: [id=]NETWORK_ID[,[ip=]IP]'])
         self._value = getattr(self, '_value', [])
         self._value.append(dict(uuid=netid))
         if ip:
             self._value[-1]['fixed_ip'] = ip
Пример #2
0
    def value(self, newvalue):
        if newvalue == self.default:
            return self.value
        self._value, input_dict = [], {}
        for i, terms in enumerate(newvalue):
            termlist = terms.split(',')
            if len(termlist) > len(self.terms):
                msg = 'Wrong number of terms (1<=terms<=%s)' % len(self.terms)
                raise CLIError(CLISyntaxError(msg), details=howto_personality)

            for k, v in self.terms:
                prefix = '%s=' % k
                for item in termlist:
                    if item.lower().startswith(prefix):
                        input_dict[k] = item[len(k) + 1:]
                        break
                    item = None
                if item:
                    termlist.remove(item)

            try:
                path = input_dict['local-path']
            except KeyError:
                path = termlist.pop(0)
                if not path:
                    raise CLIInvalidArgument(
                        '--personality: No local path specified',
                        details=howto_personality)

            if not exists(path):
                raise CLIInvalidArgument(
                    '--personality: File %s does not exist' % path,
                    details=howto_personality)

            self._value.append(dict(path=path))
            with open(expanduser(path)) as f:
                self._value[i]['contents'] = b64encode(f.read())
            for k, v in self.terms[1:]:
                try:
                    self._value[i][v] = input_dict[k]
                except KeyError:
                    try:
                        self._value[i][v] = termlist.pop(0)
                    except IndexError:
                        continue
                if k in ('mode', ) and self._value[i][v]:
                    try:
                        self._value[i][v] = int(self._value[i][v], 8)
                    except ValueError as ve:
                        raise CLIInvalidArgument(
                            'Personality mode must be in octal', details=[
                                '%s' % ve])
Пример #3
0
 def value(self, new_policy):
     if new_policy:
         if new_policy.lower() in self.policies:
             self._value = new_policy.lower()
         else:
             raise CLIInvalidArgument(
                 'Invalid value for %s' % self.lvalue,
                 details=['Valid values: %s' % ', '.join(self.policies)])
Пример #4
0
 def value(self, new_value):
     if new_value:
         v = new_value.lower()
         if v not in ('true', 'false'):
             raise CLIInvalidArgument(
                 'Invalid value %s=%s' % (self.lvalue, new_value),
                 details=['Usage:', '%s=<true|false>' % self.lvalue])
         self._value = bool(v == 'true')
Пример #5
0
 def main(self, project_id):
     super(self.__class__, self)._run()
     if self['private'] and self['public']:
         a = self.arguments
         raise CLIInvalidArgument(
             'Invalid argument combination', details=[
                 'Arguments %s and %s are mutually exclussive' % (
                     a['private'].lvalue, a['public'].lvalue)])
     self._run(project_id=project_id)
Пример #6
0
 def value(self, newvalue):
     if newvalue:
         try:
             self._value = dateutil.parser.parse(newvalue)
         except Exception:
             raise CLIInvalidArgument(
                 'Invalid value "%s" for date argument %s' %
                 (newvalue, self.lvalue),
                 details=['Suggested formats:'] + self.INPUT_FORMATS)
Пример #7
0
 def main(self, server_id):
     super(self.__class__, self)._run()
     pnpid = self.arguments['public_network_port_id']
     fp = self.arguments['firewall_profile']
     if pnpid.value and not fp.value:
         raise CLIInvalidArgument('Invalid argument compination', details=[
             'Argument %s should always be combined with %s' % (
                 pnpid.lvalue, fp.lvalue)])
     self._run(server_id=server_id)
Пример #8
0
 def main(self):
     super(self.__class__, self)._run()
     if self['no_network'] and self['network_configuration']:
         raise CLIInvalidArgument(
             'Invalid argument combination', importance=2, details=[
                 'Arguments %s and %s are mutually exclusive' % (
                     self.arguments['no_network'].lvalue,
                     self.arguments['network_configuration'].lvalue)])
     self._run()
Пример #9
0
 def value(self, new_profile):
     if new_profile:
         new_profile = new_profile.upper()
         if new_profile in self.profiles:
             self._value = new_profile
         else:
             raise CLIInvalidArgument(
                 'Invalid firewall profile %s' % new_profile,
                 details=['Valid values: %s' % ', '.join(self.profiles)])
Пример #10
0
 def value(self, newvalue):
     if not newvalue:
         return
     elif newvalue.lower() in self.formats:
         self.value = newvalue.lower()
     else:
         raise CLIInvalidArgument(
             'Invalid value %s for argument %s' % (newvalue, self.lvalue),
             details=['Valid output formats: %s' % ', '.join(self.formats)])
Пример #11
0
 def value(self, new_status):
     if new_status:
         new_status = new_status.upper()
         if new_status not in self.valid_states:
             raise CLIInvalidArgument(
                 'Invalid argument %s' % new_status,
                 details=['Usage:', '%s=[%s]' % (
                     self.lvalue, '|'.join(self.valid_states))])
         self._value = new_status
Пример #12
0
 def value(self, new_value):
     if new_value and new_value.upper() in self.types:
         self._value = new_value.upper()
     elif new_value:
         raise CLIInvalidArgument('Invalid network type %s' % new_value,
                                  details=[
                                      'Valid types: %s' %
                                      ', '.join(self.types),
                                  ])
Пример #13
0
 def main(self, server_id):
     super(self.__class__, self)._run()
     choose_one = ('nics', 'stats', 'diagnostics')
     count = len([a for a in choose_one if self[a]])
     if count > 1:
         raise CLIInvalidArgument('Invalid argument combination', details=[
             'Arguments %s cannot be used simultaneously' % ', '.join(
                 [self.arguments[a].lvalue for a in choose_one])])
     self._run(server_id=server_id)
Пример #14
0
 def main(self):
     super(self.__class__, self)._run()
     self._req2 = [arg for arg in self.required if arg != 'specs_path']
     if not (self['specs_path'] or all(self[arg] for arg in self._req2)):
         raise CLIInvalidArgument('Insufficient arguments', details=[
             'Both of the following arguments are needed:',
             ', '.join([self.arguments[arg].lvalue for arg in self._req2]),
             'OR provide a spec file (json) with %s' % self.arguments[
                 'specs_path'].lvalue,
             'OR combine arguments (higher priority) with a file'])
     self._run()
Пример #15
0
 def main(self):
     super(self.__class__, self)._run()
     if self['gateway'] and self['no_gateway']:
         raise CLIInvalidArgument(
             'Conflicting arguments',
             details=[
                 'Arguments %s and %s cannot be used together' %
                 (self.arguments['gateway'].lvalue,
                  self.arguments['no_gateway'].lvalue)
             ])
     self._run()
Пример #16
0
 def main(self, volume_id):
     super(self.__class__, self)._run()
     if all([self['status_w'], self['status_u']]):
         raise CLIInvalidArgument(
             'Invalid argument combination',
             importance=2,
             details=[
                 'Arguments %s and %s are mutually exclusive' %
                 (self.arguments['status_w'].lvalue,
                  self.arguments['status_u'].lvalue)
             ])
     self._run(volume_id=volume_id)
Пример #17
0
 def value(self, new_value):
     global _basic_cons
     if new_value:
         v = new_value.lower()
         v = self.TRANSLATE.get(v, v)
         if v in _basic_cons:
             self._value = v
         else:
             ctypes = set(_basic_cons).difference(self.TRANSLATE.values())
             ctypes = list(ctypes) + [
                 '%s (aka %s)' % (a, t) for t, a in self.TRANSLATE.items()]
             raise CLIInvalidArgument(
                 'Invalid console type %s' % new_value, details=[
                     'Valid console types: %s' % (', '.join(ctypes)), ])
Пример #18
0
 def value(self, new_pools):
     if not new_pools:
         return
     new_list = []
     for pool in new_pools:
         start, comma, end = pool.partition(',')
         if not (start and comma and end):
             raise CLIInvalidArgument(
                 'Invalid allocation pool argument %s' % pool,
                 details=[
                     'Allocation values must be of the form:',
                     '  <start address>,<end address>'
                 ])
         new_list.append(dict(start=start, end=end))
     self._value = new_list
Пример #19
0
    def main(self, server_id):
        super(self.__class__, self)._run()

        status_args = [self['status'], self['status_w'], self['status_u']]
        if len([x for x in status_args if x]) > 1:
            raise CLIInvalidArgument(
                'Invalid argument combination', importance=2, details=[
                    'Arguments %s, %s and %s are mutually exclusive' % (
                        self.arguments['status'].lvalue,
                        self.arguments['status_w'].lvalue,
                        self.arguments['status_u'].lvalue)])
        if self['status']:
            self.error(
                'WARNING: argument %s will be deprecated '
                'in the next version, use %s instead' % (
                    self.arguments['status'].lvalue,
                    self.arguments['status_w'].lvalue))

        self._run(server_id=server_id)
Пример #20
0
 def value(self, location):
     if location:
         from kamaki.cli.cmds.pithos import _PithosContainer as pc
         try:
             uuid, self.container, self.path = pc.resolve_pithos_url(
                 location)
             self.uuid = uuid or self.uuid
             assert self.container, 'No container in pithos URI'
         except Exception as e:
             raise CLIInvalidArgument(
                 'Invalid Pithos+ location %s (%s)' % (location, e),
                 details=[
                     'The image location must be a valid Pithos+',
                     'location. There are two valid formats:',
                     '  pithos://USER_UUID/CONTAINER[/PATH]',
                     'OR',
                     '  /CONTAINER[/PATH]',
                     'To see all containers:',
                     '  [kamaki] container list',
                     'To list the contents of a container:',
                     '  [kamaki] container list CONTAINER'])
Пример #21
0
 def main(self):
     super(self.__class__, self)._run()
     locator, pithos = self.arguments['pithos_location'], None
     locator.setdefault('uuid', self.astakos.user_term('id'))
     locator.path = locator.path or path.basename(
         self['local_image_path'] or '')
     if not locator.path:
         raise CLIInvalidArgument(
             'Missing the image file or object', details=[
                 'Pithos+ URI %s does not point to a physical image' % (
                     locator.value),
                 'A physical image is necessary.',
                 'It can be a remote Pithos+ object or a local file.',
                 'To specify a remote image object:',
                 '  %s [pithos://UUID]/CONTAINER/PATH' % locator.lvalue,
                 'To specify a local file:',
                 '  %s [pithos://UUID]/CONTAINER[/PATH] %s LOCAL_PATH' % (
                     locator.lvalue,
                     self.arguments['local_image_path'].lvalue)])
     self.arguments['pithos_location'].setdefault(
         'uuid', self.astakos.user_term('id'))
     self._run(self['name'], locator)
Пример #22
0
 def value(self, key_value_pairs):
     if key_value_pairs:
         super(ProjectResourceArgument, self.__class__).value.fset(
             self, key_value_pairs)
         d = dict(self._value)
         for key, value in d.items():
             try:
                 member_capacity, project_capacity = value.split(',')
                 member_capacity = int(member_capacity)
                 project_capacity = int(project_capacity)
                 assert member_capacity <= project_capacity
             except Exception as e:
                 raise CLIInvalidArgument(
                     'Invalid resource value %s' % value, details=[
                         'Usage:',
                         '  %s %s=<member_capacity>,<project_capacity>' % (
                             self.lvalue, key),
                         'where both capacities are integers',
                         'and member_capacity <= project_capacity', '',
                         '(%s)' % e])
             self._value[key] = dict(
                 member_capacity=member_capacity,
                 project_capacity=project_capacity)
Пример #23
0
 def test___init__(self):
     from kamaki.cli.errors import CLIInvalidArgument
     cliia = CLIInvalidArgument()
     self.assertEqual('%s' % cliia, 'Invalid Argument\n')
     self.assertEqual(cliia.details, [])
     self.assertEqual(cliia.importance, 1)