A Serverless function to automatically start and stop IBM Cloud Virtual Server Instances.
Before you get started, you need to install IBM Cloud CLI and IBM Cloud Functions CLI in your local machine. Then, you need to login in your IBM Cloud account on IBM Cloud CLI (if you haven't already done, run ibmcloud login
).
Download the source code from Github and access the project folder.
git clone https://github.com/victorshinya/instance-scheduler.git
cd instance-scheduler
As you can manage your infrastructure using a SDK or API, you have to authenticate with a username
and apikey
. To get your username for the current account and generate the classic infrastructure API key. Go to Manage > Access (IAM) > Users and click on your name on the list.
- Scroll down to the
VPN password
section and copy theUsername
. This is going to be used on Instance Scheduler. - Scroll down to the
API keys
section and click onCreate classic infrastructure key
to automatically generate your API key. Copy the key. You are going to use it withusername
.
Run the following command with the classic infrastructure username and API key, and the list with all Virtual Servers to power on/off:
- SOFTLAYER_USERNAME is the
Username
field that you copied from previous step. - SOFTLAYER_APIKEY is the
API key
, generated in the previous step. - VSIS_NAME is the list with all Virtual Servers on Classic IaaS (Softlayer) that you'd like to power on/off - e.g.
'["VSI NAME 01", "VSI NAME 02", "SO ON, AND ON"]'
.
export SOFTLAYER_USERNAME="" SOFTLAYER_APIKEY="" VSIS_NAME='[""]'
In manifest.yml
file, it is set (by default) to power off the VSI at 03:00 AM (00:00 AM GMT-3) and to power on the VSI at 09:00 AM (06:00 AM GMT-3). Update if you need to run both actions at the desire hour.
Run the following command to deploy handler.go
function and to set up the Triggers and Rules.
As you are using IBM Cloud Functions, you don't need to install any package or setup a package.json. The platform already has all libraries required to run the source code.
ibmcloud fn deploy --manifest manifest.yml
Copyright 2021 Victor Shinya
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.