Exemple #1
0
def main():
  try:
    shortflags = 'h'
    longflags = ['help', 'user-id=', 'user-pw=', 'url=', 'encoding=']
    opts, args = getopt.gnu_getopt(sys.argv[1:], shortflags, longflags)
  except getopt.GetoptError:
    PrintUsageAndExit()
  user_idflag = None
  user_passwordflag = None
  encoding = None
  url = None
  for o, a in opts:
    if o in ("-h", "--help"):
      PrintUsageAndExit()
    if o in ("--user-id"):
      user_idflag = a
    if o in ("--user-pw"):
      user_passwordflag = a
    if o in ("--encoding"):
      encoding = a
    if o in ("--url"):
      url = a

  if url is None:
    PrintUsageAndExit()

  rc = KubernetesRc()
  user_id = user_idflag or GetUserIDKeyEnv() or rc.GetUserIdKey()
  user_password = user_passwordflag or GetUserPasswordEnv() or rc.GetUserPasswordKey()

  print user_id
  print user_password
  
  if not user_id or not user_password:
    PrintUsageAndExit()

  api = kubernetes.Api(user_id=user_id, user_password=user_password,
                    input_encoding=encoding,
                    base_url=url,
                    debugHTTP=True)
  try:
    pod_list = api.GetPods()
  except UnicodeDecodeError:
    print "Error!! "
    sys.exit(2)
  print "GetPods: %s" % (pod_list.AsJsonString())

  try:
    pod_list = api.GetReplicationControllers()
  except UnicodeDecodeError:
    print "Error!! "
    sys.exit(2)
  print "GetReplicationControllers: %s" % (pod_list.AsJsonString())

  try:
    pod_list = api.GetServices()
  except UnicodeDecodeError:
    print "Error!! "
    sys.exit(2)
  print "GetServices: %s" % (pod_list.AsJsonString())
Exemple #2
0
 def get_client(self):
     client = None
     if KUBERNETES_INSTALLED:
         base_url = ('%s/api/%s' %
                     (self.properties.get(self.KUBERNETES_ENDPOINT),
                      self.properties.get("v1" if self.APIVERSION ==
                                          "v1beta3" else self.APIVERSION)))
         client = kubernetes.Api(base_url=base_url,
                                 token=self.properties.get(
                                     self.TOKEN, None))
     return client
Exemple #3
0
def get_kube_client(request_headers=None):
    kube_client = kubernetes.Api(base_url='{}/api/v1'.format(
        config.K8S_API_SERVER),
                                 request_headers=request_headers)
    return kube_client
Exemple #4
0
def main():
    try:
        shortflags = 'h'
        longflags = [
            'help', 'rc-data-new=', 'rc-data=', 'pod-data=', 'service-data=',
            'version=', 'host=', 'namespace=', 'user-id=', 'user-pw=', 'url=',
            'encoding='
        ]
        opts, args = getopt.gnu_getopt(sys.argv[1:], shortflags, longflags)
    except getopt.GetoptError:
        PrintUsageAndExit()

    user_idflag = None
    user_passwordflag = None
    encoding = None
    url = None
    namespace = None
    version = 'v1beta3'
    host = '172.30.10.185'
    rc_data = None
    rc_data_new = None
    service_data = None
    pod_data = None
    for o, a in opts:
        #if o in ("-h", "--help"):
        #PrintUsageAndExit()
        #if o in ("--user-id"):
        #user_idflag = a
        #if o in ("--user-pw"):
        #user_passwordflag = a
        #if o in ("--encoding"):
        #encoding = a
        #if o in ("--url"):
        #url = a
        if o in ("--namespace"):
            namespace = a
        if o in ("--host"):
            host = a
        if o in ("--version"):
            version = a
        if o in ("--pod-data"):
            pod_data = a
        if o in ("--rc-data"):
            rc_data = a
        if o in ("--rc-data-new"):
            rc_data_new = a
        if o in ("--service-data"):
            service_data = a

    rc = KubernetesRc()

    #user_id = user_idflag or GetUserIDKeyEnv() or rc.GetUserIdKey()
    #user_password = user_passwordflag or GetUserPasswordEnv() or rc.GetUserPasswordKey()

    #print user_id
    #print user_password

    #if not user_id or not user_password:
    #PrintUsageAndExit()
    def _gen_url(host, version):
        return 'https://%s:8080/api/%s' % (host, version)

    api = kubernetes.Api(input_encoding=encoding,
                         base_url=_gen_url(host, version),
                         debugHTTP=True,
                         cert_path='/home/paasuser1/source/cret/kubecfg.crt',
                         token='myToken5')

    #try create first

    rc_obj = None
    try:
        if rc_data:
            f = open(rc_data)
            content = f.read()
            f.close()
            rc_obj = api.CreateReplicationController(data=content,
                                                     namespace=namespace)
        if service_data:
            f = open(service_data)
            content = f.read()
            api.CreateService(data=content, namespace=namespace)
    except KubernetesError, e:
        print e.message
Exemple #5
0
import etcd
import config
import kubernetes
import flask
import json
import uuid
import os
import datetime

etcd_client = etcd.Client(host=config.ETCD_IP, port=config.ETCD_PORT)

base_url = 'http://%s:8080/api/v1' % (config.K8S_IP)
kube_client = kubernetes.Api(base_url=base_url)


def make_status_response(code, message=''):
    response = flask.make_response(
        json.dumps({
            'kind': 'Status',
            'code': code,
            'message': message
        }))
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response


def dump_app_json_into_file(namespace, content):
    DIR = '/tmp/paas'
    if not os.path.exists(DIR):
        os.mkdir(DIR)
Exemple #6
0
import time
import requests
import kubernetes
import eventlet
from eventlet import greenthread
from settings import settings
import copy
import etcd
import json
import os

from httplib2 import Http

from log import LOG

kube_client = kubernetes.Api(base_url=settings.K8S_API_SERVER)
etcd_client = etcd.Client(host=settings.ETCD_SERVER, port=settings.ETCD_PORT)

TIMEOUT = 10.0


def get_app_json(app_name):
    response = requests.get('{}/api/v1/applications/{}'.format(
        settings.PAAS_API_SERVER, app_name),
                            timeout=TIMEOUT)
    app_json = response.json()
    if app_json['kind'] == 'Application':
        return app_json
    else:
        return None