def create_cluster(container_engine_client, create_cluster_details, create_kwargs=None): if not create_kwargs: create_kwargs = dict( wait_for_states=[ WorkRequest.STATUS_SUCCEEDED, WorkRequest.OPERATION_TYPE_CLUSTER_CREATE, WorkRequest.STATUS_FAILED, ] ) created_response = create( container_engine_client, "create_cluster", create_cluster_details, **create_kwargs, ) if not created_response: return None cluster = None # NOTE, only supports a single cluster creation for now if created_response.resources: cluster_id = created_response.resources[0].identifier # Get the actual created cluster cluster = get(container_engine_client, "get_cluster", cluster_id) return cluster
def create_instance(compute_client, launch_instance_details, wait_for_states=None, **kwargs): if not wait_for_states: wait_for_states = [oci.core.models.Instance.LIFECYCLE_STATE_RUNNING] instance = create( compute_client, "launch_instance", launch_instance_details, wait_for_states=wait_for_states, **kwargs, ) if not instance: return None return instance
def create_subnet(network_client, create_subnet_details, wait_for_states=None, **kwargs): if not wait_for_states: wait_for_states = [Subnet.LIFECYCLE_STATE_AVAILABLE] subnet = create( network_client, "create_subnet", create_subnet_details, wait_for_states=wait_for_states, **kwargs, ) if not subnet: return None return subnet
def create_internet_gateway(network_client, create_internet_gateway_details, wait_for_states=None, **kwargs): if not wait_for_states: wait_for_states = [InternetGateway.LIFECYCLE_STATE_AVAILABLE] internetgateway = create( network_client, "create_internet_gateway", create_internet_gateway_details, wait_for_states=wait_for_states, **kwargs, ) if not internetgateway: return None return internetgateway
def create_route_table(network_client, create_route_table_details, wait_for_states=None, **kwargs): if not wait_for_states: wait_for_states = [RouteTable.LIFECYCLE_STATE_AVAILABLE] routetable = create( network_client, "create_route_table", create_route_table_details, wait_for_states=[RouteTable.LIFECYCLE_STATE_AVAILABLE], **kwargs, ) if not routetable: return None return routetable
def create_vcn(network_client, create_vcn_details, wait_for_states=None, **kwargs): if not wait_for_states: wait_for_states = [Vcn.LIFECYCLE_STATE_AVAILABLE] vcn = create( network_client, "create_vcn", create_vcn_details, wait_for_states=wait_for_states, **kwargs, ) if not vcn: return None return vcn
def refresh_kube_config(cluster_id, name="DEFAULT"): container_engine_client = new_container_engine_client(name=name) # Try to load the existing # Create or refresh the kubernetes config kube_config = create(container_engine_client, "create_kubeconfig", cluster_id) if kube_config and hasattr(kube_config, "text"): config_dict = parse_yaml(kube_config.text) # HACK, add profile to user args if name: profile_args = ["--profile", name] config_dict["users"][0]["user"]["exec"]["args"].extend(profile_args) if save_kube_config(config_dict): loaded = load_kube_config() loaded = load_kube_config() if not loaded: # The new/refreshed config failed to load return False return True
def create_node_pool(container_engine_client, create_node_pool_details): created_response = create( container_engine_client, "create_node_pool", create_node_pool_details, wait_for_states=[ WorkRequest.STATUS_SUCCEEDED, WorkRequest.OPERATION_TYPE_NODEPOOL_CREATE, WorkRequest.STATUS_FAILED, ], ) if not created_response: return None node_pool = None # NOTE, only supports a single cluster creation for now if created_response.resources: node_pool_id = created_response.resources[0].identifier # Get the actual created cluster node_pool = get(container_engine_client, "get_node_pool", node_pool_id) return node_pool