kubeflow / fairing

Python SDK for building, training, and deploying ML models
Apache License 2.0
337 stars 144 forks source link

name 'yaml' is not defined #553

Open kwonmha opened 3 years ago

kwonmha commented 3 years ago

I'm running notebook- https://github.com/kubeflow/fairing/blob/master/examples/mnist/mnist_e2e_on_prem.ipynb And on the 4th cell

from kubernetes import client as k8s_client
from kubernetes import config as k8s_config
from kubeflow.fairing.utils import is_running_in_k8s

pv_yaml = f'''
apiVersion: v1
kind: PersistentVolume
metadata:
  name: {pv_name}
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: {nfs_path}
    server: {nfs_server}
'''
pvc_yaml = f'''
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {pvc_name}
  namespace: {my_namespace}
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi
'''

if is_running_in_k8s():
    k8s_config.load_incluster_config()
else:
    k8s_config.load_kube_config()

k8s_core_api = k8s_client.CoreV1Api()
k8s_core_api.create_persistent_volume(yaml.safe_load(pv_yaml))
k8s_core_api.create_namespaced_persistent_volume_claim(my_namespace, yaml.safe_load(pvc_yaml))

It says

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-da6a0e14757a> in <module>
     39 
     40 k8s_core_api = k8s_client.CoreV1Api()
---> 41 k8s_core_api.create_persistent_volume(yaml.safe_load(pv_yaml))
     42 k8s_core_api.create_namespaced_persistent_volume_claim(my_namespace, yaml.safe_load(pvc_yaml))

NameError: name 'yaml' is not defined

What should I do?

Environment:

NOTE: If you are using fair from master, please provide us the git commit hash.

kwonmha commented 3 years ago

You need to add import yaml on the cell.

kwonmha commented 3 years ago

And also msrestazure library is needed to run the notebook.