Tag Archives: snippet

Create a free pod index in Pinecone using Python

Pinecone documentation is quite good, but when I wanted to create a free pod index in Pinecone using Python I didn’t know what parameters I should supply.

Specifically, I couldn’t understand what values would be the values for environment and pod_type

After a bit of digging (looking at the WebUI) here is how to do it

from pinecone import Pinecone, PodSpec

pc = Pinecone(api_key='<<PINECONE_API_KEY>>')
pc.create_index(
    name="example-index", 
    dimension=1536, 
    metric="cosine", 
    spec=PodSpec(
        environment='gcp-starter', 
        pod_type='s1.x1'
    )
)

How to use an SSH key stored in Azure Key Vault while building Azure Linux VMs using Terraform

So I want to use the same SSH Public key to be able to authenticate across multiple Linux VMs that I’m building in Azure in Terraform. While I did find a lot of examples (including among Terraform example repo) of how to do it if you have the key stored on your local machine I couldn’t find (or didn’t search long enough) how to use an SSH key stored in Azure Key Vault while building Azure Linux VMs using Terraform.

Continue reading How to use an SSH key stored in Azure Key Vault while building Azure Linux VMs using Terraform

Python – Test Network Connection

The below will return True/False

import socket

def test_connection(host="8.8.8.8", port=53, timeout=3):
  try:
    socket.setdefaulttimeout(timeout)
    socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
    return True
  except Exception as ex:
    #print ex.message
    return False


destination_host = "mymachine.company"
destination_port = 9997
timeout = 2
test_result = test_connection(destination_host, destination_port, timeout)

Or you can use this version to return the Exception in case connection has failed

import socket

def test_connection(host="8.8.8.8", port=53, timeout=3):
  try:
    socket.setdefaulttimeout(timeout)
    socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
    return True, None
  except Exception as ex:
    #print ex.message
    return False, ex.message


destination_host = "mymachine.company"
destination_port = 9997
timeout = 2
test_result, ex = test_connection(destination_host, destination_port, timeout)