signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install swift proxy service :param auth_uri: keystone internal endpoint e.g. `http://CONTROLLER_VIP:5000` :param auth_url: keystone admin endpoint e.g. `http://CONTROLLER_VIP:35357` :param swift_pass: password of `swift` user :param memcached_servers: memcache servers e.g. `CONTROLLER1:11211,CONTROLLER2:11211` :param ...
f10229:c0:m3
def finalize_install(self, *args, **kwargs):
return execute(self._finalize_install, *args, **kwargs)<EOL>
Finalize swift installation :param swift_hash_path_suffix: `swift_hash_path_suffix` and `swift_hash_path_prefix` are used as part of the hashing algorithm when determining data placement in the cluster. These values should remain secret and MUST NOT change once a cluster has been deployed :param swift_hash_path_prefix...
f10229:c0:m5
def _prepare_disks(self, disks_name):
fstab = '<STR_LIT>'<EOL>for disk in tqdm(disks_name.split('<STR_LIT:U+002C>')):<EOL><INDENT>sudo('<STR_LIT>'.format(disk), warn_only=True)<EOL>if sudo('<STR_LIT>'.format(disk), warn_only=True).failed:<EOL><INDENT>sudo('<STR_LIT>')<EOL>sudo('<STR_LIT>')<EOL>sudo('<STR_LIT>'.format(disk))<EOL><DEDENT>sudo('<STR_LIT>'.for...
format disks to xfs and mount it
f10230:c0:m0
def prepare_disks(self, *args, **kwargs):
return execute(self._prepare_disks, *args, **kwargs)<EOL>
Prepare the disks for storage :param disks_name: the device name, e.g. `sdb,sdc` :returns: None
f10230:c0:m1
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install swift storage :param address: the management interface ip for rsync :param bind_ip: the management interface ip for swift storage binding :returns: None
f10230:c0:m3
def create_account_builder_file(self, *args, **kwargs):
return execute(self._create_account_builder_file, *args, **kwargs)<EOL>
Create account ring :param partitions: 2^10 (1024) maximum partitions e.g. `10` :param replicas: 3 replicas of each object e.g. `3` :param moving: 1 hour minimum time between moving a partition more than once e.g. `1` :returns: None
f10230:c0:m5
def account_builder_add(self, *args, **kwargs):
return execute(self._account_builder_add, *args, **kwargs)<EOL>
Add each storage node to the account ring :param region: swift storage region e.g. `1` :param zone: swift storage zone e.g. `1` :param ip: the IP address of the management network on the each storage node e.g. `STORAGE_NODE_IP` :param device: a storage device name on the same storage node e.g. `sdb` :param weight: the...
f10230:c0:m7
def account_builder_rebalance(self):
return execute(self._account_builder_rebalance)<EOL>
Rebalance account builder :returns: None
f10230:c0:m9
def create_container_builder_file(self, *args, **kwargs):
return execute(self._create_container_builder_file, *args, **kwargs)<EOL>
Create container ring :param partitions: 2^10 (1024) maximum partitions e.g. `10` :param replicas: 3 replicas of each object e.g. `3` :param moving: 1 hour minimum time between moving a partition more than once e.g. `1` :returns: None
f10230:c0:m11
def container_builder_add(self, *args, **kwargs):
return execute(self._container_builder_add, *args, **kwargs)<EOL>
Add each storage node to the container ring :param region: swift storage region e.g. `1` :param zone: swift storage zone e.g. `1` :param ip: the IP address of the management network on the storage node e.g. `STORAGE_NODE_IP` :param device: a storage device name on the same storage node e.g. `sdb` :param weight: the st...
f10230:c0:m13
def container_builder_rebalance(self):
return execute(self._container_builder_rebalance)<EOL>
Rebalance container builder :returns: None
f10230:c0:m15
def create_object_builder_file(self, *args, **kwargs):
return execute(self._create_object_builder_file, *args, **kwargs)<EOL>
Create object ring :param partitions: 2^10 (1024) maximum partitions e.g. `10` :param replicas: 3 replicas of each object e.g. `3` :param moving: 1 hour minimum time between moving a partition more than once e.g. `1` :returns: None
f10230:c0:m17
def object_builder_add(self, *args, **kwargs):
return execute(self._object_builder_add, *args, **kwargs)<EOL>
Add each storage node to the object ring :param region: swift storage region e.g. `1` :param zone: swift storage zone e.g. `1` :param ip: the IP address of the management network on the storage node e.g. `STORAGE_NODE_IP` :param device: a storage device name on the same storage node e.g. `sdb` :param weight: the stora...
f10230:c0:m19
def object_builder_rebalance(self):
return execute(self._object_builder_rebalance)<EOL>
Rebalance object builder :returns: None
f10230:c0:m21
def get_builder_file(self):
return execute(self._get_builder_file)<EOL>
Copy *.ring.gz to local :returns: None
f10230:c0:m23
def sync_builder_file(self, hosts):
return execute(self._sync_builder_file, hosts=hosts)<EOL>
Copy the account.ring.gz, container.ring.gz, and object.ring.gz files from local to the /etc/swift directory on each storage node and any additional nodes running the proxy service :returns: None
f10230:c0:m25
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install neutron agent :param rabbit_hosts: RabbitMQ HA cluster host:port pairs. (list value) e.g. `CONTROLLER1,CONTROLLER2` :param rabbit_user: The RabbitMQ userid. (string value) e.g. `openstack` :param rabbit_pass: The RabbitMQ password. (string value) :param auth_uri: Complete public Identity API endpoint. (string ...
f10231:c0:m1
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install nova compute :param my_ip: (String) IP address of this host :param rabbit_hosts: RabbitMQ HA cluster host:port pairs. (list value) e.g. `CONTROLLER1,CONTROLLER2` :param rabbit_user: The RabbitMQ userid. (string value) e.g. `openstack` :param rabbit_pass: The RabbitMQ password. (string value) :param auth_uri: (...
f10232:c0:m1
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install rabbitmq :param erlang_cookie: setup elang cookie :param rabbit_user: set rabbit user name :param rabbit_pass: set rabbit password of `rabbit_user` :returns: None
f10233:c0:m1
def join_cluster(self, *args, **kwargs):
return execute(self._join_cluster, *args, **kwargs)<EOL>
Join to the cluster :param name: the joined name, e.g. `rabbit@CONTROLLER1`, ensure the `CONTROLLER1` can be accessed by target host :returns: None
f10233:c0:m3
def update_mysql_config(self, *args, **kwargs):
return execute(self._update_mysql_config, *args, **kwargs)<EOL>
If trusty setup Galera Cluster for MySQL. If xenial setup MariaDB Galera Cluster :param wsrep_cluster_address: the IP addresses for each cluster node e.g. `gcomm://CONTROLLER1_IP,CONTROLLER2_IP` :param wsrep_node_name: the logical name of the cluster node e.g. `galera1` :param wsrep_node_address: the IP address of the...
f10234:c0:m1
@runs_once<EOL><INDENT>def _create_glance_db(self, root_db_pass, glance_db_pass):<DEDENT>
print(red(env.host_string + '<STR_LIT>'))<EOL>sudo(<EOL>"<STR_LIT>".format(root_db_pass), shell=False)<EOL>sudo("<STR_LIT>".format(<EOL>root_db_pass, glance_db_pass), shell=False)<EOL>sudo("<STR_LIT>".format(<EOL>root_db_pass, glance_db_pass), shell=False)<EOL>
Create the glance database
f10235:c0:m0
def create_glance_db(self, *args, **kwargs):
execute(self._create_glance_db, *args, **kwargs)<EOL>
Create the `glance` database and the user named `glance` :param root_db_pass: the mysql database `root` passowrd :param glance_db_pass: the password of `glance` user :returns: None
f10235:c0:m1
def create_service_credentials(self, *args, **kwargs):
return execute(self._create_service_credentials, *args, **kwargs)<EOL>
Create the glance service credentials :param os_password: the password of openstack `admin` user :param os_auth_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param glance_pass: create a passowrd of `glance` user :param public_endpoint: public endpoint for glance service e.g. `http://CONTROLLER_VIP:...
f10235:c0:m3
def install_glance(self, *args, **kwargs):
return execute(self._install_glance, *args, **kwargs)<EOL>
Install glance, default store is ceph :param connection: The SQLAlchemy connection string to use to connect to the database. (string value) e.g. `mysql+pymysql://glance:GLANCE_PASS@CONTROLLER_VIP/glance` :param auth_uri: Complete public Identity API endpoint. (string value) e.g. `http://CONTROLLER_VIP:5000` :param aut...
f10235:c0:m5
def create_cinder_db(self, *args, **kwargs):
return execute(self._create_cinder_db, *args, **kwargs)<EOL>
Create a database named `cinder` and the `cinder` user :param root_db_pass(str): the password of mysql `root` account :param cinder_db_pass(str): the password of `cinder` user:
f10236:c0:m1
def create_service_credentials(self, *args, **kwargs):
return execute(self._create_service_credentials, *args, **kwargs)<EOL>
r""" Create the cinder service credentials :param os_password(str): the password of OpenStack `admin` user :param os_auth_url(str): keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param cinder_pass(str): password of `cinder` user :param public_endpoint_v1(str): publ...
f10236:c0:m3
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install cinder and volume service :param connection: The SQLAlchemy connection string to use to connect to the database. (string value) e.g. `mysql+pymysql://cinder:CINDER_PASS@CONTROLLER_VIP/cinde` :param rabbit_hosts: RabbitMQ HA cluster host:port pairs. (list value) e.g. `CONTROLLER1,CONTROLLER2` :param rabbit_user...
f10236:c0:m5
def install(self):
return execute(self._install)<EOL>
Install HAProxy and Keepalived :returns: None
f10237:c0:m1
def create_nova_db(self, *args, **kwargs):
return execute(self._create_nova_db, *args, **kwargs)<EOL>
Create the nova and nova_api database and the user named nova :param root_db_pass: the password of mysql database root user :param nova_db_pass: the password of nova database user :returns: None
f10238:c0:m1
def create_service_credentials(self, *args, **kwargs):
return execute(self._create_service_credentials, *args, **kwargs)<EOL>
r""" Create the nova service credentials :param os_password: the password of openstack `admin` user :param os_auth_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param nova_pass: passowrd of `nova` user :param public_endpoint: public endpoint for nova service ...
f10238:c0:m3
def install_nova(self, *args, **kwargs):
return execute(self._install_nova, *args, **kwargs)<EOL>
Install nova :param connection: (String) The SQLAlchemy connection string to use to connect to the Nova API database. e.g. `mysql+pymysql://nova:NOVA_PASS@CONTROLLER_VIP/nova` :param api_connection: mysql nova_api database SQLAlchemy connection string e.g. `mysql+pymysql://nova:NOVA_PASS@CONTROLLER_VIP/nova_api` :para...
f10238:c0:m5
def enable_repo(self):
return execute(self._enable_repo)<EOL>
Setup repository for trusty only :returns: None
f10239:c0:m1
def install(self):
return execute(self._install)<EOL>
Install Galera Cluster for MySQL if trusty, install MariaDB Galera Cluster if xenial :returns: None
f10239:c0:m3
def install(self, *args, **kwargs):
return execute(self._install, *args, **kwargs)<EOL>
Install horizon :param openstack_host: configure the dashboard to use OpenStack services on the controller node e.g. `CONTROLLER_VIP` :param memcached_servers: django memcache e.g. `CONTROLLER1:11211,CONTROLLER2:11211` :param time_zone: the timezone of the server. This should correspond with the timezone of your entir...
f10240:c0:m1
def create_keystone_db(self, *args, **kwargs):
return execute(self._create_keystone_db, *args, **kwargs)<EOL>
Create the `keystone` database and the user named keystone :param root_db_pass: the mysql database `root` passowrd :param keystone_db_pass: the password of `keystone` database user :returns: None
f10241:c0:m1
def install_keystone(self, *args, **kwargs):
return execute(self._install_keystone, *args, **kwargs)<EOL>
Install keystone :param admin_token: define the value of the initial administration token :param connection: (String) The SQLAlchemy connection string to use to connect to the database. e.g. `mysql+pymysql://keystone:PASS@CONTROLLER_VIP/keystone` :param memcached_servers: (List) Optionally specify a list of memcached ...
f10241:c0:m3
def create_entity_and_endpoint(self, *args, **kwargs):
return execute(self._create_entity_and_endpoint, *args, **kwargs)<EOL>
Create the service entity and API endpoints :param os_token: the openstack admin token :param os_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param public_endpoint: the public endpoint e.g. `http://CONTROLLER_VIP:5000/v3` :param internal_endpoint: the internal endpoint e.g. `http://CONTROLLER_VIP:...
f10241:c0:m5
def create_projects_users_roles(self, *args, **kwargs):
return execute(self._create_projects_users_roles, *args, **kwargs)<EOL>
Create an administrative and demo project, user, and role for administrative and testing operations in your environment :param os_token: the openstack admin token :param os_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param admin_pass: passowrd of openstack `admin` user :param demo_pass: passowrd ...
f10241:c0:m7
def _update_keystone_paste_ini(self):
with open('<STR_LIT>' + env.host_string, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(conf_keystone_paste_ini)<EOL><DEDENT>files.upload_template(filename='<STR_LIT>' + env.host_string,<EOL>destination='<STR_LIT>',<EOL>use_sudo=True,<EOL>backup=True)<EOL>os.remove('<STR_LIT>' + env.host_string)<EOL>
remove admin_token_auth from the [pipeline:public_api], [pipeline:admin_api], and [pipeline:api_v3] sections
f10241:c0:m8
def update_keystone_paste_ini(self):
return execute(self._update_keystone_paste_ini)<EOL>
Remove admin_token_auth from the [pipeline:public_api], [pipeline:admin_api], and [pipeline:api_v3] sections in `/etc/keystone/keystone-paste.ini` :returns: None
f10241:c0:m9
def create_manila_db(self, *args, **kwargs):
return execute(self._create_manila_db, *args, **kwargs)<EOL>
Create manila database and the user named manila :param root_db_pass: the password of mysql root user :param manila_db_pass: the password of manila database user :returns: None
f10242:c0:m1
def create_service_credentials(self, *args, **kwargs):
return execute(self._create_service_credentials, *args, **kwargs)<EOL>
r""" create the manila service credentials :param os_password: the password of openstack `admin` user :param os_auth_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param manila_pass: passowrd of `manila` user :param public_endpoint_v1: public endpoint for mani...
f10242:c0:m3
def install_manila(self, *args, **kwargs):
return execute(self._install_manila, *args, **kwargs)<EOL>
Install manila :param connection: The SQLAlchemy connection string to use to connect to the database. (string value) e.g. `mysql+pymysql://manila:MANILA_PASS@CONTROLLER_VIP/manila` :param auth_uri: Complete public Identity API endpoint. (string value) e.g. `http://CONTROLLER_VIP:5000` :param auth_url: keystone admin e...
f10242:c0:m5
def install_manila_share(self, *args, **kwargs):
return execute(self._install_manila_share, *args, **kwargs)<EOL>
Install manila share service :param connection: The SQLAlchemy connection string to use to connect to the database. (string value) e.g. `mysql+pymysql://manila:MANILA_PASS@CONTROLLER_VIP/manila` :param auth_uri: Complete public Identity API endpoint. (string value) e.g. `http://CONTROLLER_VIP:5000` :param auth_url: Au...
f10244:c0:m1
@priority(<NUM_LIT:15>)<EOL>def make(parser):
s = parser.add_subparsers(<EOL>title='<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>help='<STR_LIT:description>',<EOL>)<EOL>
DEPRECATED provison Glance with HA
f10290:m4
@priority(<NUM_LIT>)<EOL>def make(parser):
s = parser.add_subparsers(<EOL>title='<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>help='<STR_LIT:description>',<EOL>)<EOL>def create_manila_db_f(args):<EOL><INDENT>create_manila_db(args)<EOL><DEDENT>create_manila_db_parser = create_manila_db_subparser(s)<EOL>create_manila_db_parser.set_defaults(func=create_manila_db_f)<EO...
provison Manila with HA
f10296:m7
def gen_pass():
os.system('<STR_LIT>')<EOL>
DEPRECATED
f10297:m1
def cmd(user, hosts, key_filename, password, run):
try:<EOL><INDENT>remote = Cmd(user, hosts, key_filename, password)<EOL><DEDENT>except AttributeError:<EOL><INDENT>sys.stderr.write('<STR_LIT>')<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>remote.cmd(run)<EOL>
DEPRECATED
f10297:m2
@priority(<NUM_LIT:10>)<EOL>def make(parser):
s = parser.add_subparsers(<EOL>title='<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>help='<STR_LIT:description>',<EOL>)<EOL>def gen_pass_f(args):<EOL><INDENT>gen_pass()<EOL><DEDENT>gen_pass_parser = s.add_parser('<STR_LIT>', help='<STR_LIT>')<EOL>gen_pass_parser.set_defaults(func=gen_pass_f)<EOL>def cmd_f(args):<EOL><INDENT...
DEPRECATED prepare OpenStack basic environment
f10297:m3
@priority(<NUM_LIT>)<EOL>def make(parser):
s = parser.add_subparsers(<EOL>title='<STR_LIT>',<EOL>metavar='<STR_LIT>',<EOL>help='<STR_LIT:description>',<EOL>)<EOL>def install_f(args):<EOL><INDENT>install(args)<EOL><DEDENT>install_parser = install_subparser(s)<EOL>install_parser.set_defaults(func=install_f)<EOL>
provison Manila Share with HA
f10298:m3
def priority(num):
def add_priority(fn):<EOL><INDENT>fn.priority = num<EOL>return fn<EOL><DEDENT>return add_priority<EOL>
DEPRECATED Decorator to add a `priority` attribute to the function.
f10302:m0
def create_neutron_db(self, *args, **kwargs):
return execute(self._create_neutron_db, *args, **kwargs)<EOL>
Create the neutron database and the user named neutron :param root_db_pass: the password of openstack database `root` user :param neutron_db_pass: the password of `neutron` database user :returns: None
f10303:c0:m1
def create_service_credentials(self, *args, **kwargs):
return execute(self._create_service_credentials, *args, **kwargs)<EOL>
create the neutron service credentials :param os_password: the password of openstack `admin` user :param os_auth_url: keystone endpoint url e.g. `http://CONTROLLER_VIP:35357/v3` :param neutron_pass: the password of `neutron` user :param public_endpoint: public endpoint for neutron service e.g. `http://CONTROLLER_VIP:9...
f10303:c0:m3
def install_self_service(self, *args, **kwargs):
return execute(self._install_self_service, *args, **kwargs)<EOL>
Install neutron for self-service :param connection: The SQLAlchemy connection string to use to connect to the database. (string value) e.g. `mysql+pymysql://neutron:NEUTRON_PASS@CONTROLLER_VIP/neutron` :param rabbit_hosts: RabbitMQ HA cluster host:port pairs. (list value) e.g. `CONTROLLER1,CONTROLLER2` :param rabbit_u...
f10303:c0:m5
def upload_conf(self, *args, **kwargs):
return execute(self._upload_conf, *args, **kwargs)<EOL>
Upload configuration file to the target host :param file: the path of haproxy configration file :returns: None
f10304:c0:m1
def configure_keepalived(self, *args, **kwargs):
return execute(self._configure_keepalived, *args, **kwargs)<EOL>
Configure keepalived :param router_id: Keepalived router id e.g. `lb1` :param priority: Keepalived priority e.g. `150` :param state: Keepalived state e.g. `MASTER` or 'SLAVE' :param interface: Keepalived binding interface e.g. `eth0` :param vip: Keepalived virtual ip e.g. `CONTROLLER_VIP` :returns: None
f10304:c0:m3
def cmd(self, *args, **kwargs):
return execute(self._cmd, *args, **kwargs)<EOL>
The command line to be executed on the remote node :param command_line(str): command line :returns: None
f10305:c0:m1
def start_wsrep_new_cluster(self):
return execute(self._start_wsrep_new_cluster)<EOL>
Initialize the primary component on one cluster node :returns: None
f10307:c0:m1
def start_mysql(self):
return execute(self._start_mysql)<EOL>
Start the database server to join the cluster :returns: None
f10307:c0:m3
def stop_mysql(self):
return execute(self._stop_mysql)<EOL>
Stop the mysql service :returns: None
f10307:c0:m5
def change_root_password(self, *args, **kwargs):
return execute(self._change_root_password, *args, **kwargs)<EOL>
Change the mysql root password :param pwd: the new password of root user :returns: None
f10307:c0:m7
def show_cluster_status(self, *args, **kwargs):
return execute(self._show_cluster_status, *args, **kwargs)<EOL>
Display the cluster status :param root_db_pass: the password of mysql root user :returns: None
f10307:c0:m9
def _apply_base_theme(app):
if QT_VERSION < (<NUM_LIT:5>,):<EOL><INDENT>app.setStyle('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>app.setStyle('<STR_LIT>')<EOL><DEDENT>with open(_STYLESHEET) as stylesheet:<EOL><INDENT>app.setStyleSheet(stylesheet.read())<EOL><DEDENT>
Apply base theme to the application. Args: app (QApplication): QApplication instance.
f10309:m0
def dark(app):
_apply_base_theme(app)<EOL>darkPalette = QPalette()<EOL>darkPalette.setColor(QPalette.WindowText, QColor(<NUM_LIT>, <NUM_LIT>, <NUM_LIT>))<EOL>darkPalette.setColor(QPalette.Button, QColor(<NUM_LIT>, <NUM_LIT>, <NUM_LIT>))<EOL>darkPalette.setColor(QPalette.Light, QColor(<NUM_LIT>, <NUM_LIT>, <NUM_LIT>))<EOL>darkPalette....
Apply Dark Theme to the Qt application instance. Args: app (QApplication): QApplication instance.
f10309:m1
def setWindowTitle(self, title):
self.lblTitle.setText(title)<EOL>
Set window title. Args: title (str): Title.
f10310:c1:m3
@classmethod<EOL><INDENT>def from_file(cls, filename, **kwargs):<DEDENT>
filename = os.path.expanduser(filename)<EOL>if not os.path.isfile(filename):<EOL><INDENT>raise exceptions.PyKubeError("<STR_LIT>".format(filename))<EOL><DEDENT>with open(filename) as f:<EOL><INDENT>doc = yaml.safe_load(f.read())<EOL><DEDENT>self = cls(doc, **kwargs)<EOL>self.filename = filename<EOL>return self<EOL>
Creates an instance of the KubeConfig class from a kubeconfig file. :Parameters: - `filename`: The full path to the configuration file
f10316:c0:m1
@classmethod<EOL><INDENT>def from_url(cls, url, **kwargs):<DEDENT>
doc = {<EOL>"<STR_LIT>": [<EOL>{<EOL>"<STR_LIT:name>": "<STR_LIT>",<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": url,<EOL>},<EOL>},<EOL>],<EOL>"<STR_LIT>": [<EOL>{<EOL>"<STR_LIT:name>": "<STR_LIT>",<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>},<EOL>}<EOL>],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>}<EOL>self = cls(doc, **kwa...
Creates an instance of the KubeConfig class from a single URL (useful for interacting with kubectl proxy).
f10316:c0:m2
def __init__(self, doc, current_context=None):
self.doc = doc<EOL>self._current_context = None<EOL>if current_context is not None:<EOL><INDENT>self.set_current_context(current_context)<EOL><DEDENT>elif "<STR_LIT>" in doc and doc["<STR_LIT>"]:<EOL><INDENT>self.set_current_context(doc["<STR_LIT>"])<EOL><DEDENT>
Creates an instance of the KubeConfig class.
f10316:c0:m3
def set_current_context(self, value):
self._current_context = value<EOL>
Sets the context to the provided value. :Parameters: - `value`: The value for the current context
f10316:c0:m4
@property<EOL><INDENT>def clusters(self):<DEDENT>
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>cs = {}<EOL>for cr in self.doc["<STR_LIT>"]:<EOL><INDENT>cs[cr["<STR_LIT:name>"]] = c = copy.deepcopy(cr["<STR_LIT>"])<EOL>if "<STR_LIT>" not in c:<EOL><INDENT>c["<STR_LIT>"] = "<STR_LIT>"<EOL><DEDENT>BytesOrFile.maybe_set(c, "<STR_LIT>")<EOL><DEDENT>self._clusters = cs<EO...
Returns known clusters by exposing as a read-only property.
f10316:c0:m6
@property<EOL><INDENT>def users(self):<DEDENT>
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>us = {}<EOL>if "<STR_LIT>" in self.doc:<EOL><INDENT>for ur in self.doc["<STR_LIT>"]:<EOL><INDENT>us[ur["<STR_LIT:name>"]] = u = copy.deepcopy(ur["<STR_LIT:user>"])<EOL>BytesOrFile.maybe_set(u, "<STR_LIT>")<EOL>BytesOrFile.maybe_set(u, "<STR_LIT>")<EOL><DEDENT><DEDENT>self....
Returns known users by exposing as a read-only property.
f10316:c0:m7
@property<EOL><INDENT>def contexts(self):<DEDENT>
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>cs = {}<EOL>for cr in self.doc["<STR_LIT>"]:<EOL><INDENT>cs[cr["<STR_LIT:name>"]] = copy.deepcopy(cr["<STR_LIT>"])<EOL><DEDENT>self._contexts = cs<EOL><DEDENT>return self._contexts<EOL>
Returns known contexts by exposing as a read-only property.
f10316:c0:m8
@property<EOL><INDENT>def cluster(self):<DEDENT>
return self.clusters[self.contexts[self.current_context]["<STR_LIT>"]]<EOL>
Returns the current selected cluster by exposing as a read-only property.
f10316:c0:m9
@property<EOL><INDENT>def user(self):<DEDENT>
return self.users.get(self.contexts[self.current_context].get("<STR_LIT:user>", "<STR_LIT>"), {})<EOL>
Returns the current user set by current context
f10316:c0:m10
@property<EOL><INDENT>def namespace(self):<DEDENT>
return self.contexts[self.current_context].get("<STR_LIT>", "<STR_LIT:default>")<EOL>
Returns the current context namespace by exposing as a read-only property.
f10316:c0:m11
def __init__(self, filename=None, data=None):
self._filename = None<EOL>self._bytes = None<EOL>if filename is not None and data is not None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>elif filename is not None:<EOL><INDENT>if not os.path.isfile(filename):<EOL><INDENT>raise exceptions.PyKubeError("<STR_LIT>".format(filename))<EOL><DEDENT>self._filename = ...
Creates a new instance of BytesOrFile. :Parameters: - `filename`: A full path to a file - `data`: base64 encoded bytes
f10316:c1:m1
def bytes(self):
if self._filename:<EOL><INDENT>with open(self._filename, "<STR_LIT:rb>") as f:<EOL><INDENT>return f.read()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return self._bytes<EOL><DEDENT>
Returns the provided data as bytes.
f10316:c1:m2
def filename(self):
if self._filename:<EOL><INDENT>return self._filename<EOL><DEDENT>else:<EOL><INDENT>with tempfile.NamedTemporaryFile(delete=False) as f:<EOL><INDENT>f.write(self._bytes)<EOL><DEDENT>return f.name<EOL><DEDENT>
Returns the provided data as a file location.
f10316:c1:m3
def object_factory(api, api_version, kind):
resource_list = api.resource_list(api_version)<EOL>resource = next((resource for resource in resource_list["<STR_LIT>"] if resource["<STR_LIT>"] == kind), None)<EOL>base = NamespacedAPIObject if resource["<STR_LIT>"] else APIObject<EOL>return type(kind, (base,), {<EOL>"<STR_LIT:version>": api_version,<EOL>"<STR_LIT>": ...
Dynamically builds a Python class for the given Kubernetes object in an API. For example: api = pykube.HTTPClient(...) NetworkPolicy = pykube.object_factory(api, "networking.k8s.io/v1", "NetworkPolicy") This enables construction of any Kubernetes object kind without explicit support from pykube. Currently, ...
f10318:m0
def rollout_undo(self, target_revision=None):
if target_revision is None:<EOL><INDENT>revision = {}<EOL><DEDENT>else:<EOL><INDENT>revision = {<EOL>"<STR_LIT>": target_revision<EOL>}<EOL><DEDENT>params = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": self.version,<EOL>"<STR_LIT:name>": self.name,<EOL>"<STR_LIT>": revision<EOL>}<EOL>kwargs = {<EOL>"<STR_LIT:versio...
Produces same action as kubectl rollout undo deployment command. Input variable is revision to rollback to (in kubectl, --to-revision)
f10318:c6:m1
def logs(self, container=None, pretty=None, previous=False,<EOL>since_seconds=None, since_time=None, timestamps=False,<EOL>tail_lines=None, limit_bytes=None):
log_call = "<STR_LIT>"<EOL>params = {}<EOL>if container is not None:<EOL><INDENT>params["<STR_LIT>"] = container<EOL><DEDENT>if pretty is not None:<EOL><INDENT>params["<STR_LIT>"] = pretty<EOL><DEDENT>if previous:<EOL><INDENT>params["<STR_LIT>"] = "<STR_LIT:true>"<EOL><DEDENT>if since_seconds is not None and since_time...
Produces the same result as calling kubectl logs pod/<pod-name>. Check parameters meaning at http://kubernetes.io/docs/api-reference/v1/operations/, part 'read log of the specified Pod'. The result is plain text.
f10318:c17:m1
def iterator(self):
for obj in (self.execute().json().get("<STR_LIT>") or []):<EOL><INDENT>yield self.api_obj_class(self.api, obj)<EOL><DEDENT>
Execute the API request and return an iterator over the objects. This method does not use the query cache.
f10320:c1:m5
def __init__(self, config):
self.config = config<EOL>self.url = self.config.cluster["<STR_LIT>"]<EOL>session = requests.Session()<EOL>session.mount("<STR_LIT>", KubernetesHTTPAdapter(self.config))<EOL>session.mount("<STR_LIT>", KubernetesHTTPAdapter(self.config))<EOL>self.session = session<EOL>
Creates a new instance of the HTTPClient. :Parameters: - `config`: The configuration instance
f10322:c2:m0
@property<EOL><INDENT>def version(self):<DEDENT>
response = self.get(version="<STR_LIT>", base="<STR_LIT>")<EOL>response.raise_for_status()<EOL>data = response.json()<EOL>return (data["<STR_LIT>"], data["<STR_LIT>"])<EOL>
Get Kubernetes API version
f10322:c2:m3
def get_kwargs(self, **kwargs):
version = kwargs.pop("<STR_LIT:version>", "<STR_LIT>")<EOL>if version == "<STR_LIT>":<EOL><INDENT>base = kwargs.pop("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>elif "<STR_LIT:/>" in version:<EOL><INDENT>base = kwargs.pop("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>if "<STR_LIT>" not in kwargs:<EOL><INDENT>raise T...
Creates a full URL to request based on arguments. :Parametes: - `kwargs`: All keyword arguments to build a kubernetes API endpoint
f10322:c2:m5
def request(self, *args, **kwargs):
return self.session.request(*args, **self.get_kwargs(**kwargs))<EOL>
Makes an API request based on arguments. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m7
def get(self, *args, **kwargs):
return self.session.get(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP GET. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m8
def options(self, *args, **kwargs):
return self.session.options(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP OPTIONS. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m9
def head(self, *args, **kwargs):
return self.session.head(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP HEAD. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m10
def post(self, *args, **kwargs):
return self.session.post(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP POST. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m11
def put(self, *args, **kwargs):
return self.session.put(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP PUT. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m12
def patch(self, *args, **kwargs):
return self.session.patch(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP PATCH. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m13
def delete(self, *args, **kwargs):
return self.session.delete(*args, **self.get_kwargs(**kwargs))<EOL>
Executes an HTTP DELETE. :Parameters: - `args`: Non-keyword arguments - `kwargs`: Keyword arguments
f10322:c2:m14
@staticmethod<EOL><INDENT>def status(s):<DEDENT>
print('<STR_LIT>'.format(s))<EOL>
Prints things in bold.
f10331:c0:m0
def create_queryall_job(self, object_name, **kwargs):
return self.create_job(object_name, "<STR_LIT>", **kwargs)<EOL>
only supported since version 39.0
f10337:c3:m4
def get_query_batch_request(self, batch_id, job_id=None):
if not job_id:<EOL><INDENT>job_id = self.lookup_job_id(batch_id)<EOL><DEDENT>url = self.endpoint + "<STR_LIT>".format(job_id, batch_id)<EOL>resp = requests.get(url, headers=self.headers())<EOL>self.check_status(resp)<EOL>return resp.text<EOL>
Fetch the request sent for the batch. Note should only used for query batches
f10337:c3:m12
def abort_job(self, job_id):
doc = self.create_abort_job_doc()<EOL>url = self.endpoint + "<STR_LIT>" % job_id<EOL>resp = requests.post(<EOL>url,<EOL>headers=self.headers(),<EOL>data=doc<EOL>)<EOL>self.check_status(resp)<EOL>
Abort a given bulk job
f10337:c3:m14
def create_abort_job_doc(self):
root = ET.Element("<STR_LIT>")<EOL>root.set("<STR_LIT>", self.jobNS)<EOL>state = ET.SubElement(root, "<STR_LIT:state>")<EOL>state.text = "<STR_LIT>"<EOL>buf = StringIO()<EOL>tree = ET.ElementTree(root)<EOL>tree.write(buf, encoding="<STR_LIT>")<EOL>return buf.getvalue()<EOL>
Create XML doc for aborting a job
f10337:c3:m17
def get_all_results_for_query_batch(self, batch_id, job_id=None, chunk_size=<NUM_LIT>):
result_ids = self.get_query_batch_result_ids(batch_id, job_id=job_id)<EOL>if not result_ids:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>for result_id in result_ids:<EOL><INDENT>yield self.get_query_batch_results(<EOL>batch_id,<EOL>result_id,<EOL>job_id=job_id,<EOL>chunk_size=chunk_size<EOL>)<EOL><DEDENT>
Gets result ids and generates each result set from the batch and returns it as an generator fetching the next result set when needed Args: batch_id: id of batch job_id: id of job, if not provided, it will be looked up
f10337:c3:m31