Esempio n. 1
0
func (this *ServiceService) CreateBoth(data []byte) Service {
	var data_format struct {
		Service_name    string            `json:"service_name"`
		Port            string            `json:"port"`
		Container_count string            `json:"container_count"`
		Cpu             string            `json:"cpu"`
		Image           string            `json:"image"`
		Label           map[string]string `json:"label"`
	}
	json.Unmarshal(data, &data_format)

	var _k8s_service k8s_format.Service
	_k8s_service.Kind = "Service"
	_k8s_service.Metadata.Name = data_format.Service_name
	_k8s_service.Metadata.Labels = data_format.Label
	_k8s_service.Metadata.Labels["name"] = data_format.Service_name
	_k8s_service.Spec.Type = "NodePort"
	_k8s_service.Spec.Selector = map[string]string{"name": data_format.Service_name}

	var _k8s_service_ports k8s_format.ServicePort
	_k8s_service_ports.Port, _ = strconv.Atoi(data_format.Port)
	_k8s_service_ports.TargetPort, _ = strconv.Atoi(data_format.Port)
	_k8s_service_ports.Protocol = "TCP"
	_k8s_service.Spec.Ports = append(_k8s_service.Spec.Ports, _k8s_service_ports)

	var k8s_rc k8s_format.ReplicationController
	k8s_rc.Kind = "ReplicationController"
	k8s_rc.Metadata.Name = data_format.Service_name
	k8s_rc.Metadata.Labels = data_format.Label
	k8s_rc.Metadata.Labels["name"] = data_format.Service_name
	k8s_rc.Spec.Replicas, _ = strconv.Atoi(data_format.Container_count)
	k8s_rc.Spec.Selector = map[string]string{"name": data_format.Service_name}
	k8s_rc.Spec.Template.Metadata.Labels = map[string]string{"name": data_format.Service_name}

	var k8s_rc_container_port k8s_format.ContainerPort
	k8s_rc_container_port.ContainerPort, _ = strconv.Atoi(data_format.Port)

	var k8s_rc_container k8s_format.Container
	k8s_rc_container.Name = data_format.Service_name
	k8s_rc_container.Image = data_format.Image
	k8s_rc_container.Ports = append(k8s_rc_container.Ports, k8s_rc_container_port)
	k8s_rc.Spec.Template.Spec.Containers = append(k8s_rc.Spec.Template.Spec.Containers, k8s_rc_container)

	var rc_model k8sModel.ReplicationControllerModel
	var service_model k8sModel.ServiceModel

	rc_model.CreateReplicationController(k8s_rc)
	service_model.CreateService(_k8s_service)
	// _rc_service := data_format

	var service Service
	service.Status = "ok"
	// service.Data = ""
	return service
}
func (this *ReplicationControllerService) CreateReplicationController(data []byte) Cluster {
	type rc_format struct {
		Cluster_name    string            `json:"cluster_name"`
		Port            string            `json:"port"`
		Container_count string            `json:"container_count"`
		Cpu             string            `json:"cpu"`
		Image           string            `json:"image"`
		Label           map[string]string `json:"label"`
	}
	var _rc_format rc_format
	json.Unmarshal(data, &_rc_format)

	var k8s_rc k8s_format.ReplicationController
	var k8s_rc_container k8s_format.Container
	var k8s_rc_container_port k8s_format.ContainerPort

	k8s_rc.Kind = "ReplicationController"
	k8s_rc.Metadata.Name = _rc_format.Cluster_name
	k8s_rc.Metadata.Labels = _rc_format.Label
	k8s_rc.Metadata.Labels["name"] = _rc_format.Cluster_name
	k8s_rc.Spec.Replicas, _ = strconv.Atoi(_rc_format.Container_count)
	k8s_rc.Spec.Selector = map[string]string{"name": _rc_format.Cluster_name}
	k8s_rc.Spec.Template.Metadata.Labels = map[string]string{"name": _rc_format.Cluster_name}
	k8s_rc_container.Name = _rc_format.Cluster_name
	k8s_rc_container.Image = _rc_format.Image
	k8s_rc_container_port.ContainerPort, _ = strconv.Atoi(_rc_format.Port)
	k8s_rc_container.Ports = append(k8s_rc_container.Ports, k8s_rc_container_port)
	k8s_rc.Spec.Template.Spec.Containers = append(k8s_rc.Spec.Template.Spec.Containers, k8s_rc_container)

	_replication_controllerModel := k8sModel.ReplicationControllerModel{}
	_replication_controllerModel.CreateReplicationController(k8s_rc)

	var _cluster Cluster
	_cluster.Status = "ok"

	return _cluster
}