def create(namespace_name,service_name,container_port,commands,replicas):
    # creating a instance of class Namespace
    body = client.V1ReplicationController()

    # giving name for the namespace as given in the function call
    body.metadata = client.V1ObjectMeta(name=str(service_name)+"-controller")
    
    port_obj = []

    # Creating Port object
    for ports in container_port:
        port = client.V1ContainerPort(container_port=ports["port"],name=ports["name"])
        port_obj.append(port)

    #containers
    container_obj= client.V1Container(name=service_name,image="registry.gokul.com:5000/gokul/" + str(namespace_name) ,command=commands,
    ports=port_obj, resources=client.V1ResourceRequirements(requests={"cpu":"100m"}))

    #pod spec
    pod_spec = client.V1PodSpec(containers=[container_obj])

    #spec template 
    template = client.V1PodTemplateSpec(client.V1ObjectMeta(labels={"app":service_name}),spec=pod_spec)

    #replication specs
    body.spec = client.V1ReplicationControllerSpec(replicas=replicas,selector={"app":service_name},template=template)

    v1.create_namespaced_replication_controller(namespace=namespace_name,body=body)

    return "replication controller created"
def test():
    try:
        
        
        V1NamespaceBody = client.V1Namespace()
        pprint("V1NamespaceBody={}".format(V1NamespaceBody))
        
        V1ObjectReferenceBody = client.V1ObjectReference()
        pprint("V1ObjectReferenceBody={}".format(V1ObjectReferenceBody))    
        
        V1ObjectMetaBody = client.V1ObjectMeta()
        pprint("V1ObjectMetaBody={}".format(V1ObjectMetaBody))    
    
    
        #V1BindingBody = client.V1Binding()
        #pprint("V1BindingBody={}".format(V1BindingBody))    
    
    
        V1ConfigMapBody = client.V1ConfigMap()
        pprint("V1ConfigMapBody={}".format(V1ConfigMapBody))    
    
    
        V1Pod = client.V1Pod()
        pprint("V1Pod={}".format(V1Pod))    
    
    
        V1PodTemplate = client.V1PodTemplate()
        pprint("V1PodTemplate={}".format(V1PodTemplate))    
    
    
        V1ReplicationController = client.V1ReplicationController()
        pprint("V1ReplicationController={}".format(V1ReplicationController))    
    
    
        V1Service = client.V1Service()
        pprint("V1Service={}".format(V1Service))    
    
    
        V1Node = client.V1Node()
        pprint("V1Node={}".format(V1Node))   
        
        pod = 'nginx-no-split-655b866cfd-54xmg'
        namespace='default'
        read_pod = apis_api.read_namespaced_pod(name=pod,namespace=namespace)
        pprint("read_pod={}".format(read_pod))   
        
        lifecycle=read_pod.spec.node_selector.lifecycle
        pprint("lifecycle={}".format(lifecycle))   
        read_pod.spec.node_selector.lifecycle='OnDemand'
        pprint("read_pod={}".format(read_pod))  
        #metadata = read_pod.metadata
        #pprint("metadata={}".format(metadata))   
        #metadata.cluster_name = 'Ec2SpotEKS4'
        #pprint("metadata={}".format(metadata))   
        
    except Exception as e:
        print("Exception when calling CoreV1Api->create_namespace: %s\n" % e)    
예제 #3
0
def create_rc_object(scale, cpu, gpu, instance_name, mem, isSSD):
    resources = client.V1ResourceRequirements(
        requests=dict(cpu=cpu, memory=mem))
    containers = client.V1Container(name=instance_name, resources=resources)
    if isSSD:
        medium = 'memory'
    else:
        medium = 'SSD'

    empty_dir = client.V1EmptyDirVolumeSource(medium=medium, size_limit=mem)
    volumes = client.V1Volume(name=instance_name, empty_dir=empty_dir)
    pod_spec = client.V1PodSpec(containers=[containers], volumes=[volumes])
    template = client.V1PodTemplateSpec(spec=spec)
    rc_spec = client.V1ReplicationControllerSpec(selector=dict(
        name, instance_name),
                                                 replicas=scale,
                                                 template=template)
    metadata = client.V1ObjectMeta(labels=dict(name, instance_name),
                                   name=instance_name)
    rc = client.V1ReplicationController(api_version='corev1',
                                        kind='ReplicationController',
                                        spec=rc_spec,
                                        metadata=metadata)
    return rc
예제 #4
0
    def start(self, id, *args, **kwargs):
        env = {
            "RABBITMQ_HOST": settings.WORKER_RABBITMQ_HOST,
            "RABBITMQ_PORT": int(settings.WORKER_RABBITMQ_PORT),
            "TUMBO_WORKER_THREADCOUNT": settings.TUMBO_WORKER_THREADCOUNT,
            "TUMBO_PUBLISH_INTERVAL": settings.TUMBO_PUBLISH_INTERVAL,
            "TUMBO_CORE_SENDER_PASSWORD": settings.TUMBO_CORE_SENDER_PASSWORD,
            "EXECUTOR": "docker",
            "SERVICE_PORT": self.executor.port,
            "SERVICE_IP": self.executor.ip,
            "secret": self.secret
        }

        worker_env = []
        for k, v in env.iteritems():
            worker_env.append({"name": k, "value": str(v)})

        rc_body = client.V1ReplicationController()
        rc_body.api_version = "v1"
        rc_body.kind = "ReplicationController"
        rc_body.metadata = {'name': self.name}
        spec = client.V1ReplicationControllerSpec()
        spec.replicas = 1

        pretty = 'pretty_example'  # str | If 'true', then the output is pretty printed. (optional)
        rc_manifest = {
            "apiVersion": "v1",
            "kind": "ReplicationController",
            "metadata": {
                "labels": {
                    "service": self.name
                },
                "name": self.name,
                "namespace": self.namespace,
            },
            "spec": {
                "replicas": 1,
                "selector": {
                    "service": self.name
                },
                "template": {
                    "metadata": {
                        "labels": {
                            "service": self.name,
                        }
                    },
                    "spec": {
                        "containers": [{
                            "env":
                            worker_env,
                            "image":
                            "philipsahli/tumbo-worker:kubernetes",
                            "imagePullPolicy":
                            "Always",
                            "name":
                            self.name,
                            "command":
                            self._start_command,
                            "ports": [{
                                "containerPort": 80,
                                "protocol": "TCP"
                            }],
                            "resources": {},
                            "terminationMessagePath":
                            "/dev/termination-log",
                            "terminationMessagePolicy":
                            "File"
                        }],
                        "dnsPolicy":
                        "ClusterFirst",
                        "restartPolicy":
                        "Always",
                        "schedulerName":
                        "default-scheduler",
                        "securityContext": {},
                        "terminationGracePeriodSeconds":
                        30
                    }
                }
            },
            "status": {
                "availableReplicas": 1,
                "fullyLabeledReplicas": 1,
                "observedGeneration": 3,
                "readyReplicas": 1,
                "replicas": 1
            }
        }

        try:
            api_response = self.api.create_namespaced_replication_controller(
                self.namespace, rc_manifest, pretty=pretty)
        except ApiException as e:
            #logger.error(api_response)
            print "Exception when calling CoreV1Api->create_namespaced_replication_controller: %s\n" % e
            raise e

        return api_response.metadata.uid