def _get_sample_cluster_configuration_by_k8_runtime(k8_runtime): metadata = def_models.Metadata('cluster_name', 'organization_name', 'org_virtual_datacenter_name') status = def_models.Status() settings = def_models.Settings(network='ovdc_network_name', ssh_key=None) k8_distribution = def_models.Distribution( template_name='ubuntu-16.04_k8-1.17_weave-2.6.0', template_revision=2) control_plane = def_models.ControlPlane( count=1, sizing_class='Large_sizing_policy_name', storage_profile='Gold_storage_profile_name') workers = def_models.Workers(count=2, sizing_class='Medium_sizing_policy_name', storage_profile='Silver_storage_profile') nfs = def_models.Nfs(count=0, sizing_class='Large_sizing_policy_name', storage_profile='Platinum_storage_profile_name') cluster_spec = def_models.ClusterSpec(control_plane=control_plane, k8_distribution=k8_distribution, settings=settings, workers=workers, nfs=nfs) cluster_entity = def_models.ClusterEntity(metadata=metadata, spec=cluster_spec, status=status, kind=k8_runtime.value) sample_cluster_config = yaml.dump(dataclasses.asdict(cluster_entity)) CLIENT_LOGGER.info(sample_cluster_config) return sample_cluster_config
def cluster_create(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster create operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ svc = cluster_svc.ClusterService(op_ctx) cluster_entity_spec = def_models.ClusterEntity(**data[RequestKey.V35_SPEC]) return asdict(svc.create_cluster(cluster_entity_spec))
def cluster_create(req_ctx: ctx.RequestContext): """Request handler for cluster create operation. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ svc = cluster_svc.ClusterService(req_ctx) cluster_entity_spec = def_models.ClusterEntity(** req_ctx.body) # noqa: E501 return svc.create_cluster(cluster_entity_spec)
def cluster_resize(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. Required data: cluster_name, num_nodes Optional data and default values: org_name=None, ovdc_name=None Conditional data and default values: network_name, rollback=True (data validation handled in broker) :return: Dict """ svc = cluster_svc.ClusterService(op_ctx) cluster_id = data[RequestKey.CLUSTER_ID] cluster_entity_spec = def_models.ClusterEntity(**data[RequestKey.V35_SPEC]) return svc.resize_cluster(cluster_id, cluster_entity_spec)
def cluster_resize(req_ctx: ctx.RequestContext): """Request handler for cluster resize operation. Required data: cluster_name, num_nodes Optional data and default values: org_name=None, ovdc_name=None Conditional data and default values: network_name, rollback=True (data validation handled in broker) :return: Dict """ raise NotImplementedError svc = cluster_svc.ClusterService(req_ctx) cluster_id = req_ctx.url_data['id'] cluster_entity_spec = def_models.ClusterEntity(** req_ctx.body) # noqa: E501 return svc.resize_cluster(cluster_id, cluster_entity_spec)
def cluster_upgrade(data, op_ctx: ctx.OperationContext): """Request handler for cluster upgrade operation. Validate data before actual upgrade is delegated to cluster service. :return: Dict """ svc = cluster_svc.ClusterService(op_ctx) cluster_entity_spec = def_models.ClusterEntity(**data[RequestKey.V35_SPEC]) cluster_id = data[RequestKey.CLUSTER_ID] curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( asdict(cluster_entity_spec.spec), asdict(curr_entity.entity.spec), exclude_fields=[ FlattenedClusterSpecKey.TEMPLATE_NAME.value, FlattenedClusterSpecKey.TEMPLATE_REVISION.value ]) return asdict(svc.upgrade_cluster(cluster_id, cluster_entity_spec))
def cluster_resize(data: dict, op_ctx: ctx.OperationContext): """Request handler for cluster resize operation. Validate data before actual resize is delegated to cluster service. :return: Defined entity of the native cluster :rtype: container_service_extension.def_.models.DefEntity """ svc = cluster_svc.ClusterService(op_ctx) cluster_id = data[RequestKey.CLUSTER_ID] cluster_entity_spec = def_models.ClusterEntity(**data[RequestKey.V35_SPEC]) curr_entity = svc.entity_svc.get_entity(cluster_id) request_utils.validate_request_payload( asdict(cluster_entity_spec.spec), asdict(curr_entity.entity.spec), exclude_fields=[ FlattenedClusterSpecKey.WORKERS_COUNT.value, FlattenedClusterSpecKey.NFS_COUNT.value ]) return asdict(svc.resize_cluster(cluster_id, cluster_entity_spec))
def apply(self, cluster_config, cluster_id=None, **kwargs): """Apply the configuration either to create or update the cluster. :param dict cluster_config: cluster configuration information :return: dictionary containing the apply operation task :rtype: dict """ entity_svc = def_entity_svc.DefEntityService(self._cloudapi_client) cluster_spec = def_models.ClusterEntity(**cluster_config) cluster_name = cluster_spec.metadata.cluster_name if cluster_id: # If cluster id doesn't exist, an exception will be raised def_entity = entity_svc.get_entity(cluster_id) else: def_entity = entity_svc.get_native_entity_by_name(cluster_name) if not def_entity: cluster_entity = self._native_cluster_api.create_cluster( cluster_spec) # noqa: E501 else: cluster_id = def_entity.id cluster_entity = \ self._native_cluster_api.update_cluster_by_cluster_id(cluster_id, cluster_spec) # noqa: E501 return client_utils.construct_task_console_message( cluster_entity.entity.status.task_href) # noqa: E501