This file is indexed.

/usr/share/pyshared/slapos/entry.py is in slapos-client 0.35.1-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

import argparse
import ConfigParser
import os
import sys
from slapos.client import slapconsole as console
from slapos.client import request as request
from slapos.client import remove as remove
from slapos.client import supply as supply
from slapos.cache import cache_lookup

try:
  from slapos.bang import main as bang
  from slapos.format import main as format
  from slapos.grid.slapgrid import runComputerPartition as instance
  from slapos.grid.slapgrid import runSoftwareRelease as software
  from slapos.grid.slapgrid import runUsageReport as report
  from slapos.grid.svcbackend import supervisord
  from slapos.grid.svcbackend import supervisorctl
  from slapos.register.register import main as register
except ImportError:
  SLAPOS_CLIENT_ONLY = True
else:
  SLAPOS_CLIENT_ONLY = False

from slapos.version import version

# Note: this whole file is a hack. We should better try dedicated library
# like https://github.com/dhellmann/cliff or https://github.com/docopt/docopt.

GLOBAL_SLAPOS_CONFIGURATION = os.environ.get(
    'SLAPOS_CONFIGURATION',
    '/etc/slapos/slapos-node-unofficial.cfg')

USER_SLAPOS_CONFIGURATION = os.environ.get(
    'SLAPOS_CLIENT_CONFIGURATION',
    os.environ.get('SLAPOS_CONFIGURATION', '~/.slapos/slapos.cfg'))

if not os.path.exists(USER_SLAPOS_CONFIGURATION):
  USER_SLAPOS_CONFIGURATION = GLOBAL_SLAPOS_CONFIGURATION

class EntryPointNotImplementedError(NotImplementedError):
  def __init__(self, *args, **kw_args):
    NotImplementedError.__init__(self, *args, **kw_args)

def checkSlaposCfg():
  """
  Check if a slapos configuration file was given as a argument.
  If a slapos configuration file is given it return True else False
  """
  # XXX-Cedric: dangerous but quick way to achieve way to not provide
  # configuration file for each command without changing underlying code.
  # It the long term, it should be done in a better way (no guessing).
  for element in sys.argv:
    if '.cfg' in element:
      if os.path.exists(element):
        configuration = ConfigParser.SafeConfigParser()
        configuration.read(element)
        if configuration.has_section('slapos'):
          return True
  return False

def checkOption(option):
  """
  Check if a given option is already in call line
  Add it and its values if missing
  """
  option = option.split()
  key = option[0]
  for element in sys.argv:
    if key in element:
      return True
  sys.argv.append(key)
  if len(option) > 1 :
    sys.argv = sys.argv + option[1:]
  return True

def call(fun, config=False, option=None):
  """
  Add missing options to sys.argv
  Add config if asked and it is missing
  Call function fun
  """
  if option is None:
    option = []
  for element in option:
    checkOption(element)
  if config:
    if not checkSlaposCfg():
      sys.argv = [sys.argv[0]] + [os.path.expanduser(config)] + sys.argv[1:]
  fun()
  sys.exit(0)

def dispatch(command, is_node_command):
  """ Dispatch to correct SlapOS module.
  Here we could use introspection to get rid of the big "if" statements,
  but we want to control every input.
  Here we give default option and configuration file if they are needed, i.e
  If configuration file is not given: define it arbitrarily, and so on.
  """
  if is_node_command:
    # XXX-Cedric: should we check if we are root?
    if command == 'register':
      call(register)
    elif command == 'software':
      call(software, config=GLOBAL_SLAPOS_CONFIGURATION,
           option=['--pidfile /opt/slapos/slapgrid-sr.pid'])
    elif command == 'instance':
      call(instance, config=GLOBAL_SLAPOS_CONFIGURATION,
           option=['--pidfile /opt/slapos/slapgrid-cp.pid'])
    elif command == 'report':
      call(report, config=GLOBAL_SLAPOS_CONFIGURATION,
           option=['--pidfile /opt/slapos/slapgrid-ur.pid'])
    elif command == 'bang':
      call(bang, config=True)
    elif command == 'format':
      call(format, config=GLOBAL_SLAPOS_CONFIGURATION, option=['-c', '-v'])
    elif command == 'supervisord':
      call(supervisord, config=GLOBAL_SLAPOS_CONFIGURATION)
    elif command == 'supervisorctl':
      call(supervisorctl, config=GLOBAL_SLAPOS_CONFIGURATION)
    elif command in ['start', 'stop', 'restart', 'status', 'tail']:
      # Again, too hackish
      sys.argv[-2:-2] = [command]
      call(supervisorctl, config=GLOBAL_SLAPOS_CONFIGURATION)
    else:
      return False
  elif command == 'request':
    call(request, config=USER_SLAPOS_CONFIGURATION)
  elif command == 'supply':
    call(supply, config=USER_SLAPOS_CONFIGURATION)
  elif command == 'remove':
    call(remove, config=USER_SLAPOS_CONFIGURATION)
  elif command == 'start':
    raise EntryPointNotImplementedError(command)
  elif command == 'stop':
    raise EntryPointNotImplementedError(command)
  elif command == 'destroy':
    raise EntryPointNotImplementedError(command)
  elif command == 'console':
    call(console, config=USER_SLAPOS_CONFIGURATION)
  elif command == 'cache-lookup':
    call(cache_lookup, config=GLOBAL_SLAPOS_CONFIGURATION)
  else:
    return False

def main():
  """
  Main entry point of SlapOS Node. Used to dispatch commands to python
  module responsible of the operation.
  """
  # If "node" arg is the first: we strip it and set a switch
  if len(sys.argv) > 1 and sys.argv[1] == "node" and not SLAPOS_CLIENT_ONLY:
    sys.argv.pop(1)
    # Hackish way to show status if no argument is specified
    if len(sys.argv) is 1:
      sys.argv.append('status')
    is_node = True
  else:
    is_node = False

  usage = """SlapOS %s command line interface.
For more informations, refer to SlapOS documentation.
""" % version

  if SLAPOS_CLIENT_ONLY:
    usage += """
*****IMPORTANT NOTE*****: "node" subcommands are not available because
"slapos-node-unofficial" Debian package is not installed.
"""

  usage += """
Client subcommands usage:
  slapos request <instance-name> <software-url> [--configuration arg1=value1 arg2=value2 ... argN=valueN]
  slapos supply <software-url> <node-id>
  slapos console
  slapos cache-lookup <software-url-or-md5>
"""

  if not SLAPOS_CLIENT_ONLY:
    usage += """
Node subcommands usage:
  slapos node
  slapos node register <node-id>
  slapos node software
  slapos node instance
  slapos node report
  slapos node format
  slapos node start <process>
  slapos node stop <process>
  slapos node restart <process>
  slapos node tail [process]
  slapos node status <process>
  slapos node supervisorctl
  slapos node supervisord
"""

  # Parse arguments
  # XXX remove the "positional arguments" from help message
  parser = argparse.ArgumentParser(usage=usage)
  parser.add_argument('command')
  parser.add_argument('argument_list', nargs=argparse.REMAINDER)

  namespace = parser.parse_args()
  # Set sys.argv for the sub-entry point that we will call
  command_line = [namespace.command]
  command_line.extend(namespace.argument_list)
  sys.argv = command_line

  try:
    if not dispatch(namespace.command, is_node):
      parser.print_help()
      sys.exit(1)
  except EntryPointNotImplementedError, exception:
    print ('The command %s does not exist or is not yet implemented. Please '
        'have a look at http://community.slapos.org to read documentation or '
        'forum. Please also make sure that SlapOS Node is up to '
        'date.' % exception)
    sys.exit(1)